Solved

Custom Print Dialogs

Posted on 2004-08-26
10
577 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
  • 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

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 …
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 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