I am making a PropertySheet control with the Windows API, and for some reason tabs are closing when I click on them.
For instance, if I add 4 tabs:
Then if I click on any of those tabs except the active one (in which case nothing happens), it becomes:
And if I click on the inactive tab it disappears, leaving only one tab left.
I am creating the tabs with a dialog template in memory, created like this:
static const char initText[] = "Tab";
pagetemplate = (DLGTEMPLATE*)new char[sizeof(DLGTEMPLATE) + sizeof(initText) * 2];
pagetemplate->style = WS_POPUP | DS_3DLOOK | WS_BORDER | WS_SYSMENU | WS_CAPTION | DS_CENTER;
pagetemplate->cdit = 0; // 0 controls
pagetemplate->cx = PROP_SM_CXDLG;
pagetemplate->cy = PROP_SM_CYDLG;
LPWORD lpword = (LPWORD)(pagetemplate + 1);
*lpword++ = 0; // no menu
*lpword++ = 0; // predefined dialog box class (by default)
MultiByteToWideChar(CP_ACP, NULL, initText, -1, (LPWSTR)lpword, sizeof(initText) * 2);
Then creating the PropertySheet like this:
PROPSHEETHEADER psh;
SecureZeroMemory(&psh, sizeof(PROPSHEETHEADER));
psh.dwSize = sizeof(PROPSHEETHEADER);
psh.dwFlags = PSH_MODELESS | PSH_PROPSHEETPAGE | PSH_USECALLBACK;
psh.pszCaption = "Window";
psh.nPages = 1;
psh.nStartPage = 0;
PROPSHEETPAGE pages[1];
SecureZeroMemory(pages, sizeof(PROPSHEETPAGE));
pages[0].dwSize = sizeof(PROPSHEETPAGE);
pages[0].dwFlags = PSP_DLGINDIRECT;
pages[0].pResource = CGTabWindow::pagetemplate;
pages[0].pfnDlgProc = DialogProc;
pages[0].lParam = (LPARAM)this;
psh.ppsp = (PROPSHEETPAGE*)&pages;
propsheet = PropertySheet(&psh);
And adding the four pages like this:
PROPSHEETPAGE page;
SecureZeroMemory(&page, sizeof(PROPSHEETPAGE));
page.dwSize = sizeof(PROPSHEETPAGE);
page.dwFlags = PSP_DLGINDIRECT;
page.pResource = CGTabWindow::pagetemplate;
page.pfnDlgProc = DialogProc;
page.lParam = (LPARAM)this;
HPROPSHEETPAGE hpage = CreatePropertySheetPage(&page);
SendMessage((HWND)propsheet, PSM_ADDPAGE, NULL, (LPARAM)hpage);
And finally, here's my DialogProc:
BOOL CALLBACK DialogProc(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
cout << "hey" << endl;
switch (iMsg)
{
case WM_INITDIALOG :
return TRUE ;
case WM_COMMAND:
switch (LOWORD (wParam))
{
case ID_EDIT :
return TRUE;
case ID_HELP :
return TRUE;
case IDOK :
EndDialog 开发者_Python百科(hDlg, 0) ;
return TRUE ;
}
break ;
}
return FALSE;
}
But for some reason, "hey" is never displayed. Also, sending the PSM_INDEXTOHWND with any index always returns NULL. Does anyone know why this is happening?
It was because you must have at least 1 control in the dialog template.
精彩评论