Help and Support
 

powered byLive Search

MFC does not call the CPrintDialog::OnInitDialog function in Visual C++ 6.0

Article ID:193272
Last Review:August 7, 2007
Revision:4.2
This article was previously published under Q193272
On This Page

SYMPTOMS

The OnInitDialog() function (which is called in response to a WM_INITDIALOG message) for a CPrintDialog-derived class, was called in MFC prior to Visual C++ 6.0. However, this is no longer true for MFC DLLs of Visual C++ 6.0. Therefore, programs that rely on OnInitDialog() to be called will not work as expected.

Back to the top

CAUSE

Previously, MFC set up a message hook for CPrintDialog. This hook was the only way to catch a WM_INITDIALOG message. MFC for Visual C++ 6.0 purposely removed this hook so MFC applications would automatically get the new Print dialog by default on Windows 2000; however, this causes applications that rely on CPringDialog::OnInitDialog() to fail to work.

Back to the top

RESOLUTION

Set up the message hook function, _AfxCommDlgProc(), in the constructor of your CPrintDialog-derived class as shown below:
   // CMyPrintDialog is a CPrintDialog-derived class.
   CMyPrintDialog::CMyPrintDialog(DWORD dwFlags)
   : CPrintDialog(FALSE,dwFlags)
   {
      //{{AFX_DATA_INIT(CMyPrintDialog)
      //}}AFX_DATA_INIT
      // MFCBUG: MFC 6.0 doesn't set the message hook!
      m_pd.Flags |= PD_ENABLEPRINTHOOK | PD_ENABLESETUPHOOK;
      // _AfxCommDlgProc is exported from static MFC libraries
      m_pd.lpfnPrintHook = _AfxCommDlgProc;
      m_pd.lpfnSetupHook = _AfxCommDlgProc;
   }
				
Then, make your project statically linked to MFC.

Back to the top

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug has been fixed in the Visual Studio 6.0 Service Pack 1.

To obtain this service pack, visit the following MIcrosoft Developer Network (MSDN) Web site:
http://msdn2.microsoft.com/en-us/vstudio/Aa718362.aspx (http://msdn2.microsoft.com/en-us/vstudio/Aa718362.aspx)
For more information about Visual Studio 6.0 Service Pack 1, click the following article numbers to view the articles in the Microsoft Knowledge Base:
193009 (http://support.microsoft.com/kb/193009/) Visual Studio 6.0 Service Pack 1 readme
194022 (http://support.microsoft.com/kb/194022/) Visual Studio 6.0 service packs, what, where, why
194295 (http://support.microsoft.com/kb/194295/) How to tell that a Visual Studio service pack is installed

Back to the top

MORE INFORMATION

Steps to reproduce the behavior

1.Derive a class from CPrintDialog.
2.Add a message handler for WM_INITDIALOG in the CPrintDialog-derived class. The message handler OnInitDialog() is not called in Visual C++ 6.0.
(c) Microsoft Corporation 1998, All Rights Reserved. Contributions by Yeong-Kah Tam, Microsoft Corporation.

Back to the top


APPLIES TO
Microsoft Foundation Class Library 4.2, when used with:
  Microsoft Visual C++ 6.0 Enterprise Edition
  Microsoft Visual C++ 6.0 Professional Edition
  Microsoft Visual C++, 32-bit Learning Edition 6.0

Back to the top

Keywords: 
kbtshoot kbbug kbfix kbvs600sp1fix kbcmndlg KB193272

Back to the top

Article Translations

 

Other Support Options

  • Need More Help?
    Contact a Support professional by Email, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.