# Techniques to "Clear" a transparent windows client area

This topic is 2348 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello

I have created a Transparent Checkbox in Win32 C++. I have made it because as far as I know you cant have a transparent checkbox in native win32 and I need to use this checkbox in a NSIS installer.

My Problem: When repainting, I don't know how to erase my transparent background so I can draw on a "clear canvas". This is important when the user changes the text inside the checkbox and I need to repaint it. I guess I have run into the problem everyone must get with transparent windows.

What is the way I can clear my transparent window, Note I am familiar with WinAPI that you cant really clear a window AFAIK because you just repaint over the window. So I am looking for advice on what techniques I can use to redraw the window such as:

- Send a repaint message to the parent window which will hopefully repaint the parent(which is the sit below the checkbox) withut sending a message down to its children(ie, the checkbox). I've tried this, it make the checkbox have a lot of flickering.
- Maybe theres a transparent brush/paint function I dont know about that I could use to paint over the whole checkbox window which will essentially clear the window? I've tried this it makes the checkbox window black for some reason?

My code:
 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;  Edited by gretty

##### Share on other sites
What does "transparent" mean in this context? What are you expecting to see "through" the checkbox control?

##### Share on other sites
I'm expecting to see the parent window or whatever window sits behind the checkbox. The painting of the Checkbox is just, set background colour to transparent, TextOut the checkbox label/text , Rectangle for the checkbox and finally use the marlett font for the tick.

##### Share on other sites
Does the parent window have the WS_CLIPCHILDREN style set?

##### Share on other sites
Given that you don't know how complex the drawing code was that rendered the stuff underneath, I'd suggest one approach might be to investigate whether you can grab your own copy of the pixel data beneath your transparent window before you draw it. There's probably a GDI function for this that people use for screengrabs.

Then when you need to clear and refresh your transparent window, you clear it to your copy of the pixel data, rather than asking all the other apps to do full refreshes via windows. Another possibility is that windows may well do some clever caching of drawn areas itself anyway, you might be able to hook into this.

Another issue is if a window underneath your transparent window needs to update something in it. If windows reckons your transparent window is obscuring a window / part of a window underneath, it may optimize out the update of the lower window. I have no idea if this is an issue or not, just a possible thing that might crop up.

##### Share on other sites
A quick google suggests that SetBkMode may not do as you intend, as far as drawing a transparent rectangle :

http://msdn.microsof...5(v=vs.85).aspx

Value Meaning
OPAQUE
Background is filled with the current background color before the text, hatched brush, or pen is drawn.
TRANSPARENT
Background remains untouched.[/quote]

It almost seems like you think that there exists some kind of 'transparent' subtractive brush that will remove what you have drawn and leave what was there underneath before your window had the chance to paint itself.

Afaik there is no such system by default (I'm sure windows vista / 7 has some things it uses for the 'aero' interface, but I wouldn't rely on this). If you wanted to be able to remove a layer without redrawing everything underneath, either you or windows would need to retain a copy of everything underneath. And I very much doubt windows does this 'just in case', as it would be very slow, memory hungry, and not needed in 99% of cases. Edited by lawnjelly

1. 1
2. 2
Rutin
19
3. 3
khawk
15
4. 4
A4L
13
5. 5

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633744
• Total Posts
3013657
×