Transparent, Editbox, HOLLOW_BRUSH, Marking text?

This is a discussion on Transparent, Editbox, HOLLOW_BRUSH, Marking text? within the Windows Programming forums, part of the Platform Specific Boards category; Hi I have a little problem when I am using "HOLLOW_BRUSH" as a background (?) I create a editbox and ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    18

    Question Transparent, Editbox, HOLLOW_BRUSH, Marking text?

    Hi
    I have a little problem when I am using "HOLLOW_BRUSH" as a background (?)
    I create a editbox and sets the readonly-flag, but the background goes grey and I want it white.
    To prevent that I use this in WM_CTLCOLORSTATIC:
    Code:
                                        case IDC_INFOBOX: {
                                                 HDC hdc = (HDC)wParam;
                                                 SetBkColor(hdc, 0xFFFFFF);
    	                                         SetTextColor(hdc, 0);
    	                                         return (LRESULT)GetStockObject(WHITE_BRUSH);
    }
    Its working fine, but now I want to make the editbox background transparent, to do that I use this:
    Code:
                                        case IDC_INFOBOX: {
                                                 HDC hdc = (HDC)wParam;
                                                 //SetBkColor(hdc, 0xFFFFFF);
    	                                         SetTextColor(hdc, 0);
    	                                         SetBkMode(hdc, TRANSPARENT);
    	                                         return (LRESULT)GetStockObject(HOLLOW_BRUSH);
    }
    I don’t know if it´s the right way to do it, but it works, almost =P.
    The transparent background is there, but if I mark some text, the marking stays in the background.
    Picture link: LINK!

    Is there some way to prevent that? Or maybe to prevent marking overall in the textbox?
    If I minimize and maximize the window the editbox is normal again, why? Can I use the same principle?

    I want the transparent background because I want to display a bitmap behind, it´s working fine as long I don’t mark the text =P

    Edit:
    Is it possible to make the blue "select-color" transparent?
    I have tried to find some way to do that on msdn, but I am bad searcher...
    Last edited by Dampy; 09-16-2008 at 12:45 PM. Reason: New text

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Yeah, just mess with these messages. You could do it via subclassing too, but that seems a little bit more work than necessary.

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    18
    Ok thanks, but I don’t understand how to chance the highlighting colors, or at least how to know that I am editing the highlighting-color?

    EDIT:
    Hum, I read in another forum that my way to do it don’t going to work..

    This is at best an incomplete solution because the edit control uses an
    opaque text background and the window background brush to erase text. If the
    text is never going to change, then this might not be a problem, but
    otherwise new content will be written on top of old and you will have a
    mess.
    BUT! This works, but with one small problem!
    Code:
    Global:
      HBRUSH brush =NULL;
      HBITMAP hbMG =NULL;
    
    case WM_CREATE:
      hbMG = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_GLAS));
      if(hbMG == NULL) MessageBox(hwnd, "Could not load bmp!", "Error", MB_OK | MB_ICONEXCLAMATION);
      brush = CreatePatternBrush(hbMG);
    
    case WM_CTLCOLORSTATIC:
      case IDC_INFOBOX:
        HDC hdc = (HDC)wParam;
        SetTextColor(hdc, 0);
        SetBkMode(hdc, TRANSPARENT);
        return (LRESULT)(HBRUSH)brush;
    
    case WM_DESTROY:
      DeleteObject(brush);
      DeleteObject(hbMG);
    When I "spam" the textbox and the box starts to scroll down (autoscroll), the brush starts to go up. picture: LINK.
    If I click in the box the brush goes to normal again. So is it possible to lock the brush somehow? Or maby “repaint” it when I post a message in the box? But how?

    And if I need to repaint the box, I also need to "lock" the box because if I mark some of the text so it scrolls up, the brush goes bad again.

    Is it possible to lock the box from marking the text or scroll it?

    Edit2:
    One way to update the window was to send:

    ShowWindow(hwnd, SW_HIDE);
    ShowWindow(hwnd, SW_NORMAL);

    When i send a new message.

    Now i only need to know how to lock the the box from marking / Draging the text so that scroll goes up.
    Or if it is possible to lock the brush in the box that is probably the best way to do it
    Last edited by Dampy; 09-16-2008 at 06:43 PM. Reason: More info

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    What about if you just handle this message?

    Or subclass the edit box.

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    I do this type of thing by drawing directly to the dialog/windows background (in WM_PAINT) I create an image and redraw each time the text changes.

    Or I subclass.
    Too many msgs to handle in the parents callback (and keep the code readable).
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  6. #6
    Registered User
    Join Date
    Sep 2007
    Posts
    18
    Ok, thanks.
    It works fine that way I do it, but it is probably not the best way to do it (hide and show the window every time something happens in the editbox)

    The best way would to look the brush somehow, then the user cud use the box as normal.

    I will try to paint it again in WM_PAINT and try to repaint the pic on EN_SETFOCUS and EN_VSCROLL, that way the user can use the box to copy.
    But I have a dumb question, How do I update/repaint the hbitmap?

    Code:
                      case WM_PAINT:{
                               BITMAP bm;
    			               PAINTSTRUCT ps;
    			               hdc = BeginPaint(hwnd, &ps);
    			               HDC hdcMem = CreateCompatibleDC(hdc);
    			               HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, hbMG);
    			               GetObject(hbMG, sizeof(bm), &bm);
    			               BitBlt(hdc, 7, 91, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
    			               SelectObject(hdcMem, hbmOld);
    			               DeleteDC(hdcMem);
    			               EndPaint(hwnd, &ps);
    		          }
    Code:
                                        case IDC_INFOBOX:
                                                 if (HIWORD(wParam) == EN_SETFOCUS) {
                                                          REPAINT THE IMG HERE?! BUT HOW? 
                                                 }
                                                 if (HIWORD(wParam) == EN_VSCROLL) {
                                                          REPAINT THE IMG HERE?! BUT HOW?
                                                 }

  7. #7
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    InvalidateRect();//send paint msg
    UpdateWindow();//bypass OS msg queue and post directly to window.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Accessing a Specific Text Line Inside CEditView :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 04-14-2002, 08:12 PM
  2. Validating the contents of a char buffer
    By mattz in forum C Programming
    Replies: 3
    Last Post: 12-09-2001, 05:21 PM
  3. Moving to the next structure array
    By mattz in forum C Programming
    Replies: 2
    Last Post: 11-30-2001, 02:43 PM
  4. Structure problem
    By mattz in forum C Programming
    Replies: 10
    Last Post: 11-30-2001, 12:19 PM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 06:35 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21