Solved

Printing from CDialog

Posted on 1997-12-11
4
882 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
[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
  • 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
haveThree challenge 22 127
Detect file exist or not 3 215
Not needed 13 134
Way to decrease size of apk file 9 132
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

734 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