Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Printing from CDialog

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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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…
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.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

610 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