suti
suti

Reputation: 181

WinAPI: set fill color of a readonly textbox

I have a program winapi (C++) nearly complete. The problem now is I want to set fill color of text box and that textbox is readonly. When I set that textbox readonly, I can't fill it white. And when I don't, it can be filled with white. This is how I create a textbox:

CreateWindow(L"EDIT", text, WS_CHILD|WS_VISIBLE|WS_BORDER|ES_READONLY|ES_RIGHT, left, top, width, height, hWnd, (HMENU)ID, hInst, NULL)

And this code is in WinProc:

case WM_CTLCOLOREDIT:
        SetTextColor((HDC)wParam,RGB(0,0,255));
        SetBkColor((HDC)wParam,RGB(255,255,255));
        SetBkMode((HDC)wParam, TRANSPARENT);
    return (LRESULT)GetStockObject(WHITE_BRUSH);

Upvotes: 2

Views: 2480

Answers (2)

Barry Smith
Barry Smith

Reputation: 1

As per HerrJoebob's solution, but you need to differentiate between static's and edit's: (untested code, but the idea is there)

case WM_CTLCOLORSTATIC:
{
TCHAR senderClass[256] ;
GetClassName((HWND)lParam, senderClass, 256);
if (_tscmp(senderClass, WC_EDIT)
  {
  //Code to change the colour of edit controls
  }
}
break;

Upvotes: 0

HerrJoebob
HerrJoebob

Reputation: 2313

You'll want to use WM_CTLCOLORSTATIC for read-only text boxes; see the docs for WM_CTLCOLOREDIT.

Upvotes: 1

Related Questions