change label's text fails after set its background color

你离开我真会死。 提交于 2021-01-29 05:30:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!