How to "clear" WinAPI transparent window

I created a transparent checkbox in Win32 C ++. I did this because, as far as I know, you do not have a transparent flag in native win32, and I need to use this flag in the NSIS installer.

My problem: When redrawing, I don’t know how to erase the transparent background so that I can draw a “transparent canvas”. This is important when the user changes the text inside the checkbox, and I need to redraw it. I think I ran into a problem that everyone should get with transparent windows.

How can I clear a transparent window . Note that I am familiar with WinAPI that you cannot really clear the AFAIK window because you are simply redrawing the window. So I'm looking for advice on what methods I can use to redraw the window, for example:

  • Send a repaint message to the parent window, which we hope will repaint the parent (which sits under this flag) without sending the message to its children (i.e., the flag). I tried this, it makes the checkbox a lot of flicker.
  • Perhaps this is a transparent brush / paint function. I don’t know what I could use for drawing the whole window of a checkbox that essentially clears the window? I tried this, for some reason it closes the check box?

My code is:

case WM_SET_TEXT: { // set checkbox text // Technique 1: update parent window to clear this window RECT thisRect = {thisX, thisY, thisW, thisH}; InvalidateRect(parentHwnd, &thisRect, TRUE); } break; case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); // Technique 2: SetBkMode(hdc, TRANSPARENT); Rectangle(hdc, thisX, thisY, thisW, thisH); // doesn't work just makes the window a big black rectangle? EndPaint(hwnd, &ps); } break; 
+6
source share
2 answers

You need to process the WM_ERASEBBKGND message. Something like the following should work!

 case WM_ERASEBKGND: { RECT rcWin; RECT rcWnd; HWND parWnd = GetParent( hwnd ); // Get the parent window. HDC parDc = GetDC( parWnd ); // Get its DC. GetWindowRect( hwnd, &rcWnd ); ScreenToClient( parWnd, &rcWnd ); // Convert to the parent co-ordinates GetClipBox(hdc, &rcWin ); // Copy from parent DC. BitBlt( hdc, rcWin.left, rcWin.top, rcWin.right - rcWin.left, rcWin.bottom - rcWin.top, parDC, rcWnd.left, rcWnd.top, SRC_COPY ); ReleaseDC( parWnd, parDC ); } break; 
0
source

Try removing window style WS_CLIPCHILDREN

0
source

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


All Articles