 |
|
 |
Hello,
There is a memory leak when running the print preview (clicking the Preview button). Memory is allocated in the function CPrintPreviewDialog::OnDialogPrintPreview (the memory is never deallocated):
CPrintPreviewState* pState = new CPrintPreviewState;
Is this line necessary? I've noticed that this same code is called in CDummyView::OnDoPrintPreview(), but there is no memory leak.
Regards,
Mike
|
|
|
|
 |
|
 |
I am using an existing MS Office Addin developed in ATL COM.I want to provide this kind of print and print preview functionality to it. Now MFC Extension DLL can't be used in an ATL COM Application, so is it possible to create an MFC Regular DLL and then call it from my ATL COM application??Maverick
modified on Wednesday, February 17, 2010 1:44 AM
|
|
|
|
 |
|
 |
Hi,
I am using VC++ 2005, when I tried to compile the project I got the error message:
LINK : fatal error LNK1104: cannot open file '..\PrintExtension\Debug\PrintExtensiond.lib'
Couldn't find this PrintExtensiond.lib anywhere, anyone can help ?
Thanks
|
|
|
|
 |
|
 |
I encountered another problem:
sometimes I get the program crash closing the preview frame, after a long time of debugging, I found the following trace:
1. user clicking the close button of the preview frame wnd
2. CDummyView::OnEndPrintPreview() calls GetParentFrame()->DestroyWindow()
3. CFrameWnd->Onclose()
4. CFrameWnd->GetActiveDocument()
as the Document runtime class is given as NULL when the doc template was
created, then this call cause crash.
My workaround is as follows:
Create a CFrameWnd derived class CMainFrame, override the method:
CDocument* CMainFrame::GetActiveDocument()
{
return NULL;
}
as a side product, I can create a status bar, to make this print preview
exaclty as same as the standard preview: The current page number will be displayed automatically on the status bar.
min2max
|
|
|
|
 |
|
 |
Hello there,
I don't like DLL's, never did - they solve some things, but open up other problems...
How can I use the code as part of my project / source instead?
Any help will be good
Cheers
Alex
|
|
|
|
 |
|
 |
