I am trying to develop a print preview function for my MFC application. Below is a brief account of how I go about doing it...or rather how it was done previously (I had to do code reuse from previous developer!)
Step 1) Executed in CMainFrame
CWinApp::OnFileNew();
A call to this function. I am not sure why this step is needed.
Supposedly, from the comments, it is to create a Print View?
----------------------------------------------------------------------------
Step 2) Executed in CMainFrame
The following codes are executed
I belief this is to find the main View Class when a project is created using the MFC wizard. Note, the found CView is stored in
m_pTestView
CView* pView;
CTestView *m_pTestView; // A ptr to application's main view obj
CMDIChildWnd* pMDIActive;
CDocument* pDoc;
POSITION pos;
That's it. 4 Steps and the Print Preview is created and displayed. However, there are some problems.
1) When Step 1 is executed (CWinApp::OnFileNew()), a dialog appears. Refer to picture below. How can I not show this dialog?
Also, if i click on cancel, the program will crash
2) In the print preview mode, when I press "Ctrl-Alt-Del" or clicking the top right close button, it will send a message similar to that when I close my application. As in it thinks that I am closing the application!? After that, it just close the Print preview and resumes control back to my main application
3) In Print Preview mode, if i right click on the icon in the task bar, the program will also crash.
1) are you displaying that dialog box yourself? or its just appearing from no-where? If you are displaying it... and you dont wona show it... then you may HIDE it? And if its appearing from somwhere you dont know... then i guess you need debug.
2) As you press Ctrl+Alt+Del the application receives the messages of OnDraw(and i guess... OnSize too). So there might be something written in your OnDraw function. You shud comments those lines... and then build the application again and run.
KMan use code-tags
Rating a post is'nt injurious(0:
The dialog appears because of the CWinApp::OnFileNew() function.
Inside this function, it calls another function
m_pDocManager->OnFileNew();
Inside this OnFileNew function, it creates a CNewTypeDlg dialog and calls its DoModal function. Thats when the dialog appears. But my previous developers used the same code and the dialog did not appear. It simple executes pass the DoModal function.
Print preview is a standard feature of MFC. If you want to add it, why are you trying to do it on a new empty document (thats what OnFIleNew() does). You can probably skip that stage. You probably only need to add a menu option for ID_FILE_PRINT_PREVIEW to your menu. If its not a dialog app, that will get the basics working, and all you need to do is mess around with your OnPreparePrinting() and OnPrint() functions for your documents view.
Please use meaningful question titles - "Help me" does not let me know whether I can help with your question, and I am unlikely to bother reading it. Please remember to rate useful answers. It lets us know when a question has been answered.
i agree. I would have done what you said. But the thing is i'm maintaining legacy codes. Or rather I have to follow. The schedule Im following doesn't allow me to start a project anew.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.