Solved

Print Dialog, Properties-Buttion Question

Posted on 2006-06-29
8
516 Views
Last Modified: 2013-11-20
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..

Thanks
0
Comment
Question by:hari4130
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17015787
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:
http://www.codeproject.com/printing/customprintdialog.asp


-MAHESH
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 17016103
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.
0
 

Author Comment

by:hari4130
ID: 17018243
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
ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)

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.

Thanks
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17019239
>>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

-MAHESH
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 49

Accepted Solution

by:
DanRollins earned 500 total points
ID: 17027566
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,
             PD_ALLPAGES | PD_USEDEVMODECOPIES | PD_NOPAGENUMS |
             PD_HIDEPRINTTOFILE | PD_NOSELECTION,
            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
                  }
            }
      }
      return(0);
}

void CD35Dlg::OnButton1()
{
      CPrintDialog dlg(FALSE, PD_PAGENUMS | PD_ENABLEPRINTHOOK);
      dlg.m_pd.nMinPage = dlg.m_pd.nFromPage =1;
      dlg.m_pd.nMaxPage = dlg.m_pd.nToPage = 10;
      dlg.m_pd.lpfnPrintHook= MyPrintHookProc;
      dlg.DoModal();
}

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
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 17029605
<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)
0
 

Author Comment

by:hari4130
ID: 17052096
Dan,

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.

Hari

0
 
LVL 49

Expert Comment

by:DanRollins
ID: 17054325
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
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Folder Comparison 12 52
Add content to output file 4 58
VBA "SendKeys" Syntax for Multiple Keystrokes 7 98
Making an alias 7 54
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now