Solved

Custom Print Dialogs

Posted on 2004-08-26
10
555 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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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…

747 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

12 Experts available now in Live!

Get 1:1 Help Now