Solved

Custom Print Dialogs

Posted on 2004-08-26
10
606 Views
Last Modified: 2013-11-20
Scenario:
I have an application that manipulates data in a variety of ways (table, graph, contact sheets, ect...).
When the user clicks 'print', the application goes through a set of property pages I made that form a 'report wizard' that, through the users manipulation, will tell the app what to print.  After the report wizard is completed, a custom print dialog is displayed that has a summary sheet based on data from the wizard.

Problem:
The app will open and go through the report wizard, then display the custom print dialog.  But clicking print on the custom print dialog simply closes the dialog and nothing prints.  It does not seem to make it to the OnPrint() override, so I suspect that the custom print dialog simply closes and that is as far as it gets.


// here is the function that is called when the user clicks print.
// this function opens the report wizard, then calls the OnPreparePrinting() function.
void CARmemView::OnFilePrint()
{
      CARmemDoc* pDoc = GetDocument();
      ASSERT_VALID(pDoc);

      CDlgPrintPP dlg("Print");
      dlg.m_pTable = pDoc->m_pDataSheet;

      if(dlg.DoModal() == ID_WIZFINISH)
      {
            CPrintInfo info;

            info.m_pPD = new CDlgPrint3(FALSE);

            info.m_pPD->m_pd.nMinPage = 1;
            info.m_pPD->m_pd.nMaxPage = 0xffff;

            info.m_pPD->m_pd.hInstance = AfxGetInstanceHandle();
            info.m_pPD->m_pd.lpPrintTemplateName = MAKEINTRESOURCE(1538);

            info.m_pPD->m_pd.Flags |= PD_ENABLEPRINTTEMPLATE;


            OnPreparePrinting(&info);
      }
}

Maybe there is something I am not initializing properly in the CPrintInfo structure properly?

Thanks for your help =]
0
Comment
Question by:r2far
[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
  • 5
  • 4
10 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 11906679
There are lot of things that default implementation of OnPrint() function does. You have to read the MFC source code to get an idea.
If you are working with VC6, look at:
C:\Program Files\MICROSOFT VISUAL STUDIO\VC98\MFC\SRC\VIEWPRNT.CPP
0
 
LVL 86

Expert Comment

by:jkr
ID: 11906783
Also check out http://www.codeproject.com/printing/customprintdialog.asp ("An easy way to customise the default Print dialog in an MFC app")
0
 
LVL 4

Author Comment

by:r2far
ID: 11907461
jaime_olivares:
OnFilePrint() is called when the user selects 'file->print'.  OnPrint() is a different function, that is called when a page of the document is to be printed.  Correct me if I am wrong.  If I am missing code that would usually be called when the user clicks 'file->print' then what is it?

jkr:
I have done what you have listed with the exception that instead of in OnPreparePrinting(), the CPrintInfo structure is created and modified in the OnFilePrint() function.  The modifications made to the CPrintInfo structure are the same though.


Thanks for the responses
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 55

Expert Comment

by:Jaime Olivares
ID: 11907500
Sorry, it was a typo, really I mean OnFilePrint(), read the source code, search for OnFilePrint() implementation in the file I mentioned and you will notice what are you missing.
0
 
LVL 4

Author Comment

by:r2far
ID: 11909071
jaime_olivares:
Ok, that definetly helps.  I knew I somehow cut-out the entire print loop.

I have copied the code, and made a bunch of modifications to suit my needs.  I have one question about the code however.

The compiler says that afxData is an 'undeclared identifier'.  However I can access it's members.  How do I solve that problem?

if (afxData.bMarked4)
    OnPrepareDC(&dcPrint, &printInfo);


I also had problems with a few other functions, however studied the code and found that I did not need those portions and commented them out.  But I am fairly certain that the part shown above is needed =]

Thanks for your help thus far, I am getting very close to my goal.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11909130
afxData is an internal MFC support structure, you can avoid it and use your own variables. It is not intended that you make an exact copy of OnFilePrint(), just to know what function calls are you missing, so it is correct to delete all what you don't need. So, go ahead.

0
 
LVL 4

Author Comment

by:r2far
ID: 11909528
Ok, thanks jaime_olivares.  I think you've given me enough information to complete my task.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11909556
Thanks, r2far.
BTW. How far are you?
0
 
LVL 4

Author Comment

by:r2far
ID: 11909977
oh... very far... very far indeed...
*r2far looks around suspiciously as he backs out of the room.

0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11909991
Someday you will have to tell....................
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

707 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