This vc++ code try to save rtf file in PDF.
I'm using my personal editor (CWritexTB) and before printing StatDoc of this editor always fails.
void CDlgGestDoc::OnSavepdf()
{
if ( !m_pCurrentDoc )
return;
CString csFile = m_pCurrentDoc->GetPath();
CString csNomeFilePdf = csFile.Left(csFile.ReverseFind('.'))+ ".pdf";
BROWSEINFO bi; ::ZeroMemory(&bi,sizeof(bi));
bi.ulFlags=BIF_RETURNONLYFSDIRS;
bi.lpszTitle = "Selezionare la cartella dove salvare il file pdf";
LPCITEMIDLIST lpcidLista = SHBrowseForFolder(&bi);
CString csTmp;
if ( lpcidLista )
{
SHGetPathFromIDList(lpcidLista, csTmp.GetBuffer(_MAX_PATH));
csTmp.ReleaseBuffer();
if ( csTmp.IsEmpty() )
{
MSG_INF("Nessuna cartella selezionata, file non salvato");
return;
}
m_hPDF.Create("", WS_CHILD, CRect(0,0,0,0), this, 10000001);
m_hPDF.DriverInit("Amyuni Document Converter");
m_hPDF.EnablePrinter("company", "code");
VERIFY(m_hPDF.SetDefaultPrinter());
m_hPDF.SetFileNameOptions(3 + 0x20);
m_hPDF.SetDefaultFileName(csTmp+csNomeFilePdf);
m_hPDF.CaptureEvents(TRUE);
CWritexTB hWx;
hWx.Create("",WS_CHILD,CRect(0,0,0,0),this,10000002);
hWx.CloseFile();
hWx.OpenFile(GetTemplateFilePath()+csFile);
LPDEVNAMES hDevNames;
LPDEVMODE hDevMode;
TCHAR sz[256]; strcpy(sz,"Amyuni Document Converter");
GetPrinterDevice(sz,(HGLOBAL*)&hDevNames,(HGLOBAL*)&hDevMode);
hWx.ChangeSystemPrinter((long)::GlobalLock(hDevNames),(short)::GlobalSize(hDevNames),(long)::GlobalLock(hDevMode),(short)::GlobalSize(hDevMode));
hWx.PrintDirect();
hWx.DestroyWindow();
VERIFY(m_hPDF.RestoreDefaultPrinter());
m_hPDF.DriverEnd();
m_hPDF.DestroyWindow();
}
}
What I have to do?
This is the right way?
Thanks
StartDoc fails in VC++ Applications
-
- Posts: 7
- Joined: Fri Dec 17 2004
Re: StartDoc fails in VC++ Applications
Riccardone wrote:This vc++ code try to save rtf file in PDF.
I'm using my personal editor (CWritexTB) and before printing StatDoc of this editor always fails.
void CDlgGestDoc::OnSavepdf()
{
m_hPDF.Create("", WS_CHILD, CRect(0,0,0,0), this, 10000001);
m_hPDF.DriverInit("Amyuni Document Converter");
m_hPDF.EnablePrinter("company", "code");
VERIFY(m_hPDF.SetDefaultPrinter());
m_hPDF.SetFileNameOptions(3 + 0x20);
m_hPDF.SetDefaultFileName(csTmp+csNomeFilePdf);
m_hPDF.CaptureEvents(TRUE);
CWritexTB hWx;
hWx.Create("",WS_CHILD,CRect(0,0,0,0),this,10000002);
hWx.CloseFile();
hWx.OpenFile(GetTemplateFilePath()+csFile);
LPDEVNAMES hDevNames;
LPDEVMODE hDevMode;
TCHAR sz[256]; strcpy(sz,"Amyuni Document Converter");
GetPrinterDevice(sz,(HGLOBAL*)&hDevNames,(HGLOBAL*)&hDevMode);
hWx.ChangeSystemPrinter((long)::GlobalLock(hDevNames),(short)::GlobalSize(hDevNames),(long)::GlobalLock(hDevMode),(short)::GlobalSize(hDevMode));
hWx.PrintDirect();
hWx.DestroyWindow();
VERIFY(m_hPDF.RestoreDefaultPrinter());
m_hPDF.DriverEnd();
m_hPDF.DestroyWindow();
}
}
What I have to do?
This is the right way?
Thanks
-
- Posts: 7
- Joined: Fri Dec 17 2004
Hallo Joan!
I try to apply one more EnablePrinter to my code...
{
.
.
.
// Init my pdf printer
m_hPDF.Create("", WS_CHILD, CRect(0,0,0,0), this, 10000001);
m_hPDF.DriverInit("Amyuni Document Converter");
m_hPDF.EnablePrinter("company", "activation");
VERIFY(m_hPDF.SetDefaultPrinter());
m_hPDF.SetFileNameOptions(3 + 0x20);
m_hPDF.SetDefaultFileName(csTmp+csNomeFilePdf);
m_hPDF.CaptureEvents(TRUE);
// Create my editor
CWritexTB hWx;
hWx.Create("",WS_CHILD,CRect(0,0,0,0),this,10000002);
hWx.CloseFile();
hWx.OpenFile(GetTemplateFilePath()+csFile);
HGLOBAL hDN = AfxGetDbApp()->GetDevNames();
HGLOBAL hDM = NULL;
hWx.ChangeSystemPrinter((long)::GlobalLock(hDN), (short)::GlobalSize(hDN),(long)::GlobalLock(hDM), (short)::GlobalSize(hDM));
::GlobalUnlock(hDN); ::GlobalUnlock(hDM);
// Your suggestion...
m_hPDF.EnablePrinter("company", "activation");
hWx.PrintDirect();
hWx.DestroyWindow();
VERIFY(m_hPDF.RestoreDefaultPrinter());
m_hPDF.DestroyWindow();
.
.
.
}
I have a function the get the fire message EnablePrinterPre() before printing, in this function call again the EnablePrinter(...)
But the priter doesn't work and I still have the errore in StartDoc(...)
Thanks in advanced.
Riccardo
I try to apply one more EnablePrinter to my code...
{
.
.
.
// Init my pdf printer
m_hPDF.Create("", WS_CHILD, CRect(0,0,0,0), this, 10000001);
m_hPDF.DriverInit("Amyuni Document Converter");
m_hPDF.EnablePrinter("company", "activation");
VERIFY(m_hPDF.SetDefaultPrinter());
m_hPDF.SetFileNameOptions(3 + 0x20);
m_hPDF.SetDefaultFileName(csTmp+csNomeFilePdf);
m_hPDF.CaptureEvents(TRUE);
// Create my editor
CWritexTB hWx;
hWx.Create("",WS_CHILD,CRect(0,0,0,0),this,10000002);
hWx.CloseFile();
hWx.OpenFile(GetTemplateFilePath()+csFile);
HGLOBAL hDN = AfxGetDbApp()->GetDevNames();
HGLOBAL hDM = NULL;
hWx.ChangeSystemPrinter((long)::GlobalLock(hDN), (short)::GlobalSize(hDN),(long)::GlobalLock(hDM), (short)::GlobalSize(hDM));
::GlobalUnlock(hDN); ::GlobalUnlock(hDM);
// Your suggestion...
m_hPDF.EnablePrinter("company", "activation");
hWx.PrintDirect();
hWx.DestroyWindow();
VERIFY(m_hPDF.RestoreDefaultPrinter());
m_hPDF.DestroyWindow();
.
.
.
}
I have a function the get the fire message EnablePrinterPre() before printing, in this function call again the EnablePrinter(...)
But the priter doesn't work and I still have the errore in StartDoc(...)
Thanks in advanced.
Riccardo
-
- Posts: 7
- Joined: Fri Dec 17 2004