如何将 属性 页面添加到 CPrintDialogEx
How do I add a property page to CPrintDialogEx
我正在尝试实现 CPrintDialogEx。我还有一些其他需要的选项,我想向 window 添加另一个 属性 页面。没有 MFC 示例,尝试 Win API 示例失败得很惨。它兑现。我做错了什么?
CPrintDialogEx dlg;
PROPSHEETPAGE optionsPage1;
HPROPSHEETPAGE hOptionsPage;
memset(&optionsPage1, 0, sizeof(PROPSHEETPAGE));
optionsPage1.dwSize = sizeof(PROPSHEETPAGE);
optionsPage1.dwFlags = PSP_DLGINDIRECT;
optionsPage1.hInstance = AfxGetInstanceHandle();
optionsPage1.pszTemplate = MAKEINTRESOURCE(IDD_QREPORT_OPTIONS);
optionsPage1.pResource = (DLGTEMPLATE*)IDD_QREPORT_OPTIONS;
optionsPage1.hIcon = NULL;
optionsPage1.pszIcon = NULL;
optionsPage1.pszTitle = "Options";
optionsPage1.pfnDlgProc = AfxWndProc;
optionsPage1.lParam = NULL;
dlg.m_pdex.nPropertyPages = 1;
hOptionsPage = CreatePropertySheetPage(&optionsPage1);
dlg.m_pdex.lphPropertyPages = &hOptionsPage;
if (dlg.DoModal() == IDOK)
空指针崩溃
optionsPage1.dwFlags = PSP_DLGINDIRECT;
...
optionsPage1.pResource = (DLGTEMPLATE*)IDD_QREPORT_OPTIONS;
IDD_QREPORT_OPTIONS
是一个整数,不应该强制转换成DLGTEMPLATE*
。这样做会将 pResource
指向某个随机内存地址,这很可能是崩溃的原因。
反正你不需要pResource
。将 PSP_DLGINDIRECT
替换为 PSP_DEFAULT
,这将指示 CreatePropertySheetPage
使用 pszTemplate
。
PROPSHEETPAGE
文档:
pszTemplate
Type: LPCSTR
Dialog box template to use to create the page. This member can specify
either the resource identifier of the template or the address of a
string that specifies the name of the template. If the PSP_DLGINDIRECT
flag in the dwFlags
member is set, pszTemplate
is ignored. This member
is declared as a union with pResource
.
示例:
INT_PTR CALLBACK dlgproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_COMMAND:
if(LOWORD(wParam) == IDC_BUTTON1)
MessageBox(hwnd, _T("test"), 0, 0);
return 0;
}
return FALSE;
}
PROPSHEETPAGE optionsPage1 = { 0 };
optionsPage1.dwSize = sizeof(PROPSHEETPAGE);
optionsPage1.dwFlags = PSP_DEFAULT | PSP_USETITLE;
optionsPage1.hInstance = AfxGetInstanceHandle();
optionsPage1.pszTemplate = MAKEINTRESOURCE(IDD_QREPORT_OPTIONS);
optionsPage1.pszTitle = _T("Options");
optionsPage1.pfnDlgProc = dlgproc;// AfxWndProc;
我正在尝试实现 CPrintDialogEx。我还有一些其他需要的选项,我想向 window 添加另一个 属性 页面。没有 MFC 示例,尝试 Win API 示例失败得很惨。它兑现。我做错了什么?
CPrintDialogEx dlg;
PROPSHEETPAGE optionsPage1;
HPROPSHEETPAGE hOptionsPage;
memset(&optionsPage1, 0, sizeof(PROPSHEETPAGE));
optionsPage1.dwSize = sizeof(PROPSHEETPAGE);
optionsPage1.dwFlags = PSP_DLGINDIRECT;
optionsPage1.hInstance = AfxGetInstanceHandle();
optionsPage1.pszTemplate = MAKEINTRESOURCE(IDD_QREPORT_OPTIONS);
optionsPage1.pResource = (DLGTEMPLATE*)IDD_QREPORT_OPTIONS;
optionsPage1.hIcon = NULL;
optionsPage1.pszIcon = NULL;
optionsPage1.pszTitle = "Options";
optionsPage1.pfnDlgProc = AfxWndProc;
optionsPage1.lParam = NULL;
dlg.m_pdex.nPropertyPages = 1;
hOptionsPage = CreatePropertySheetPage(&optionsPage1);
dlg.m_pdex.lphPropertyPages = &hOptionsPage;
if (dlg.DoModal() == IDOK)
空指针崩溃
optionsPage1.dwFlags = PSP_DLGINDIRECT; ... optionsPage1.pResource = (DLGTEMPLATE*)IDD_QREPORT_OPTIONS;
IDD_QREPORT_OPTIONS
是一个整数,不应该强制转换成DLGTEMPLATE*
。这样做会将 pResource
指向某个随机内存地址,这很可能是崩溃的原因。
反正你不需要pResource
。将 PSP_DLGINDIRECT
替换为 PSP_DEFAULT
,这将指示 CreatePropertySheetPage
使用 pszTemplate
。
PROPSHEETPAGE
文档:
pszTemplate
Type:
LPCSTR
Dialog box template to use to create the page. This member can specify either the resource identifier of the template or the address of a string that specifies the name of the template. If the
PSP_DLGINDIRECT
flag in thedwFlags
member is set,pszTemplate
is ignored. This member is declared as a union withpResource
.
示例:
INT_PTR CALLBACK dlgproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_COMMAND:
if(LOWORD(wParam) == IDC_BUTTON1)
MessageBox(hwnd, _T("test"), 0, 0);
return 0;
}
return FALSE;
}
PROPSHEETPAGE optionsPage1 = { 0 };
optionsPage1.dwSize = sizeof(PROPSHEETPAGE);
optionsPage1.dwFlags = PSP_DEFAULT | PSP_USETITLE;
optionsPage1.hInstance = AfxGetInstanceHandle();
optionsPage1.pszTemplate = MAKEINTRESOURCE(IDD_QREPORT_OPTIONS);
optionsPage1.pszTitle = _T("Options");
optionsPage1.pfnDlgProc = dlgproc;// AfxWndProc;