Solved

Printing from CDialog

Posted on 1997-12-11
4
877 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Include multiple hostnames in this command? 3 55
Host to IP 7 78
Smart Camera scanning and reading information 3 106
ShiftLeft challenge 21 82
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 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