4
votes

I am using MyPrintDialog extended CPrintDialog. The problem is: OnInitDialog() method of MyPrintDialog does not get called on first time when the application try to open Print dialog.

I am trying to set the Printer name in the Print Dialog from the OnInitDialog() method. Printer name is specified by the user in the application which I want to use for the Printing.

My OnInitDialog() method

CComboBox *wndCmbBox = (CComboBox *)GetDlgItem( IDC_PER_USER ); /*IDC_PER_USER which is ID of Prin Dialog combo */
if( wndCmbBox != NULL )
{
    wndCmbBox->SelectString( -1, PrinterName );
} 

Or is their any way to set the user choice Printer name in the Print dialog..?

Please Explain.

Edit

Yes, by onInit() I mean OnInitDialog()

I am using VS 2012 with Win7 32 bit. I am facing this issue only first call of DoModel(). Next consecutive DoModel() methods calls OnInitDialog(). I have debug the issue and found something

INT_PTR CALLBACK AfxDlgProc(HWND hWnd, UINT message, WPARAM, LPARAM)
{
    if (message == WM_INITDIALOG)
    {
        // special case for WM_INITDIALOG
        CDialog* pDlg = DYNAMIC_DOWNCAST(CDialog, CWnd::FromHandlePermanent(hWnd));
        if (pDlg != NULL)
            return pDlg->OnInitDialog();
        else
            return 1;
    }
    return 0;
}

The above is the function of dlgcore.cpp. When issue is reproduced I observed that DYNAMIC_DOWNCAST returns NULL.

Please note that I have customized CPrintDialog and added one check box in it. I doubt if it is creating the issue.

1
Can you show when and how you create the modal dialog?Roger Rowland
Also, if you use the supplied CPrintDialog instead of your customised version, does it also behave the same way? So, have you verified that your customisation is not to blame?Roger Rowland
please find file at this locationAB Bolim
I can't see anything obvious, although in your overridden OnInitDialog() you should call CPrintDialog::OnInitDialog() first rather than after your code. What happens if you just use CPrintDialog instead of CCustomPrintDlg?Roger Rowland

1 Answers

0
votes

If you meant to say OnInitDialog() instead of OnInit(), then it's possible that your problem is explained by this MSKB article although it seems to have been fixed after VC6 SP1.