Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////////////////
- /// Resource file
- 1 DIALOGEX 32, 32, 300, 200
- STYLE DS_MODALFRAME | WS_POPUP |
- WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
- CAPTION "Sample"
- FONT 8, "MS Shell Dlg"
- BEGIN
- LTEXT "Hello World!",100,7,8,100,10
- END
- 2 DIALOGEX DISCARDABLE 32, 32, 200, 76
- STYLE WS_CHILD | DS_CONTROL
- CAPTION "Sample"
- FONT 8, "MS Shell Dlg"
- BEGIN
- LTEXT "A mumbler is needed.",-1,7,8,100,10
- AUTORADIOBUTTON "Do not &obtain a mumber now",
- 100,17,24,180,10
- AUTORADIOBUTTON "Obtain a mumbler auto&matically",
- 101,17,34,180,10
- AUTORADIOBUTTON "&Enter mumbler manually",
- 102,17,44,180,10
- DEFPUSHBUTTON "OK",IDOK,92,58,50,14
- PUSHBUTTON "Cancel",IDCANCEL,146,58,50,14
- END
- ////////////////////////////////////////
- /// Here's the code
- #include <windows.h>
- #include <windowsx.h>
- #include <uxtheme.h>
- #include <commctrl.h>
- #pragma comment(lib, "uxtheme.lib")
- #pragma comment(lib, "comctl32.lib")
- #pragma comment(linker, \
- "\"/manifestdependency:type='Win32' "\
- "name='Microsoft.Windows.Common-Controls' "\
- "version='6.0.0.0' "\
- "processorArchitecture='*' "\
- "publicKeyToken='6595b64144ccf1df' "\
- "language='*'\"")
- #define DYNACONTROL_WINDOW "_ODynaControlWindow_"
- HINSTANCE g_hInst = NULL;
- HWND g_hDlg = NULL;
- HWND g_hWndTab = NULL;
- HWND g_hStatic = NULL;
- HWND g_hChildDlg = NULL;
- HWND g_hCustomPanel = NULL;
- INT_PTR CALLBACK DlgProc(HWND hdlg, UINT uMsg,
- WPARAM wParam, LPARAM lParam);
- INT_PTR CALLBACK ChildDlgProc(HWND hdlg, UINT uMsg,
- WPARAM wParam, LPARAM lParam);
- HRESULT OnSize(HWND hwndTab, LPARAM lParam);
- BOOL OnNotify(HWND hwndTab, HWND hwndDisplay, LPARAM lParam);
- HWND DoCreateTabControl(HWND hwndParent);
- void CenterChildControls();
- int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
- {
- g_hInst = hInstance;
- return DialogBox(hInstance, MAKEINTRESOURCE(1), 0, DlgProc);
- }
- INT_PTR CALLBACK DlgProc(HWND hdlg, UINT uMsg,
- WPARAM wParam, LPARAM lParam)
- {
- switch (uMsg) {
- case WM_INITDIALOG:
- {
- g_hDlg = hdlg;
- CheckRadioButton(hdlg, 100, 102, 100);
- g_hWndTab = DoCreateTabControl(hdlg);
- g_hStatic = GetDlgItem(hdlg, 100);
- g_hChildDlg = CreateDialog(g_hInst, MAKEINTRESOURCE(2), g_hDlg, ChildDlgProc);
- EnableThemeDialogTexture(g_hChildDlg, ETDT_ENABLETAB);
- WNDCLASS wndcls = {0};
- wndcls.style = CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW;
- wndcls.lpfnWndProc = DefWindowProc;
- wndcls.cbClsExtra = wndcls.cbWndExtra = 0;
- wndcls.hInstance = g_hInst;
- wndcls.hIcon = NULL;
- wndcls.hbrBackground = NULL;
- wndcls.lpszMenuName = NULL;
- wndcls.lpszClassName = DYNACONTROL_WINDOW;
- if (RegisterClass(&wndcls))
- {
- g_hCustomPanel = CreateWindowEx(WS_EX_CONTROLPARENT,
- DYNACONTROL_WINDOW, NULL,
- WS_CHILD | WS_TABSTOP | WS_GROUP,
- 0, 0, 100, 100,
- g_hDlg,
- NULL,
- g_hInst,
- NULL
- );
- if ( g_hCustomPanel )
- {
- HWND hStatic = CreateWindow(WC_STATIC, "My Panel", WS_CHILD|WS_VISIBLE|WS_GROUP|SS_LEFT,
- 10, 10, 100, 30,
- g_hCustomPanel,
- NULL, g_hInst, NULL);
- EnableThemeDialogTexture(g_hCustomPanel, ETDT_ENABLETAB);
- }
- }
- CenterChildControls();
- }
- return TRUE;
- case WM_SIZE:
- return OnSize(g_hWndTab, lParam);
- case WM_NOTIFY:
- return OnNotify(g_hWndTab, g_hStatic, lParam);
- case WM_COMMAND:
- switch (GET_WM_COMMAND_ID(wParam, lParam)) {
- case IDOK:
- break;
- case IDCANCEL:
- EndDialog(hdlg, -1);
- break;
- }
- }
- return FALSE;
- }
- INT_PTR CALLBACK ChildDlgProc(HWND hdlg, UINT uMsg,
- WPARAM wParam, LPARAM lParam)
- {
- switch (uMsg) {
- case WM_INITDIALOG:
- return TRUE;
- }
- return FALSE;
- }
- BOOL OnNotify(HWND hwndTab, HWND hwndDisplay, LPARAM lParam)
- {
- switch (((LPNMHDR)lParam)->code)
- {
- case TCN_SELCHANGING:
- {
- // Return FALSE to allow the selection to change.
- return FALSE;
- }
- case TCN_SELCHANGE:
- {
- int iPage = TabCtrl_GetCurSel(hwndTab);
- ShowWindow(g_hStatic, 0 == iPage);
- ShowWindow(g_hChildDlg, 1 == iPage);
- ShowWindow(g_hCustomPanel, 2 == iPage);
- break;
- }
- }
- return TRUE;
- }
- void CenterControl(HWND hWnd, const RECT& rcTab)
- {
- RECT rc;
- GetWindowRect(hWnd, &rc);
- ScreenToClient(g_hDlg, (POINT*)&rc);
- ScreenToClient(g_hDlg, ((POINT*)&rc)+1);
- SetWindowPos(hWnd, HWND_TOP,
- rcTab.left+(rcTab.right-rcTab.left-(rc.right-rc.left))/2,
- rcTab.top+(rcTab.bottom-rcTab.top-(rc.bottom-rc.top))/2,
- -1, -1, SWP_NOSIZE);
- }
- void CenterChildControls()
- {
- // Center the static control
- RECT rcTab;
- GetWindowRect(g_hWndTab, &rcTab);
- ScreenToClient(g_hDlg, (POINT*)&rcTab);
- ScreenToClient(g_hDlg, ((POINT*)&rcTab)+1);
- TabCtrl_AdjustRect(g_hWndTab, FALSE, &rcTab);
- CenterControl(g_hStatic, rcTab);
- CenterControl(g_hChildDlg, rcTab);
- CenterControl(g_hCustomPanel, rcTab);
- }
- #define TAB_GAP_TO_DLG 20
- HRESULT OnSize(HWND hwndTab, LPARAM lParam)
- {
- if (hwndTab == NULL)
- return E_INVALIDARG;
- // Resize the tab control to fit the client are of main window.
- if (!SetWindowPos(hwndTab, HWND_TOP, TAB_GAP_TO_DLG, TAB_GAP_TO_DLG, GET_X_LPARAM(lParam)-TAB_GAP_TO_DLG*2, GET_Y_LPARAM(lParam)-TAB_GAP_TO_DLG*2, SWP_SHOWWINDOW))
- return E_FAIL;
- CenterChildControls();
- return S_OK;
- }
- #define DAYS_IN_WEEK 7
- HWND DoCreateTabControl(HWND hwndParent)
- {
- RECT rcClient;
- INITCOMMONCONTROLSEX icex;
- HWND hwndTab;
- TCITEM tie;
- int i;
- // Initialize common controls.
- icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
- icex.dwICC = ICC_TAB_CLASSES;
- InitCommonControlsEx(&icex);
- GetClientRect(hwndParent, &rcClient);
- hwndTab = CreateWindow(WC_TABCONTROL, "",
- WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE,
- TAB_GAP_TO_DLG, TAB_GAP_TO_DLG, rcClient.right-TAB_GAP_TO_DLG*2, rcClient.bottom-TAB_GAP_TO_DLG*2,
- hwndParent, NULL, g_hInst, NULL);
- if (hwndTab == NULL)
- {
- return NULL;
- }
- // Add tabs for each day of the week.
- tie.mask = TCIF_TEXT | TCIF_IMAGE;
- tie.iImage = -1;
- TCHAR* arrTabItems[] = {"No child dialog", "Child dialog", "Custom panel"};
- for (i = 0; i < _countof(arrTabItems); i++)
- {
- tie.pszText = arrTabItems[i];
- if (TabCtrl_InsertItem(hwndTab, i, &tie) == -1)
- {
- DestroyWindow(hwndTab);
- return NULL;
- }
- }
- return hwndTab;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement