Today, I was adding Print Preview option in my current project. MFC has made this process very easy. But, the application tended to crash if I invoked the print preview. This was the flow:
>CView::OnFilePrintPreview()
>>AFXAPI _AfxCheckDialogTemplate(LPCTSTR lpszResource, BOOL bInvisibleChild)
>>>HINSTANCE hInst = AfxFindResourceHandle(lpszResource, RT_DIALOG) <<<----- Bingo!! this fails
lpszResource = 0X7803 which is for print preview dialog. But, my app seems
not being able to locate it!
The trace message was :
ERROR: Cannot find dialog template with IDD 30723.
By the by, my app uses MFC in static library. I googled, but found that many
others faced same questions, some found the reson (not being able to locate
the resource), but could not get any solution from the internet.
Then, after much R&D + thinking, I found the solution.
If you face the same problem, just follow these simple steps:
1. Open your project's resource file (*.rc) in text editor
2. find this (including the quotes)
"#include ""afxres.rc"" // Standard components\r\n"
3. Add the following line after that line (including the quotes)
"#include ""afxprint.rc"" // printing/print preview resources\r\n"
4. Find this
#include "afxres.rc" // Standard components
5. Add the following line after that line
#include "afxprint.rc" // printing/print preview resources
----------- You are all done ---------------
Happy programming!
By the way, I am using VS2005
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment