Print Dialog, Properties-Buttion Question

I have encountered an unusual Microsoft related bug while calling the CView::OnFilePrint(); This problem started when i upgraded to VS 2005...

Iam able to get the standard Print dialog box, but when i press the "Properties" button to open the printer-properties dialog, I am unable to make any selection.

To overcome this problem i have to first set focus outside my application (desktop or other application) and then re-again focus for the properties dialog. After this process everything seems normal.

Is there any quick workaround i can add in the code to prevent the previous process of re-setting focus ?

Is there any way i can get notified or triggered when the user clicks on the "properties button" of the print dialog box ? This way i can forcefully Release and Re-set focus.

If anyone can attach a snippet or share some ideas that would be great..

Who is Participating?
DanRollinsConnect With a Mentor Commented:
First, the problem might be solved more easily :  In the constructor of CPrintDialog, there is an often-overlooked parameter that lets you specify the parent window.  There is a chance that just setting this (rather than using the defualt (NULL [the desktop]) will avoid the problem:

      CPrintDialog dlg( FALSE,
            this   // <<===== added

If that does not work, there is a simpler way to detect the click of the [Properties] button (without having to derive from CPrintDialog.  Try this:

UINT CALLBACK MyPrintHookProc( HWND hdlg, UINT uiMsg, WPARAM wParam,  LPARAM lParam )
      if ( uiMsg == WM_COMMAND ) {
            if ( (wParam & 0xffff0000) >> 16 == BN_CLICKED ) {
                  if ( (wParam & 0xffff) == 1025 ) {
                        // the [Properties] button was clicked

void CD35Dlg::OnButton1()
      dlg.m_pd.nMinPage = dlg.m_pd.nFromPage =1;
      dlg.m_pd.nMaxPage = dlg.m_pd.nToPage = 10;
      dlg.m_pd.lpfnPrintHook= MyPrintHookProc;

Note that this will detect the click of the button, but you are actually needing to detect a message that indicates that the print dialog itself has gone inactive (lost focus).  It may be best to filter for the WM_ACTIVATE or WM_ENABLE message or some other message.  If you need more help, just ask.

-- Dan
I suggest to avoid this by customising CPrintDialog and check..or catch Properties events..derive your own print dialog from CPrintDialog and use it...

Following shows an easy way to customise the default Print dialog in an MFC app with src:

AndyAinscowFreelance programmer / ConsultantCommented:
I've just made a dummy project with VS 2005 and can't duplicate the problem you describe.
It will just take you a minute to make a new project and test if it works in the new project or if you experience the same behaviour.
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

hari4130Author Commented:
I tested by creating a new project and it doesn't seem to be having a focus problem

The difference in my application is that I have a dll linked to my main application.
The printing routines are invoked from the dll.

All I am doing in the dll is calling the standard MFC function

Is there any way i can get invoked when the properties button is clicked on the print dialog ?
or is there any other simple way to solve this instead of customizing the default print dialog.

>>Is there any way i can get invoked when the properties button is clicked on the print dialog ?

only way seems : Derive your own dialog and trap events..refer above link

AndyAinscowFreelance programmer / ConsultantCommented:
<The difference in my application is that I have a dll linked to my main application.
The printing routines are invoked from the dll.>

Are you creating a view in the dll?
If yes is it an extension dll or a regular dll?

(Creating a modeless window eg. view, in a regular dll is not the simplest of tasks.  If it is not done correctly all sorts of wierd behaviour such as focus problems can be experienced)
hari4130Author Commented:

Thanks for the suggestions. The extra parameter for CWnd in the CPrintDialog did not help to solve the focus issue.
I was able to trap the properties button click. However, i was still unable to reset focus or transfer focus to the main application.

I also noticed that this focus problem occurs only in machines running XP 64. When i tested it on 32-bit machines  running XP, it works fine.


Thansk for the points and the grade :)

Sorry I don't have that platform for testing.  About the only other thing that comes to mind relates the use of a DLL.  Make sure that you have called
         AFX_MANAGE_STATE( AfxGetStaticModuleState() );
at each entry point in the DLL.

A diagnostic technique would be to run Spy++ and look for difference in the messages that fly around in the failing system and comparing them to the sequence of messages in the working systems.

-- Dan
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.