?
Solved

Printing from CDialog

Posted on 1997-12-11
4
Medium Priority
?
886 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 210 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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 …
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

771 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