3

I am creating a dialog with a tab control. Each tab should show different set of controls, so I have created child dialog boxes in resource editor to behave like pages.

I have used instructions from this post to do this.

In resource editor I made dialog boxes without border, set their styles to Child, removed system menu, and I have set flags Control and Control Parent to true.

In my child dialog box procedures I have handled WM_INITDIALOG by adding EnableThemeDialgTexture(handleOfmyDialog, ETDT_ENABLETAB); and returning TRUE. No WM_ERASEBKGND, WM_PAINT or WM_CTLCOLORDLG have been overridden.

In main dialog box that contains tab control, I have created "child dialogs" with CreateDialog function, and have used MoveWindow to properly position them.

I did not use EndDialog to destroy "child dialogs" on IDCANCEL or WM_CLOSE, I think that they will get destroyed automatically.

I have used Visual Studio 2013 on Windows 8.1 to do all this.

There seems to be no problem on Windows 7 and Windows 8.1, but maybe my eyes are playing tricks with me, since the background color of the tab control is similar to the default background color of the dialog box. The problem is best seen on Windows XP, as shown on the picture below:

enter image description here

How can I make background color of "child dialogs" ( and their child controls like checkbox/trackbar/radio button/static control ) to be transparent ( match the background color of tab control )?

Thank you.

Community
  • 1
  • 1
AlwaysLearningNewStuff
  • 2,939
  • 3
  • 31
  • 84
  • Did you try calling `EnableThemeDialogTexture` for the child dialog as well? I'm not sure it supports child dialogs but it's worth trying if you haven't already. – Jonathan Potter Nov 06 '14 at 23:14
  • @JonathanPotter: I called `EnableThemeDialogTexture` in every child dialog procedure, on `WM_INITDIALOG`. I didn't do anything in main dialog's `WM_INITDIALOG`, except creating child dialogs with CreateDialog`. – AlwaysLearningNewStuff Nov 07 '14 at 00:32
  • In that case I'd say it's not supported for children (i.e. children of children). One option would be to subclass the dialog and do your own background rendering using the tab part from the theme. – Jonathan Potter Nov 07 '14 at 01:08

2 Answers2

2

This is a pretty straight-forward problem. You can't see the mistake on later Windows version because they no longer use a gradient for the "texture". EnableThemeDialogTexture() worked just fine, your dialog certainly has the same texture as your tabcontrol. The brush origin starts at the upper-left corner of the dialog. Like it does for the tabcontrol. But the dialog is not positioned correctly, now the gradients are mis-aligned and the dialog no longer blends.

You need to move the dialog so it is located correctly inside the tab page area. The relevant line of code from the MSDN article:

// Size the dialog box. 
SetWindowPos(hwndDlg, NULL, 
    0, 0,                                                           // <=== here!
    rcTab.right + cyMargin + (2 * GetSystemMetrics(SM_CXDLGFRAME)), 
    rcTab.bottom + rcButton.bottom + (2 * cyMargin)
    + (2 * GetSystemMetrics(SM_CYDLGFRAME)) 
    + GetSystemMetrics(SM_CYCAPTION), 
    SWP_NOMOVE | SWP_NOZORDER); 

Positioned at (0, 0) in the client area of the tabcontrol, now the gradients align.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • I have reread your linked MSDN article, and have a problem. That code resizes dialog box to fit entire client area of the tab control, and then destroys that dialog when tab selection changes, creating another corresponding child dialog. Then it resizes that new dialog box to the tab's client area again. My problem is that **all child dialogs must exist** and can only be simultaneously hidden/shown. Therefore I don't know how to apply your code snippet to adress this issue. Can you suggest a solution? Thank you. – AlwaysLearningNewStuff Nov 08 '14 at 23:35
  • This issue has absolutely nothing to do with the creation of the dialogs. Just where you put them. – Hans Passant Nov 08 '14 at 23:40
  • Unfortunately, [it seems things are not so easy after all...](http://stackoverflow.com/questions/27085427/common-controls-are-not-properly-painted-when-i-resize-window) – AlwaysLearningNewStuff Nov 28 '14 at 08:51
1

Hans’ observation is right, but with the wrong conclusions.

Indeed, EnableThemeDialogTexture() worked: There clearly is a gradient on the background of the Slider control. And indeed it does not line up with the tab control’s background.

However, this is not an alignment problem. The gradient you see on the Slider control is the correct gradient according to EnableThemeDialogTexture(). The gradient on the background is actually the wrong one. You can clearly see it with enhanced contrast – the background gradient is blocky and coarse, while the Slider’s gradient is perfectly fine.

I observed this exact behavior when the main window had the WS_CLIPCHILDREN style set while the Z order was wrong (tab above child). Move the child dialog boxes to the top of the Z order via SetWindowPos(child, HWND_TOP, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE) and it should align perfectly and not be blocky any more.

Krishty
  • 164
  • 12
  • Same as with your answer to my other question: I can not test your solution for now, but have upvoted. If I manage to test it and it works I will officially accept it. Thanks again for your effort! :) – AlwaysLearningNewStuff Oct 19 '19 at 12:52