Discussion:
How to make a control transparent to the underlying tab ctrl?
(too old to reply)
Juan Dent
2006-04-19 01:24:02 UTC
Permalink
Hi,

I have a CFormView that has a CTabCtrl and I have controls in the tab items.
I need to make the BkColor of these controls the same as the background of
the CTabCtrl - which in XP is a gradient. I first thought I could use
SetBkMode(TRANSPARENT) but that makes the BkColors the same color as the
CFormView's - not the gradually darkened CTabCtrl!!

Is there a simple way out of this?
--
Thanks in advance,

Juan Dent, M.Sc.
Joseph M. Newcomer
2006-04-19 01:59:44 UTC
Permalink
SetBkMode is unrelated to this problem. This simply explains how text should be drawn on
the control's background, which has nothing to do with how the background is drawn.

COM handles this with something called "ambient properties", but I don't know if that
handles gradient fills either.

You may be asking for something that is not currently supported (transparent controls of
the type you describe *are* supported in Vista).

Edit controls will be particularly intractable. Static controls will probably be the
easiest.

Look at WS_EXTRANSPARENT, and also look at "Layered Windows" articles in the MSDN. There
are hazards to this, such as a completely transparent background will not respond to mouse
clicks in the control, which may lead to other problems (OTOH, a transparency of 100%-1 [I
forget if this is 254 or 1] may solve this problem without introducing intolerably ugly
artifact.s

joe
Post by Juan Dent
Hi,
I have a CFormView that has a CTabCtrl and I have controls in the tab items.
I need to make the BkColor of these controls the same as the background of
the CTabCtrl - which in XP is a gradient. I first thought I could use
SetBkMode(TRANSPARENT) but that makes the BkColors the same color as the
CFormView's - not the gradually darkened CTabCtrl!!
Is there a simple way out of this?
Joseph M. Newcomer [MVP]
email: ***@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
--
NewsGuy.Com 30Gb $9.95 Carry Forward and On Demand Bandwidth
Juan Dent
2006-04-19 17:19:02 UTC
Permalink
Hi and thanks for the prompt reply.

However, I disagree in that SetBkColor is unrelated to the problem - rather
IT IS the problem! I need the text's background color to match the tab ctrl's
background color AT THE location of the control (ie. taking into accout the
gradient of the tab ctrl's background in XP).

Any other ideas?
--
Thanks in advance,

Juan Dent, M.Sc.
Post by Joseph M. Newcomer
SetBkMode is unrelated to this problem. This simply explains how text should be drawn on
the control's background, which has nothing to do with how the background is drawn.
COM handles this with something called "ambient properties", but I don't know if that
handles gradient fills either.
You may be asking for something that is not currently supported (transparent controls of
the type you describe *are* supported in Vista).
Edit controls will be particularly intractable. Static controls will probably be the
easiest.
Look at WS_EXTRANSPARENT, and also look at "Layered Windows" articles in the MSDN. There
are hazards to this, such as a completely transparent background will not respond to mouse
clicks in the control, which may lead to other problems (OTOH, a transparency of 100%-1 [I
forget if this is 254 or 1] may solve this problem without introducing intolerably ugly
artifact.s
joe
Post by Juan Dent
Hi,
I have a CFormView that has a CTabCtrl and I have controls in the tab items.
I need to make the BkColor of these controls the same as the background of
the CTabCtrl - which in XP is a gradient. I first thought I could use
SetBkMode(TRANSPARENT) but that makes the BkColors the same color as the
CFormView's - not the gradually darkened CTabCtrl!!
Is there a simple way out of this?
Joseph M. Newcomer [MVP]
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
--
NewsGuy.Com 30Gb $9.95 Carry Forward and On Demand Bandwidth
Joseph M. Newcomer
2006-04-20 04:35:13 UTC
Permalink
Getting the text to draw without the bounding box only solves some of the problem, and it
won't work at all in some controls, such as edit controls. In fact, if you think
SetBkMode(TRANSPARENT) appears to work in an edit control, try doing some internal
deletions of characters, internal insertions of characters, etc. Type ABC<<I<<W and see
what a mess you get (where < means left arrow) if you SetBkMode(TRANSPARENT). So edit
controls and the edit control of combo boxes are going to be dysfunctional in this regard.
Also, I've had problems trying to play games with CListCtrl and CTreeCtrl backgrounds,
even with owner-draw set. So I consider the problem to be fairly intractable in < Vista.
On the other hand, Vista definitely supports what you want, and a lot more. Sometimes it
is best to not try to do things that the current system actively works against.
joe
Post by Juan Dent
Hi and thanks for the prompt reply.
However, I disagree in that SetBkColor is unrelated to the problem - rather
IT IS the problem! I need the text's background color to match the tab ctrl's
background color AT THE location of the control (ie. taking into accout the
gradient of the tab ctrl's background in XP).
Any other ideas?
Joseph M. Newcomer [MVP]
email: ***@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
--
NewsGuy.Com 30Gb $9.95 Carry Forward and On Demand Bandwidth
Doug Harrison [MVP]
2006-04-20 02:35:26 UTC
Permalink
Post by Juan Dent
Hi,
I have a CFormView that has a CTabCtrl and I have controls in the tab items.
I need to make the BkColor of these controls the same as the background of
the CTabCtrl - which in XP is a gradient. I first thought I could use
SetBkMode(TRANSPARENT) but that makes the BkColors the same color as the
CFormView's - not the gradually darkened CTabCtrl!!
Is there a simple way out of this?
If you are hosting child dialogs inside the CTabCtrl, you may need to call
the following in your subdialog OnInitDialog functions:

EnableThemeDialogTexture(m_hWnd, ETDT_ENABLETAB);

There are also DrawThemeParentBackground and DrawThemeBackground to
consider. See this message for more on that, where I discussed drawing
"hover" buttons that look correct on gradient backgrounds:

http://groups.google.com/group/microsoft.public.vc.mfc/msg/7650b34723e74f72
--
Doug Harrison
Visual C++ MVP
Juan Dent
2006-04-21 01:58:02 UTC
Permalink
Hi,

I read your article and tested it with a CStatic derived class. I cannot
obtain a background color that matches the color of the gradient tab control
on which it stands. The back color seems to always be white. I used the
following in the overriden void CThemedStatic::DrawItem( LPDRAWITEMSTRUCT
lpDrawItemStruct ):

---------
::DrawThemeParentBackground(m_hWnd, lpDrawItemStruct->hDC, 0);
::DrawThemeBackground(
hTheme,
lpDrawItemStruct->hDC,
EP_EDITTEXT,
ETS_NORMAL,
&rect,
0);
----------
Any help here? Also- I get a border when I really don't want one (it is
really supposed to be a static control - I am using edit only because there
seems to be NO theme support for static controls!!)
--
Thanks in advance,

Juan Dent, M.Sc.
Post by Doug Harrison [MVP]
Post by Juan Dent
Hi,
I have a CFormView that has a CTabCtrl and I have controls in the tab items.
I need to make the BkColor of these controls the same as the background of
the CTabCtrl - which in XP is a gradient. I first thought I could use
SetBkMode(TRANSPARENT) but that makes the BkColors the same color as the
CFormView's - not the gradually darkened CTabCtrl!!
Is there a simple way out of this?
If you are hosting child dialogs inside the CTabCtrl, you may need to call
EnableThemeDialogTexture(m_hWnd, ETDT_ENABLETAB);
There are also DrawThemeParentBackground and DrawThemeBackground to
consider. See this message for more on that, where I discussed drawing
http://groups.google.com/group/microsoft.public.vc.mfc/msg/7650b34723e74f72
--
Doug Harrison
Visual C++ MVP
Doug Harrison [MVP]
2006-04-21 02:27:41 UTC
Permalink
Post by Juan Dent
Hi,
I read your article and tested it with a CStatic derived class. I cannot
obtain a background color that matches the color of the gradient tab control
on which it stands. The back color seems to always be white. I used the
following in the overriden void CThemedStatic::DrawItem( LPDRAWITEMSTRUCT
---------
::DrawThemeParentBackground(m_hWnd, lpDrawItemStruct->hDC, 0);
::DrawThemeBackground(
hTheme,
lpDrawItemStruct->hDC,
EP_EDITTEXT,
ETS_NORMAL,
&rect,
0);
----------
Any help here? Also- I get a border when I really don't want one (it is
really supposed to be a static control - I am using edit only because there
seems to be NO theme support for static controls!!)
What happens if you omit the DrawThemeBackground? (Sorry, I don't have
experience with owner-drawn static controls and themes.)

Also, I don't know if this will help you, but I've had to do the following
in a couple of SDI apps:

BOOL TransparentDialogBar::OnEraseBkgnd(CDC* pDC)
{
if (m_themed)
{
DrawThemeParentBackground(m_hWnd, pDC->m_hDC, 0);
return true;
}

return CDialogBar::OnEraseBkgnd(pDC);
}
--
Doug Harrison
Visual C++ MVP
Loading...