Solved

Print in a dialog box of Visual C++

Posted on 1998-04-22
8
495 Views
Last Modified: 2008-02-01
I am developing in Visual C++ 5.0 with MFC.
My application is dialog based and composed of static text and entry field that I fill (CEdit). How can I print the content of this dialog, that's the static text and the CEdit ? Is it possible ? There is an alternative method (without changing the application obviously) ?
Thanks  in advance.
Nino
0
Comment
Question by:grimaldi
[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
  • 5
  • 2
8 Comments
 
LVL 10

Accepted Solution

by:
RONSLOW earned 120 total points
ID: 1163142
You can send yourself a WM_PRINT message
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1163143
Something like this...

void CMyDialog::PrintMe() {
  // Instantiate a CPrintDialog.
  CPrintDialog printDlg(FALSE, PD_ALLPAGES | PD_RETURNDC, NULL);
  // Initialize some of the fields in PRINTDLG structure.
  printDlg.m_pd.nMinPage = printDlg.m_pd.nMaxPage = 1;
  printDlg.m_pd.nFromPage = printDlg.m_pd.nToPage = 1;
  // Display Windows print dialog box.
  printDlg.DoModal();
  // Obtain a handle to the device context.
  HDC hdcPrn = printDlg.GetPrinterDC();
  if (hdcPrn != NULL) {
    CDC *pDC = new CDC;
    pDC->Attach (hdcPrn);      // attach a printer DC
    pDC->StartDoc("job");      // begin a new print job
    pDC->StartPage();          // begin a new page
    Print(pDC,PRF_CHILDREN|PRF_CLIENT|PRF_ERASEBKGND);
    pDC->EndPage();            // end a page
    pDC->EndDoc();             // end a print job
    pDC->Detach();             // detach the printer DC
    delete pDC;
  }
}

The CWnd::Print function does the printing by sending WM_PRINT to all the controls (to print each control);  and sends WM_PRINTCLIENT to itself (to print the dialog itself)

0
 

Author Comment

by:grimaldi
ID: 1163144
Thank for your code. It is good but the problem is that it does not printing the static text that I inserted into dialog box by palette, while it's printing the other controls.
How is it possible ?
I have another problem: I set a dialog property: vertical scroll-bar, but when I resize in execution the dialog box the scroll-bar does not activate. Why ?
Thanks in advance.
Nino
0
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!

 
LVL 10

Expert Comment

by:RONSLOW
ID: 1163145
Ah .. forgot that.  Statics for some reason known only to M$, won't respond to the printing (by default).

You need to derive your own CStatic derived class that resonds to the WM_PRINT message by printing itself.  I'll see if I can dig up some code for this.  It shouldn't be TOO hard.  Perhaps just calling Default() will do it? .. I'll see what I can find.

0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1163146
Try deriving from CStatic and handline WM_PRINT by sending a WM_PAINT with the same wParam.  It might work.

Of course, then you need to subclasss you static's in the dialog (pretty disgusting).

Another way my be to put in a loop in your printme that goes thru all the child controls, checks if they are statics and then sends them the approriate WM_PRINT .. but that is tricky.

I'm still looking for a better solution for printing the statics for you.
0
 

Author Comment

by:grimaldi
ID: 1163147
Thanks for your advice, but I found a solution for my problem, maybe not the best.
In fact I'm printing static text by TextOut() method of the device context  In this case the problem is that I have to write my text in a file and not diretcly in the resource CStatic text and I have to write 5 or 6 pages !!!
But there is a problem with TextOut(),  because I don't know why the newline doesn't work
in printing. Do you Know why ?
Thanks
Nino
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1163148
You'd need to post some code.

Also I don't understand what you mean by "to write my text in a file and not diretcly in the resource CStatic text" ??
0
 

Expert Comment

by:skater6188
ID: 4615215
Thanks alot the code works perfect, but it print out in a 1" by 1" size. Is there any way to increase the size?

Thanks
0

Featured Post

Technology Partners: 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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

739 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