CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2004
    Posts
    38

    Arrow Edit Box SetBkColor

    Anyone can tell me why this code does not work. The only thing that comes out is that the editbox becomes grey??
    I am missing something??

    {
    PAINTSTRUCT ps;
    HWND htest = GetDlgItem(hDlg, IDC_CHANNEL);
    HDC hdc = GetWindowDC(htest);
    hdc = BeginPaint (htest, &ps);
    SetBkMode(hdc, TRANSPARENT);
    SetBkColor(hdc, RGB(0, 255, 0));
    EndPaint(htest, &ps);
    ReleaseDC(htest, hdc);
    }

    thanks,
    see u!

  2. #2
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: Edit Box SetBkColor

    Well... why not handle WM_CTLCOLOREDIT message?
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  3. #3
    Join Date
    Oct 2004
    Posts
    38

    Re: Edit Box SetBkColor

    Actually I have tryed to put this code inside a "case WM_CTLCOLOREDIT", but I am not sure how to make it work!!

    I am trying to find something around...

  4. #4
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: Edit Box SetBkColor

    Well WM_CTLCOLOREDIT requires you to return a HBRUSH from the handle. That means you can return every brush you need from WM_CTLCOLOREDIT and the edit will draw itself with it.

    Code:
    LRESULT CALLBACK WndProc ( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
    {
       static HBRUSH hBrush = NULL;
       switch ( msg )
       {
          case WM_CTLCOLOREDIT:
              {
                  if ( hBrush == NULL )
                  { // Red color
                      hBrush = CreateSolidBrush(RGB(0xFF, 0x00, 0x00));
                  }
              }
              return (LRESULT)hBrush;
    
          case WM_CLOSE:
             {
                 if ( hBrush != NULL )
                 {
                     DestroyObject((HGDIOBJ)hBrush);
                 }
             } break;
       }
    }
    Now the edit control should be painted red.
    Last edited by NoHero; May 4th, 2005 at 12:14 PM.
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  5. #5
    Join Date
    May 2004
    Location
    Michigan, United States
    Posts
    457

    Re: Edit Box SetBkColor

    Good example. And don't forget to DestroyObject() in WM_CLOSE or something similar.
    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

  6. #6
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: Edit Box SetBkColor

    Quote Originally Posted by Bond
    Good example. And don't forget to DestroyObject() in WM_CLOSE or something similar.
    Thank you missed that!
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured