Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Transparent background

144 views
Skip to first unread message

Peter

unread,
Nov 18, 2008, 3:14:01 AM11/18/08
to
Hi,
I am trying to add CTabCtrl into my modeless dialog.
I want to have all other buttons, editboxes, checkboxes placed on dialog
surface
and only to change values for controls by active tab on my CTabCtrl.
So for all active tabs there are the same controls, only values are changed.
I draw CTabCtrl in resource editor to include all dialog controls with
exception of OK and Cancel buttons.
Problem is when CTabCtrl redraws itself then some dialog controls stays
hidden.
I tried "Transparent" property in resource editor, but no success.
How can I enable that CTabCtrl will have transparent background to see
always all controls which are directly on dialog surface ?
Or any other tip ?

Peter

David Lowndes

unread,
Nov 18, 2008, 6:53:10 AM11/18/08
to
>I draw CTabCtrl in resource editor to include all dialog controls with
>exception of OK and Cancel buttons.
>Problem is when CTabCtrl redraws itself then some dialog controls stays
>hidden.

Peter,

What's common between which are hidden? Do you perhaps just need to
alter the tab order so that the controls are after the tab control?

Fundamentally it's not a good idea to overlap controls. If I
understand what you're doing correctly, in your usage the tab control
is just something to fire an event to your dialog so you can switch
the contents of the other controls and it's a child of your dialog the
same as the other controls on the dialog.

Dave

Peter

unread,
Nov 18, 2008, 9:03:00 AM11/18/08
to
Hi David,

Yes, you understand right what I want to do.
I want to use CTabCtrl selection only to fire event to set dialog's controls
values by CTabCtrl selected item.

Common property of hidden controls is that they are inside of CTabCtrl in
resource editor.
These controls are placed on dialog surface and CTabCtrl is also on dialog
surface.
I tried to alter tab order and make CTabCtrl with the lowest order number
but no success.

I think that problem can be resolved by setting CTabCtrl transparent
background,
thus CTabCtrl cannot hide controls if system draws it like last control. But
I was not successful with setting transparent background.
But maybe problem can be resolved by forcing to draw CTabCtrl like first
control when dialog is redrawed, I dont know how to do it.

Or any other tip ?

Peter

David Lowndes

unread,
Nov 18, 2008, 11:01:21 AM11/18/08
to
>Common property of hidden controls is that they are inside of CTabCtrl in
>resource editor.

What do you mean by "inside"? All controls (incl the tab control) are
children of the dialog, so I don't understand what you mean.

Dave

AliR (VC++ MVP)

unread,
Nov 18, 2008, 11:10:22 AM11/18/08
to
You should make the child controls/dialog children of the tab control
instead of the main dialog, that way the tab control will never go on top of
the controls.
Normally one would put the controls to go on a tab in a dialog box (Child
Dialog, not popup), and remove the border, and then create that dialog as
the child of the tab control.

Planty of examples on codeproject.com

AliR.


"Peter" <Pe...@discussions.microsoft.com> wrote in message
news:0E3B65C2-013B-4C37...@microsoft.com...

Peter

unread,
Nov 18, 2008, 1:28:01 PM11/18/08
to
"inside" I mean that in resource editor are these controls visible in inner
side of CTabCtrl.
Or in other words:
1 .Create dialog in resource editor,
2. create some controls in resource editor (edit, check, buttons),
3. Create CTabCtrl in resource editor and enlarge it to have included all
dialog controls in it.

Peter

Peter

unread,
Nov 18, 2008, 1:43:03 PM11/18/08
to
I understand what do you recommend.
Problem is that in this application is not so simple process to adjust it by
your recommendation.
The most simple should be to set CTabCtrl background transparent and then
forget
it forever.
How can I set transparent background in CTabCtrl ?
Or how to make functional "Transparent" property of CTabCtrl in resource
editor ?

Peter

AliR (VC++ MVP)

unread,
Nov 18, 2008, 3:04:37 PM11/18/08
to
I'm sorry but there is no other way to get around this problem other than
what I suggested. The controls or the child dialog have to be a child of
the tab control. Good luck with the transparent background thing: Here is
an article I wrote about transparent static, you can see what is required to
get that to work!
http://www.codeproject.com/KB/static/TransparentStaticCtrl.aspx
And here is how you would make a listbox transparent, which again will not
apply to a tab control.
http://www.codeproject.com/KB/combobox/TransListBox.aspx

I don't know why you don't want to make the controls children of the tab.
but it is easy you can simply call SetParent on the child controls to change
their parent to the tab control!

BOOL CMyDialogWithTab::OnInitDialog()
{
CDialog::OnInitDialog();

m_Child1.SetParent(&m_TabCtrl);
m_Child2.SetParent(&m_TabCtrl);
...
}

or if you are putting all your controls in a dialog box and then putting it
in the tab:
BOOL CMyDialogWithTab::OnInitDialog()
{
CDialog::OnInitDialog();

m_ChildDlg.Create(CMyChildDlg::IDD,&m_TabCtrl);

...
}

AliR.

"Peter" <Pe...@discussions.microsoft.com> wrote in message

news:08922225-B6C7-4154...@microsoft.com...

AliR (VC++ MVP)

unread,
Nov 18, 2008, 3:05:42 PM11/18/08
to
But if the controls are sibilings of the tab control, then the tab will
endup in front of the control, as the zorder changes when the controls get
focused.

AliR.


"Peter" <Pe...@discussions.microsoft.com> wrote in message

news:896A990A-502C-4538...@microsoft.com...

David Lowndes

