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

x
?
Solved

Print in a dialog box of Visual C++

Posted on 1998-04-22
8
Medium Priority
?
517 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 240 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

596 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