Solved

OnPrint() not executing correctly...

Posted on 1997-05-27
9
356 Views
Last Modified: 2013-11-20
I'm sending a SendMessage(WM_COMMAND, ID_FILE_PRINT) to a view of mine from a dialog that I have written.  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 to that of the drawing code in the dialog. I tried a simple pDC->TextOut(0,0,"Hello World!") in OnPrint() and that didn't even write to the page.  Could it possibly be due to the fact that the print is being called from a modal dialog I wrote? I'm stumped. Any ideas?

Dave
0
Comment
Question by:David Gray
  • 4
  • 3
  • 2
9 Comments
 

Author Comment

by:David Gray
ID: 1301833
Edited text of question
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1301834
The call from a modal dialog shouldn't make any difference.

Do you not have a view window created?  That could explain why nothing happens because there is no window to receive the messages.

Could you please post some code for me to look at.

I am at Roger_Onslow@compsys.com.au
0
 

Author Comment

by:David Gray
ID: 1301835
I don't actually have the view created.  Would you suggest that I create the window and then hide it to accomplish what I want.  I don't actually want to display the view, just use it for the printing capabilities.

I'll e-mail you the code I'm using soon.

Thanks,
    Dave
0
 
LVL 1

Expert Comment

by:jmmougeolle
ID: 1301836
Are you sure the OnPrint method is called? Try to put a MessageBox call there so to be sure it's really called, or a BreakPoint.

So if you wanna try the Messagebox think just try a:

::AfxMessageBox("I'm in OnPrint",);
Before or after your TextOut...

jmmougeolle@calva.net
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Expert Comment

by:jmmougeolle
ID: 1301837
Are you sure the OnPrint method is called? Try to put a MessageBox call there so to be sure it's really called, or a BreakPoint.

So if you wanna try the Messagebox think just try a:

::AfxMessageBox("I'm in OnPrint",);
Before or after your TextOut...

jmmougeolle@calva.net
0
 

Author Comment

by:David Gray
ID: 1301838
I actually have already tried putting a message box in the OnPrint(), and it never displayed.

Dave
0
 
LVL 1

Accepted Solution

by:
jmmougeolle earned 50 total points
ID: 1301839
So that's mean it never called! What you got to do to check what's going wrong is to put a break point in the CView::OnFilePrint, and even, if it's not handling the reception of your message, just try to call it directly.... That's will normally work...

If that's not working either, it don't seems that the code that is included in the OnFilePrint MFC source code is not easy enough to not be directly managed by your own code, and do what ever you want it to do, to be able to print form your dialog. SO you o could try to make it a new method of your CDialog, and make it work from there....
May the MFC be with you....
 jmmougeolle@calva.net strikes back!
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1301840
Ths problem is as I said before - if there is no window, then there is nothing to receive the message.

Think I deserve points for that!!

0
 

Author Comment

by:David Gray
ID: 1301841
I actually do think that Ronslow's appraoch is more likely to be what my problem is.  I think Ronslow deserves the points as well, but I'm not sure how to grade this because it says that the points will go to jmmougeolle's answer.

Anyway, for Ronslow, how would I go about creating the view without making it visible and have so that it is there to receive the message.  Right now I have code associated with a button on my dialog that looks somewhat like:

CMyView* pView;
pView->SendMessage(WM_COMMAND,ID_FILE_PRINT);

How can I "create the window", as you say?

Thanks,
   Dave
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

760 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