Solved

Printing from CDialog

Posted on 1997-12-11
4
872 Views
Last Modified: 2013-11-20
 I am currently trying to print a modal dialog that is derived from CDialog.  I am getting the Device Context and have had success printing out text with TextOut.  But I'm having a problem printing out the actual dialog being displayed.  For example, any color bitmaps and static fields are not appearing on the printout.  Also, I can't get the SetViewPortOrg to set my origen so I can center my dialog on the printout.  Here is what I have:

    CPrintDialog dlg(FALSE);

    CWinApp* app = AfxGetApp();
      if (!app->GetPrinterDeviceDefaults(&dlg.m_pd))

        {
        if (app->DoPrintDialog(&dlg) != IDOK)
           return ;
        }

 
    if (dlg.CreatePrinterDC() == NULL)
        return ;

    CDC PrintDC;
      PrintDC.Attach(dlg.m_pd.hDC);

      PrintDC.StartDoc("print dialog");
      PrintDC.StartPage();

    PrintDC.SetMapMode(MM_ANISOTROPIC);

    CClientDC dcScreen(NULL);

    int ixd = dcScreen.GetDeviceCaps(LOGPIXELSX);
    int iyd = dcScreen.GetDeviceCaps(LOGPIXELSY);

    // get the printer's pixel resolution
    int ixp = PrintDC.GetDeviceCaps(LOGPIXELSX);
    int iyp = PrintDC.GetDeviceCaps(LOGPIXELSY);
     
        PrintDC.SetMapMode(MM_ANISOTROPIC);
      PrintDC.SetWindowExt(ixd, -iyd);
      PrintDC.SetViewportExt(ixp, -iyp);
      
      Print(&PrintDC, PRF_CHILDREN | PRF_CLIENT);
      PrintDC.EndPage();
      PrintDC.EndDoc();
      PrintDC.Detach();

Thanks,
   Kevin
0
Comment
Question by:kdevers
  • 2
4 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 1312170
I guess the IDs of those static controls that cannot be printed out are IDC_STATIC (-1). Change the IDs to different actual IDs.
0
 

Author Comment

by:kdevers
ID: 1312171
Actually, all the static controls are not the default IDC_STATIC.  They are all have custom IDs in the range of 1000+.  Sorry.
0
 
LVL 1

Accepted Solution

by:
IgorGrebnev earned 70 total points
ID: 1312172
Dear Kevin,
The content of window is printed through WM_PRINT message. Actually the function CWnd::Print does nothing more than sending of WM_PRINT message to the window with Device contenst in WPARAM and falgs in LPARAM. You can get little more information by reading description of WM_PRINT and WM_PRINTCLIENT messages.
If you specify the PRF_CHILDREN, then the window should recursively to all childs. Also the message WM_PRINTCLIENT should be send to the dialog itself and all controls.
The first thing I would do is to check with the SPY whether the messages are send to the dialog and its childs.Each child shoudl get the WM_PRINT and WM_PRINTCLIENT. Try to see the static controls printed if you send WM_PRINT message directly to them ( or calling the print functions of the controls ).
If nothing works, you can try sending of WM_PAINT message to the dialog and controls. If you specify DC in WPARAM of the message, the the control paints itself on the DC ( probably you need to invalidate the dialog before sending WM_PAINT ). THis method works for sure, I have frinedwho used it. You can also offset positions of controls properly with DC origin. THis method makes more work, because you need to send messages to all controls.
YOurs Igor

0
 

Author Comment

by:kdevers
ID: 1312173
I still have a few questions that the answer you provided didn't totally address but overall, it helped me out.  Please email me at evers@NO_SPAM.amered.com.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

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 …
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

708 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

9 Experts available now in Live!

Get 1:1 Help Now