Updating text in the CW32 STATIC API using WS_EX_TRANSPARENT

I have a window with some STATIC tags and BUTTONS on it. I do all the transparent LABELS backgrounds, so I can do a RED background. In CALLBACK, I process the WM_CTLCOLORSTATIC message, determine the ID of the control using GetDlgCtrlID (), and then:

SetBkMode((HDC)wParam, TRANSPARENT); // Make STATIC control Bkgd transparent
return (INT_PTR)(HBRUSH)GetStockObject(NULL_BRUSH);

So far so good. The shape is drawn, the background is RED, and the text of the inscription is on top.

After interacting with the user, I need to change the text, so I get the message SetDlgItemText (), and the new text is a draw. The problem is that the old text is not erased, and the new text is drawn on top of it.

After reading a few today, it seems that the problem is that the parent control (form) is responsible for painting the background. This means that when the label text changes, the control redraws the new text, but the form does not automatically redraw the background.

Question: HOW do I force the form to redraw the rectangle region of the label control (preferably without subclassing anything)?

ADDED:

I tried the following:

HWND hctrl;
hctrl = GetDlgItem(hwnd, ControlID);
RedrawWindow( hctrl, 0, 0, 
RDW_UPDATENOW || RDW_ALLCHILDREN || RDW_FRAME || RDW_INVALIDATE || RDW_ERASE || RDW_INTERNALPAINT ); // RDW_UPDATENOW 

and

I do not process the WM_PAINT message at all, only:

case WM_CTLCOLORSTATIC:
 SetBkMode((HDC)wParam, TRANSPARENT); 
 return (INT_PTR)(HBRUSH)GetStockObject(NULL_BRUSH);




int Library::SetControlTxt( int ControlID, string sText  ) // Dialog Out
{ 
 int RetVal;

  RetVal = SetDlgItemText( hwnd, ControlID, sText.c_str() ); 
  RECT rect;
  HWND hctrl;
  hctrl = GetDlgItem(hwnd, ControlID);
  GetClientRect(hctrl, &rect);
  MapWindowPoints(hctrl, hwnd, (POINT *)&rect, 2);
  InvalidateRect(hwnd, &rect, TRUE);

       return RetVal;
} 

Mark, thanks for working.

+3
source share
1 answer

Use an InvalidateRect on the rectangle occupied by the control.

RECT rect;
GetClientRect(hctrl, &rect);
InvalidateRect(hctrl, &rect, TRUE);
MapWindowPoints(hctrl, hwnd, (POINT *) &rect, 2);
RedrawWindow(hwnd, &rect, NULL, RDW_ERASE | RDW_INVALIDATE);
+3
source

Source: https://habr.com/ru/post/1724354/


All Articles