unread,
Nov 18, 2008, 3:48:06 PM11/18/08
to
>"inside" I mean that in resource editor are these controls visible in inner
>side of CTabCtrl.
>Or in other words:
>1 .Create dialog in resource editor,
>2. create some controls in resource editor (edit, check, buttons),
>3. Create CTabCtrl in resource editor and enlarge it to have included all
>dialog controls in it.

As you're finding, that won't work. Just resize the tab control so
that it doesn't overlap the other controls.

Dave

Nico

unread,
Nov 18, 2008, 4:32:26 PM11/18/08
to
AliR (VC++ MVP) wrote:
> ...

> http://www.codeproject.com/KB/static/TransparentStaticCtrl.aspx
> And here is how you would make a listbox transparent, which again will not
> apply to a tab control.
> http://www.codeproject.com/KB/combobox/TransListBox.aspx

Horrible newbie method !
Read the Petzold to learn api bases and how a Listbox works.

AliR (VC++ MVP)

unread,
Nov 18, 2008, 4:55:26 PM11/18/08
to
"Nico" <ni...@nico.com> wrote in message
news:gfvc97$apa$1...@news.albasani.net...

What's a newbie method?

AliR.

Peter

unread,
Nov 18, 2008, 5:04:01 PM11/18/08
to

I understand your both described methods how to make controls child of
CTabCtrl.
Second one seems to be good choice for me,
but it takes much of time, because in this application there are
dependencies among member functions of some controls and member functions of
parent dialogs.

Still I am thinking about setting transparent background and I appear
that there is available GDI function ExcludeClipRect()
Why cannot be this function used to create CTabCtrl with excluded large
rectangle inside CTabCtrl ?

AliR (VC++ MVP)

unread,
Nov 18, 2008, 5:26:26 PM11/18/08
to
At no point you can specify the clip rect using ExcludeClipRect that would
actually have any effect on the way the tab control is drawn.

AliR.


"Peter" <Pe...@discussions.microsoft.com> wrote in message

news:0AD5A7A0-FB85-4235...@microsoft.com...

Peter

unread,
Nov 19, 2008, 8:59:02 AM11/19/08
to
I found solution,

added OnEraseBackground() for CMyTabCtrl derived from CTabCtrl,
and inside it commented:
// CTabCtrl::OnEraseBackground().
Added small code to the same function:

GetClientRect(&r);
r.top += 0;
r.bottom = r.top + 20;
COLORREF clrBack=GetSysColor(COLOR_3DFACE);
CBrush brBackground;
brBackground.CreateSolidBrush(clrBack);
pDC->FillRect(&r,&brBackground);

which erases only top part of CMyTabCtrl where are displayed tabs.

AliR (VC++ MVP)

unread,
Nov 19, 2008, 10:44:41 AM11/19/08
to
I'm sorry but I don't see how this code will help with your zorder problem!

That will simply not earse the background under the tab control. But the
paint routine will simply paint over it anyway!

By the way where did you get 20 from?
And what does r.Top += 0; do?

In order to find the location of the tabs of the tab control you can use
AdjustRect

CRect r;
GetClientRect(&r);

CRect r2 = r;
AdjustRect(FALSE,&r2);
r.bottom = r2.top;

COLORREF clrBack=GetSysColor(COLOR_3DFACE);
CBrush brBackground;
brBackground.CreateSolidBrush(clrBack);
pDC->FillRect(&r,&brBackground);


AliR.


"Peter" <Pe...@discussions.microsoft.com> wrote in message

news:F10FE0B9-1650-45DB...@microsoft.com...

Peter

unread,
Nov 20, 2008, 9:44:01 AM11/20/08
to
When tab control's background is not erased,
it cannot overlap other controls.
(Tab control and other controls are sibling on the same dialog.)
So when tab controls get focus, only it's tabs background is redrawed.

r.Top += 0;
does of course nothing, I only experiment with different values instead of 0.

Anyway,
thanks for your effort.
I know that my solution is not clean solution, but for business reasons
acceptable this time for me.

David Ching

unread,
Nov 20, 2008, 9:45:40 AM11/20/08
to
"AliR (VC++ MVP)" <Al...@online.nospam> wrote in message
news:KRGUk.6488$as4...@nlpi069.nbdc.sbc.com...

>> Horrible newbie method !
>> Read the Petzold to learn api bases and how a Listbox works.
>
> What's a newbie method?
>
> AliR.
>

No worries AliR, your transparent articles are very useful and are the only
way I've found to achieve transparency as well. The fact is, Win32 does not
support overlapping child controls with transparency natively. WPF is the
first serious scheme MS has come up with to do that.

-- David

AliR (VC++ MVP)

unread,
Nov 20, 2008, 2:01:01 PM11/20/08
to
You said that it will not erase the background, but only the tab surface
will be redrawn, so if it is going to draw over the controls it will do it
in it's WM_PAINT handler anyway, therefore overriding the WM_ERASEBKGND will
not buy you much.

Good luck
AliR.


"Peter" <Pe...@discussions.microsoft.com> wrote in message

news:843C8C86-E9BA-4A91...@microsoft.com...

AliR (VC++ MVP)

unread,
Nov 20, 2008, 2:02:49 PM11/20/08
to
I haven't played around with WPF much. I have to check it out and see how
it handles this situation.

AliR.

"David Ching" <d...@remove-this.dcsoft.com> wrote in message
news:47F83162-36DF-4561...@microsoft.com...

Peter

unread,
Nov 27, 2008, 2:07:02 PM11/27/08
to
I am testing this application more than week and CMyTabCtrl with my
adjustment never redraws over other controls. It seems that when CMyTabCtrl
redraws itself, it only erases background in it's main area - essential.
And it does much of work to draw tabs with texts and selections.
0 new messages