i want to break the print/preview page of records from database. i'm using MS ACCESS DAO database. i want to print only 6 (six) records onto a page and next six on to next page and so on upto the end of the records available.
how can i do it?
when i`m printing it it is showing all the records on to a single page and showing 8 or nine records onto first page... but it is not continuing after it to the next page.
plz help me in detail how can i print records on the next page after 6 records.
i'll be highly thankful to u.
regards!
Shiv
DRDO
INDIA
|
|
|
|
 |
|
 |
I created a dll and a test dialog with this class and everything was working just fine. I then tried to attach the dll project to another project (PROJECTB) and I was getting a generic assertion error. I drilled down the problem and found out that the string AFX_IDS_PREVIEWPAGEDESC was getting set into the variable pInfo->m_strPageDesc. Then later on in the code it was attempting to put the page number into pInfo->m_strPageDesc which was failing. The problem was AFX_IDS_PREVIEWPAGEDESC as a resource string id of 61508 which was used in PROJECTB as IDS_TEST_STRING123 with an id of 61508 which had a string something like "This is the error message %s.".
Anyway seeing this alerted me to many errors with string ids ranging from 61505-61512.
To Fix these errors....
PrintPreviewDialog.cpp:
BOOL CPrintPreviewDialog::OnPreparePrinting(CPrintInfo* pInfo)
{
BOOL bRet = m_pView->DoPreparePrinting(pInfo);
if (bRet == TRUE)
{
pInfo->m_strPageDesc = LoadStringFromDLL(AFX_IDS_PREVIEWPAGEDESC).c_str();
}
return bRet;
}
DummyView.cpp:
CString strDef(LoadStringFromDLL(AFX_IDS_PRINTDEFAULTEXT).c_str());
CString strPrintDef(LoadStringFromDLL(AFX_IDS_PRINTDEFAULT).c_str());
CString strFilter(LoadStringFromDLL(AFX_IDS_PRINTFILTER).c_str());
CString strCaption(LoadStringFromDLL(AFX_IDS_PRINTCAPTION).c_str());
CFileDialog dlg(FALSE, strDef, strPrintDef,
OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, strFilter);
dlg.m_ofn.lpstrTitle = strCaption;
MyPreviewView.cpp:
BEGIN_MESSAGE_MAP(CMyPreviewView, CPreviewView)
...
ON_UPDATE_COMMAND_UI(AFX_ID_PREVIEW_NUMPAGE, OnUpdateNumPageChange)
END_MESSAGE_MAP()
...
...
...
void CMyPreviewView::OnUpdateNumPageChange(CCmdUI* pCmdUI)
{
CPreviewView::OnUpdateNumPageChange(pCmdUI);
UINT nPages = m_nZoomState == ZOOM_OUT ? m_nPages : m_nZoomOutPages;
pCmdUI->SetText(LoadStringFromDLL(nPages == 1 ? AFX_IDS_TWOPAGE : AFX_IDS_ONEPAGE).c_str());
}
MyPreviewView.h:
...
afx_msg void OnUpdateNumPageChange(CCmdUI* pCmdUI);
If anyone has any more strings that should be defined or updated please let me know thanks...
Chris
|
|
|
|
 |
|
 |
Wow. It took me 6 hours to figure out why I was getting an assertion failure when my program was trying to create the hidden frame.
This was the place where the assertion was occurring...
CView* CFrameWnd::GetActiveView() const
{
ASSERT(m_pViewActive == NULL ||
m_pViewActive->IsKindOf(RUNTIME_CLASS(CView)));
return m_pViewActive;
}
If you run your code and get an error here make sure you have and IDR_MAINFRAME under the icon section of your resource file AND under the menu section of your resource file. In the menu section create a menu item called ignore like in the demo project.
Chris
|
|
|
|
 |
|
 |
Hi Roger,
I am writing an instrument control software for my company. It is a dialog based application. The dll you provided is really handy. I am wondering if I could include it in our commercial release of the software which will accompany the instrument.
Thank you for a job well done!
|
|
|
|
 |
|
 |
Hi,
First, thx for Roger for all his contribution with his codes.
Well, I tried to use the DLL in my Doc / View App, with a Dialog based Class, and finally compiled it. But, when I click on my buttons nothing happen .... There are named ID_FILE_PRINT and ID_FILE_PRINT_PREVIEW and after following the code, there is no relationship between buttons and OnPreparePrinting function .... I just needed to adapt my CView print routine in a CDialog class, in CView it's automatic but in CDialog no. And I wonder if it is supposed to be with the DLL. For information, I'm in Static DLL project and can't change this propertie at all.
Hope to have news soon.
---------
| Luke_21 |
---------
|
|
|
|
 |
|
 |
Can we use C++ dlls in C#.Net.
I am using C#.Net and i am faceing some probelm in Crystal Reports. If you have any idea about Crystal Reports Please Tell me.
Muhamad Waqas Butt
waqasb4all@yahoo.com
|
|
|
|
 |
|
 |
I'm getting a crash when my dialog based on CPrintPreviewDialog is invoked. The crash occurs in dlgcore.cpp at the line "if (hWndParent != NULL && ::IsWindowEnabled(hWndParent))". I am using MFC in a static library. The dialog is not the dialog-based app's main dialog but one invoked from it. I think I followed all of Roger's steps, so I would appreciate anyone's input.
|
|
|
|
 |
|
 |
I had the same problem. I also had my project settings set using MFC in a static library. I had to change that setup to using MFC in a shared DLL. This change is needed for both the Release and the Debug configurations. Another thing that I had to do to get the program to work in Debug mode was copy the "PrintExtensiond.dll" into the Debug folder of my project and then change the name of the file to "PrintExtension.dll". The executable will look for the "PrintExtension.dll" file regardless of whether your configuration is set up for Debug or Release. Of course, the original "PrintExtension.dll" should be copied into the Release folder for the release configuration. Both of these files will be found in the PrintExtension project folder, one in the Debug folder and one in the Release folder.
This made all of the functionality available to me.
I want to thank Roger for this. I have been looking for a way to print from a Dialog for eons, it seems.
|
|
|
|
 |
|
 |
First of all, it's a great work! Thank you.
I have incorporated you code into my multiView SDI app. But I encountered a problem. I/m using you code to print a seperate page from a modelless dlg, which is different from those pages you can get from the File/Print command via the main frame.
After activating the preview window, I can still shift to the dlg by Alt-Tab key combinition, and I can re-click the print/preview and even Close button, for the latter, which will make the program crash.
Do you have any good idea to get rid of this?
Thanks again for your good job and your attention.
B.Rgds
min2max
|
|
|
|
 |
|
 |
I've added a line in OnDialogPrintPreview() as follows,
attempting to hide also the dialog initiating the preview frame.
void CPrintPreviewDialog::OnDialogPrintPreview()
{
CFrameWnd* pOldFrame = (CFrameWnd*)AfxGetApp()->m_pMainWnd;
pOldFrame->ShowWindow(SW_HIDE);
// Max: 2007-12-20 also hide the initiating dialog
ShowWindow(SW_HIDE);
...
}
but unfortunately, it seems not work. The dialog doesn't hide as I
anticipated.
What's wrong?
Thanks for any hints.
min2max
|
|
|
|
 |
|
 |
Yes, this will work, with the following code midification:
void CPrintPreviewDialog::EndPreviewMode()
{
// Max: 2007-12-20 let the dialog re-appear
ShowWindow(SW_SHOW);
m_bPrintPreview = false;
}
|
|
|
|
 |
|
 |
Unfortunately my application crashes when I try to close preview window with close button (not this one on toolbar, but th button in top-right corner of the window).
It crash on:
"CDocument* pDocument = GetActiveDocument();"
winfrm.cpp: line 775: in void CFrameWnd::OnClose();
I tryed to add something like this:
pState->lpfnCloseProc=NULL;
to "void CDummyView::OnDoPrintPreview()" method, but now closing preview window closes whole application alsow
Any idea how to solve this problem?
Kajko
|
|
|
|
 |
|
 |
you can remove sysmenu from FrameWnd ;
like this;
void CPrintPreviewDialog::OnDialogPrintPreview()
{
CFrameWnd* pOldFrame = (CFrameWnd*)AfxGetApp()->m_pMainWnd;
pOldFrame->ShowWindow(SW_HIDE);
if (!m_pTemplate)
{
m_pTemplate = new CSingleDocTemplate(
128, // so load fram is happy. This matches the IDR_MAINFRAME value from your application!
NULL,
RUNTIME_CLASS(CFrameWnd),
RUNTIME_CLASS(CDummyView));
//AfxGetApp()->AddDocTemplate(m_pTemplate);
}
CFrameWnd* pFrameWnd = m_pTemplate->CreateNewFrame(NULL, NULL);
// In derived classes, implement special window handling here
// Be sure to Unhook Frame Window close if hooked.
// must not create this on the frame. Must outlive this function
CPrintPreviewState* pState = new CPrintPreviewState;
UNUSED_PARAMETER(pState);
m_bPrintPreview = true;
m_pTemplate->InitialUpdateFrame(pFrameWnd, NULL, FALSE);
m_pView = (CDummyView*)pFrameWnd->GetActiveView();
AfxGetApp()->m_pMainWnd = pFrameWnd;
pFrameWnd->ModifyStyle(WS_SYSMENU,0) ; //remove sysmenu
pFrameWnd->SetWindowText(_T("打印预览"));
pFrameWnd->ShowWindow(SW_SHOWMAXIMIZED);
m_pView->SetPrintDialog(this);
m_pView->m_pOldFrame = pOldFrame;
m_pView->OnDoPrintPreview();
}
tangxingbin
|
|
|
|
 |
|
 |
When I am clicking ALT + F4 , application crashes.
Please show me some way.
N N Mishra
N N MISHRA
|
|
|
|
 |
|
 |
1 - Add the function OnDestroy, dont forget to comment CView::OnDestroy()
2 - Call OnDestroy inside OnEndPrintPreview
void CDummyView::OnEndPrintPreview(CDC* pDC, CPrintInfo* pInfo, POINT point, CPreviewView* pView)
{
CView::OnEndPrintPreview(pDC, pInfo, point, pView);
OnDestroy();
}
void CDummyView::OnDestroy()
{
//CView::OnDestroy();
// show the original frame
m_pOldFrame->ShowWindow(SW_SHOW);
// restore main frame pointer
AfxGetApp()->m_pMainWnd = m_pOldFrame;
m_pDialog->EndPreviewMode();
m_pDialog->SetFocus();
GetParentFrame()->DestroyWindow();
}
|
|
|
|
 |
|
 |
Program still crashes on close with close button. Error in wincore.cpp line 1007:
// Should have been detached by OnNcDestroy
ASSERT(pMap->LookupPermanent(hWndOrig) == NULL);
Any Idea how to fix it?
THX
Mr. S
|
|
|
|
 |
|
 |
My solution (as this program seems to be abandoned...):
I've simply created a new CFrameWnd-derived class (CPrintPreviewFrame) with the OnClose() handler redefined to do nothing. Then I specify this class in the document template created in CPrintPreviewDialog::OnDialogPrintPreview(), so it gets used instead of the standard CFrameWnd:
class CPrintPreviewFrame: public CFrameWnd
{
public:
CPrintPreviewFrame ();
DECLARE_DYNCREATE (CPrintPreviewFrame);
protected:
afx_msg void OnClose ();
DECLARE_MESSAGE_MAP ()
};
IMPLEMENT_DYNCREATE (CPrintPreviewFrame, CFrameWnd);
CPrintPreviewFrame::CPrintPreviewFrame ()
{
}
BEGIN_MESSAGE_MAP (CPrintPreviewFrame, CFrameWnd)
ON_WM_CLOSE ()
END_MESSAGE_MAP ()
void CPrintPreviewFrame::OnClose ()
{
// nothing...
}
void CPrintPreviewDialog::OnDialogPrintPreview()
{
if (m_bPrintPreview)
{
AfxGetApp()->m_pMainWnd->SetFocus();
return;
}
CFrameWnd* pOldFrame = (CFrameWnd*)AfxGetApp()->m_pMainWnd;
pOldFrame->ShowWindow (SW_HIDE);
if (m_pTemplate == NULL)
{
m_pTemplate = new CSingleDocTemplate(
IDR_MAINFRAME, // so load fram is happy. This matches the IDR_MAINFRAME value from your application!
NULL,
RUNTIME_CLASS(CPrintPreviewFrame), // <-- HERE!
RUNTIME_CLASS(CDummyView));
//AfxGetApp()->AddDocTemplate(m_pTemplate);
}
CFrameWnd* pFrameWnd = m_pTemplate->CreateNewFrame(NULL, NULL);
// In derived classes, implement special window handling here
// Be sure to Unhook Frame Window close if hooked.
// must not create this on the frame. Must outlive this function
DEL (m_pState);
m_pState = new CPrintPreviewState;
m_bPrintPreview = true;
m_pTemplate->InitialUpdateFrame(pFrameWnd, NULL, FALSE);
m_pView = (CDummyView*)pFrameWnd->GetActiveView();
AfxGetApp()->m_pMainWnd = pFrameWnd;
pFrameWnd->SetWindowText(_T("Print preview"));
pFrameWnd->ShowWindow(SW_SHOWMAXIMIZED);
m_pView->SetPrintDialog(this);
m_pView->m_pOldFrame = pOldFrame;
m_pView->OnDoPrintPreview();
}
This way the close button on the caption bar remains unuseful, but at least it doesn't make the application crash.
Cheers
Eduard
|
|
|
|
 |
|
 |
How do I add a page setup and print separately which gets reflected in the preview and print?
|
|
|
|
 |
|
 |
I have written an with Print Preview capability and cant seem to get the Prev Page button working. Any ideas? The Next Page and Two Pages buttons work fine. I have tried setting the SetMaxPage and SetMinPage and m_nCurPage values in OnPreparePrinting thinking these would enable the button, but sadly these changes had no effect.
Any help would be much appreciated.
BTW! Great article
Andy
|
|
|
|
 |
|
 |
please click on the next page!
find out the artikel "Dialog bar button update fix".
---
Yunce
|
|
|
|
 |