Solved

Print Dialog, Properties-Buttion Question

Posted on 2006-06-29
8
526 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…

726 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