How can I get the handle to the property sheet in CPrintDialogEx

Viewed 127

I'm trying to add a property page to CPrintDialogEx and failing miserably. My code currently is

PROPSHEETPAGE optionsPage1;
HPROPSHEETPAGE hOptionsPage = NULL;

memset(&optionsPage1, 0, sizeof(PROPSHEETPAGE));
optionsPage1.dwSize = sizeof(PROPSHEETPAGE);
optionsPage1.dwFlags = PSP_DEFAULT | PSP_USETITLE;
optionsPage1.hInstance = AfxGetInstanceHandle();
optionsPage1.pszTemplate = MAKEINTRESOURCE(IDD_QUICKREPORT_OPTIONS);
optionsPage1.hIcon = NULL;
optionsPage1.pszIcon = NULL;
optionsPage1.pszTitle = _T("Options");
optionsPage1.pfnDlgProc = (DLGPROC)CQuickReport::OptionsPropertyPageDlgProc;
optionsPage1.lParam = NULL;
m_pdex.nPropertyPages = 1;
hOptionsPage = CreatePropertySheetPage(&optionsPage1);
m_pdex.lphPropertyPages = &hOptionsPage;

INT_PTR nResult = CPrintDialogEx::DoModal();

The property page is NOT showing, so I want to add it after WM_INITDIALOG in CPrintDialogEx. How can I get the handle to the property sheet after it's created. If somebody has a valiant way to make this work and title the CPrintDialogEx outside of setting the txt of the grandparent to the dialog in OnInitDialog

1 Answers

Property sheet should be added before calling DoModal.

OnInitDialog is called after DoModal, so it is too late to initialize the page.

Simply override DoModal instead:

class CMyPrintDialogEx : public CPrintDialogEx
{
public:
    INT_PTR DoModal()
    {
        PROPSHEETPAGE optionsPage1;
        memset(&optionsPage1, 0, sizeof(PROPSHEETPAGE));
        optionsPage1.dwSize = sizeof(PROPSHEETPAGE);
        optionsPage1.dwFlags = PSP_DEFAULT | PSP_USETITLE;
        optionsPage1.hInstance = AfxGetInstanceHandle();
        optionsPage1.pszTemplate = MAKEINTRESOURCE(IDD_QUICKREPORT_OPTIONS);
        optionsPage1.pszTitle = _T("Options");
        optionsPage1.pfnDlgProc = (DLGPROC)CQuickReport::OptionsPropertyPageDlgProc;
        optionsPage1.lParam = NULL;
        m_pdex.nPropertyPages = 1;
        HPROPSHEETPAGE hOptionsPage = CreatePropertySheetPage(&optionsPage1);
        m_pdex.lphPropertyPages = &hOptionsPage;

        INT_PTR nResult = CPrintDialogEx::DoModal();

        return nResult;
    }
};
Related