Jump to content
  • Advertisement
Sign in to follow this  
gretty

Techniques to "Clear" a transparent windows client area

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

If you intended to correct an error in the post then please contact us.

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 this post


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

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!