-
January 14th, 2009, 07:06 AM
#1
transparent static control and display icon
hi, i want to make my static control transparent, so it will draw transsparent background with text.
and i want to have a transparent static where i can display my icon.
i can set the WS_EX_TRANSPARENT but that does not make it transparent yet?
-
January 14th, 2009, 10:17 AM
#2
Re: transparent static control and display icon
Did you try using SetBkMode?
http://msdn.microsoft.com/en-us/libr...62(VS.85).aspx
If you are using MFC you could do something like:
Code:
if(CTLCOLOR_STATIC == nCtlColor)
{
pDC->SetBkMode(TRANSPARENT);
return (HBRUSH)GetStockObject(NULL_BRUSH);
}
http://msdn.microsoft.com/en-us/library/0wwk06hc.aspx
Best Wishes,
-David Delaune
-
January 14th, 2009, 11:04 AM
#3
Re: transparent static control and display icon
Randor has a start, but there is more to it.
You need to set the back mode and color, then copy the bitmap to a monochrome. Using that monochrome bitmap as a mask, you then can paint a seemingly transparent background by just painting the rest of the bitmap.
There are hundreds of threads on this subject in this forum, just do a search.
-Erik
-
January 14th, 2009, 11:13 AM
#4
Re: transparent static control and display icon
i dont use MFC (this is the winapi forum not VC++ forum)
WS_EX_TRANSPARENT and SetBkMode seems to work fine.
now i just need to use DrawIcon... should i put it in WM_PAINT
-
January 14th, 2009, 11:39 AM
#5
Re: transparent static control and display icon
Originally Posted by cj-wijtmans
i dont use MFC (this is the winapi forum not VC++ forum)
WS_EX_TRANSPARENT and SetBkMode seems to work fine.
now i just need to use DrawIcon... should i put it in WM_PAINT
My apologies, I am generally on codeproject.com and have only recently signed up here and have not become familiar with the codeguru forum peculiars and layout.
Yes, the WM_PAINT would be the correct location for calling DrawIcon. If you are concerned with flicker then perhaps you could experiment with disabling the WM_ERASEBKGND message by returning 1 or adding WS_CLIPCHILDREN to the parent window.
Best Wishes,
-David Delaune
-
January 14th, 2009, 11:59 AM
#6
Re: transparent static control and display icon
i already have the WS_CLIPCHILDREN flag set i wont have to handle the ERASEBKGND msg?
i tried drawing the icon there but it does not work it does not show up.
Code:
PAINTSTRUCT ps = {0};
HDC hdc = ::BeginPaint(Handle(), &ps);
::DrawIcon(hdc, 0, 0, Arrow);
::EndPaint(Handle(), &ps);
-
January 14th, 2009, 12:20 PM
#7
Re: transparent static control and display icon
Originally Posted by cj-wijtmans
i already have the WS_CLIPCHILDREN flag set i wont have to handle the ERASEBKGND msg?
WS_CLIPCHILDREN on the parent window will cause it to exclude the child when redrawing. Don't worry about the WM_ERASEBKGND message unless you have flicker issues that you want to resolve.
Originally Posted by cj-wijtmans
i tried drawing the icon there but it does not work it does not show up.
Have you invalidated the area associated with your static control? Try calling InvalidateRect on the client coordinates of the static.
http://msdn.microsoft.com/en-us/libr...03(VS.85).aspx
http://msdn.microsoft.com/en-us/libr...93(VS.85).aspx
Best Wishes,
-David Delaune
-
January 14th, 2009, 12:32 PM
#8
Re: transparent static control and display icon
thanks alot for your help
-
January 14th, 2009, 03:13 PM
#9
Re: transparent static control and display icon
Originally Posted by Randor
WS_CLIPCHILDREN on the parent window will cause it to exclude the child when redrawing.
Even if control has WS_EX_TRANSPARENT style?
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
January 14th, 2009, 03:36 PM
#10
Re: transparent static control and display icon
Originally Posted by VladimirF
Even if control has WS_EX_TRANSPARENT style?
Yes, even if the static control has the WS_EX_TRANSPARENT style. When the parent window is redrawn it will clip the child if the parent has the WS_CLIPCHILDREN flag.
By default, the windows affected by RedrawWindow depend on whether the specified window has the WS_CLIPCHILDREN style. Child windows that are not the WS_CLIPCHILDREN style are unaffected; non-WS_CLIPCHILDREN windows are recursively validated or invalidated until a WS_CLIPCHILDREN window is encountered.
http://msdn.microsoft.com/en-us/libr...00(VS.85).aspx
Best Wishes,
-David Delaune
-
January 14th, 2009, 03:39 PM
#11
Re: transparent static control and display icon
If you want all of your static controls be transparent you can use the same method that mentioned in post 2 but for win32 API, especially for dialog box:
Code:
case WM_CTLCOLORSTATIC:
SetBkMode ( (HDC)wParam, TRANSPARENT);
return (BOOL)hbrush;
-
January 14th, 2009, 06:11 PM
#12
Re: transparent static control and display icon
Originally Posted by Randor
Yes, even if the static control has the WS_EX_TRANSPARENT style. When the parent window is redrawn it will clip the child if the parent has the WS_CLIPCHILDREN flag.
Then who draws the background under WS_EX_TRANSPARENT controls?
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
January 14th, 2009, 06:37 PM
#13
Re: transparent static control and display icon
i think WS_EX_TRANSPARENT will tell the parent window to draw the area behind the child first even if WS_CLIPCHILDREN is set
-
January 14th, 2009, 06:43 PM
#14
Re: transparent static control and display icon
Originally Posted by cj-wijtmans
i think WS_EX_TRANSPARENT will tell the parent window to draw the area behind the child first even if WS_CLIPCHILDREN is set
That was my point
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
January 14th, 2009, 07:23 PM
#15
Re: transparent static control and display icon
Originally Posted by VladimirF
Then who draws the background under WS_EX_TRANSPARENT controls?
You are correct. I knew you were baiting me when you posted the response so I took the bait. The background is painted behind the child window and therefore non-clipped during the parent window painting. However during the recursive invalidation the child window is excluded/clipped.
Best Wishes,
-David Delaune
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|