问题
In order to make the static control background transparent, I did handle the WM_CTLCOLORSTATIC
like this:
// make label transparent
case WM_CTLCOLORSTATIC:
{
HDC hdcStatic = (HDC) wParam;
SetTextColor(hdcStatic, RGB(0,0,0));
SetBkMode(hdcStatic, TRANSPARENT);
return (LRESULT)GetStockObject(NULL_BRUSH);
}
the label is created like this:
LRESULT CALLBACK Win2Proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
hTab3_label =
CreateWindowW(L"Static", L"This is my dear text!",
WS_VISIBLE | WS_CHILD | WS_TABSTOP,
50, 90, 130, 25, hwnd, (HMENU) 18, NULL, NULL);
break;
// ...
}
}
the GUI is fine so far:
but when I set a new text to it from a button call, like this:
case WM_COMMAND:
switch(LOWORD(wParam))
{
// ....
case ID_TAB1_BUTTONB:
//MessageBox(NULL, L"Click on B button", L"", MB_OK);
SetWindowText(hTab3_label, L"This is the new text!");
break;
}
break;
the static control gets messed up, without replace the previous text for some reason, like the image below. If I remove the case WM_CTLCOLORSTATIC
the text is replaced properly. What am I missing?
来源:https://stackoverflow.com/questions/65658704/change-labels-text-fails-after-set-its-background-color