Hello,
Thank you for the replies.
From third party side, everything is okay. Their sample application is also working fine. In our application, printing is performed successfully. The problem occurs only in case of printing the sub-sequent page. I need a proper mechanism in VC++ (as I am novice in this area) that handle that message raised from the API to the window. To achieve this, I have created a class that is inherited from CWnd, so that I can handle messages.
Below is the latest design I am using. Please check it.
Code:
class CFxPrinterWnd : public CWnd
{
DECLARE_DYNCREATE(CFxPrinterWnd)
public:
CFxPrinterWnd(); // protected constructor used by dynamic creation
virtual ~CFxPrinterWnd();
public:
#ifdef _DEBUG
virtual void AssertValid() const;
#ifndef _WIN32_WCE
virtual void Dump(CDumpContext& dc) const;
#endif
#endif
protected:
DECLARE_MESSAGE_MAP()
public:
int PrintReport(int flg);
protected:
virtual LRESULT DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam);
};
LRESULT CFxPrinterWnd::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch( message )
{
case WM_DESTROY:
// e.g. Stop the printing if it was still running and the window or app is closed.
mpUninitialize();
Sleep(1000);
break;
case MP_EVENT_REQ_NEW_PAGE:
int ret;
ret = PrintReport(1);
if (ret == 0)
{
mpReqPrintNewPage(NULL, FALSE );
}
else if (ret == 1)
{
mpReqPrintNewPage(NULL, TRUE);
}
}
return CWnd::DefWindowProc(message, wParam, lParam);
}
void CAboutDlg::OnBnClickedButton1()
{
int ret;
ret = wnd.PrintReport(0);
}
int CFxPrinterWnd::PrintReport(int flg)
{
... ... ...
... ... ...
if (flg == 0)
{
CString title;
title = _T("del");
hWnd = ::FindWindow(NULL, title);
CFxPrinterWnd::Attach(hWnd);
if (hWnd == NULL)
{
::AfxMessageBox(_T("FindWindow failed."));
return -1;
}
//Initializing the print library
gl_hPrintDC = mpInitialize(hWnd, sizePaper, 1);
if (gl_hPrintDC == NULL)
{
::AfxMessageBox(_T("mpInitialize failed."));
return -1;
}
... ... ...
... ... ...
}
}
Now, in the Attach function, I am getting "Debug Assertion failed!" error message at wincore.cpp Line: 380 which is like "ASSERT(FromHandlePermanent(hWndNew) == NULL);".
Can you please let me know how to solve this? If you can find any other way to implement this, please let me know.
--
Regards,
Sachin.