I am trying to insert dialog boxes, as separate pages, into tab control.
I have created the dialog boxes successfully in resource editor, with all necessary styles.
Since my application uses visual styles, I ran into problem with transparency of the dialog's child controls ( radio button, trackbar and similar ).
I have found a solution in
EnableThemeDialogTexture
API. Calling it in
WM_INITDIALOG
solves transparency issues of dialog's child controls. However, this API draws portion of tab control's background as dialog's background.
After inserting the dialog box as a page, mismatch between a dialog's and tab's background appear on
Windows XP. Please see
this image[
^].
I have asked here and on
Stack Overflow[
^] why is this the case and got an answer.
I have tried to reposition the dialog box to fit tab control's display area but had no success. I am off by 3 pixels.
I will submit code that reproduces my results below, and the logic behind it will be in comments.
INSTRUCTIONS FOR CREATING CODE EXAMPLE THAT REPRODUCES THE PROBLEM:
1.) Create
default Win32 project
in Visual Studio;
2.) Create small dialog box in resource editor and add 2 or 3 controls for each;
I have added trackbar, radio buttons, checkboxes and static controls; These are problematic when transparency is needed;
3.) Add the following dialog procedure above the
// Message handler for about box.
in your
.cpp
template:
INT_PTR CALLBACK FirstTabProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
EnableThemeDialogTexture(hDlg, ETDT_ENABLETAB);
return (INT_PTR)TRUE;
}
return (INT_PTR)FALSE;
}
4.) add a tab control to the
About
dialog box, it is in your resource editor;
5.) Add the following
WM_INITDIALOG
handler to
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
dialog procedure, in your
.cpp
template:
case WM_INITDIALOG:
{
HWND hwndTab = GetDlgItem(hDlg, IDC_TAB1);
RECT rcTab = { 0 }, rcTabItem = { 0 };
GetClientRect(hwndTab, &rcTab);
TabCtrl_GetItemRect(hwndTab, 0, &rcTabItem);
TCITEM tci = { 0 };
tci.mask = TCIF_TEXT | TCIF_PARAM;
tci.pszText = L"First tab";
HWND FirstPageDialogBox = CreateDialog(hInst,
MAKEINTRESOURCE(IDD_DIALOG1), hDlg, (DLGPROC)FirstTabProc);
ShowWindow(FirstPageDialogBox , SW_SHOW);
POINT pt = { 0 };
ClientToScreen(hwndTab, &pt);
ScreenToClient(hDlg, &pt);
TabCtrl_AdjustRect(hwndTab, FALSE, &rcTab);
MoveWindow(FirstPageDialogBox ,
rcTab.left + pt.x, rcTabItem.bottom + pt.y + 3, rcTab.right - rcTab.left,
rcTab.bottom - rcTabItem.bottom - 3, TRUE);
tci.lParam = (LPARAM)FirstPageDialogBox;
SendMessage(hwndTab, TCM_INSERTITEM, (WPARAM)0, (LPARAM)&tci);
}
return (INT_PTR)TRUE;
6.) Now we are left with technicalities. First we shall add the following in
stdafx.h
just below
#include <windows.h>
:
#include <windowsx.h>
#include <CommCtrl.h>
#include <Uxtheme.h>
#pragma comment(lib, "comctl32.lib")
#pragma comment(lib, "UxTheme.lib")
#pragma comment( linker, "/manifestdependency:\"type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' \
language='*'\"")
7.) Next, we initialize common controls in
ATOM MyRegisterClass(HINSTANCE hInstance)
:
INITCOMMONCONTROLSEX iccex = { 0 };
iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
iccex.dwICC = ICC_TAB_CLASSES | ICC_STANDARD_CLASSES | ICC_BAR_CLASSES;
InitCommonControlsEx(&iccex);
That would be all. Please remember to test the application on
Windows XP to see the problem.
QUESTION:
How do I insert dialog box into tab control's display area, so their background's properly align?
Thank you.