Solved

Custom Print Dialogs

Posted on 2004-08-26
10
566 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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…
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.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

914 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

18 Experts available now in Live!

Get 1:1 Help Now