Thread: WinAPI: Editbox + WM_CTLCOLORSTATIC sets bigger border?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    18

    Question WinAPI: Editbox + WM_CTLCOLORSTATIC sets bigger border?

    Hi

    I have a little problem with my program.
    I am creating an EDIT-box with this line:
    Code:
    HWND hA = CreateWindowEx(0, "EDIT", "", WS_CHILD|WS_TABSTOP|WS_VISIBLE|WS_BORDER, 5, 22, 165, 20, hwnd, (HMENU)IDC_US, GetModuleHandle(NULL), NULL);
    After the user presses “ok” I send:
    Code:
    SendMessage(hA, EM_SETREADONLY, (WPARAM) TRUE, 0);
    to make the box “readonly”.

    Then the box color chance to gray, but I want it to be white.
    To do so I use this in my WindowProcedure:

    Code:
    case WM_CTLCOLORSTATIC: {
             switch(GetDlgCtrlID((HWND) lParam)) {
                      case IDC_US:
                               #define WHITE 0x0FFFFFFF
                               CreateSolidBrush(WHITE);
                               break;
                      default: return DefWindowProc (hwnd, message, wParam, lParam);
             }
    }
    It works fine, but the problem is that the border around the box goes bigger?
    Why? Can I block or chance it?

    ____Pic: LINK

    Sorry for my bad eng =)

    EDIT:
    I think I have found a way to do it now, de first time I did it wrong ^^
    I hope someone can confirm that I am doing it right now:

    I set this to be global:
    Code:
    HBRUSH g_hbrBackground = CreateSolidBrush(RGB(255,255,255));
    My case lock like this:
    Code:
    case WM_CTLCOLORSTATIC: {
         switch(GetDlgCtrlID((HWND) lParam)) {
              case IDC_US: {
                   HDC hdcStatic = (HDC)wParam;
                   SetTextColor(hdcStatic, RGB(0, 0, 0));
                   SetBkMode(hdcStatic, TRANSPARENT);
                   return (LONG)g_hbrBackground;
                   break;
              }
         default: return DefWindowProc (hwnd, message, wParam, lParam);
         }
    }
    And on destroy:
    Code:
    DeleteObject(g_hbrBackground);
    Last edited by Dampy; 05-17-2008 at 02:34 PM. Reason: Find a way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem aligning floating point numbers
    By esbo in forum C Programming
    Replies: 4
    Last Post: 01-05-2009, 08:09 PM
  2. creating new sets
    By axon in forum C++ Programming
    Replies: 7
    Last Post: 12-03-2003, 06:37 PM

Tags for this Thread