Solved

How to get access to the CDC* and CPrintInfo* that are incoming parameters of OnPrint?

Posted on 1997-05-22
5
691 Views
Last Modified: 2013-11-20
What I want to know is, how do you get the current CDC* and CPrintInfo* from a CView class that I created without being in a procedure that has them as incoming parameters.

I'm trying to call OnPrint() from within a procedure that doesn't have the CDC* or CPrintInfo* as incoming parameters.  The reason I want to do this is that I want have a dialog button (not the print dialog) execute the printing functions of a view that I have created.  I have everything set up for this, except I can't get a hold of the CDC* and the CPrintInfo* , and when I try to just declare my own locally, the program crashes on execution.

Thanks for your help in advance,
    Dave
0
Comment
Question by:David Gray
  • 3
  • 2
5 Comments
 
LVL 10

Accepted Solution

by:
RONSLOW earned 25 total points
ID: 1301713
Don't call OnPrint directly (not a good idea generally) - send your view a command message (ID_FILE_PRINT) to do the printing.

Alternatively, you could directly call OnFilePrint (instead of OnPrint).

But - it is better to do a SendMessage because then you don't bypass the message routing logic.


0
 

Author Comment

by:David Gray
ID: 1301714
The problem still remains, in that I need to execute the views printing from an external call in a dialog.  How can I directly send my view a ID_FILE_PRINT from the dialog?  Could you elaborate on the SendMessage?

Thanks,
  Dave
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1301715
Lookup SendMessage in the documentation.

You simply call pMyView->SendMessage(WM_COMMAND,ID_FILE_PRINT);

This sends the ID_FILE_PRINT command to your view class.  This will call the OnFilePrint of the CView or whatever base class which will set up everything and call your view's OnPrint etc, and if you are hooked up to a document template.

If not, try calling OnFilePrint of your view class instead


All should just work fine IF you are deriving from CView (or a derivative of that).

0
 

Author Comment

by:David Gray
ID: 1301716
Much appreciated.

Dave
0
 

Author Comment

by:David Gray
ID: 1301717
I've got it to work in as far as bringing up the print dialog, but when it goes to print nothing is actually written on the page.  Could this be due to the fact that I don't actually have that view running anywhere, I just using it as a means to print the image that I'm drawing on the surface of my own dialog by paralleling the drawing code in the view off of the drawing code in the dialog.  I tried a simple pDC->TextOut(0,0,"Hello World!") and that didn't even write to the page.  I'm stumped.  Any ideas?

Dave
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now