Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » RichText,QTF,RTF... » Name of a print job is missing
Name of a print job is missing [message #5422] Thu, 21 September 2006 01:48 Go to next message
zsolt is currently offline  zsolt
Messages: 697
Registered: December 2005
Location: Budapest, Hungary
Contributor
When printing Report object, the name of the job is missing in the list of pending jobs.

Fix is simple:

In Report/Reportdlg.cpp change Print() from
bool Print(Report& r, int i, const char *_name) {
	PrinterJob pd;

to
bool Print(Report& r, int i, const char *_name) {
	PrinterJob pd(_name);
Re: Name of a print job is missing [message #6439 is a reply to message #5422] Mon, 13 November 2006 02:18 Go to previous messageGo to next message
laurice is currently offline  laurice
Messages: 22
Registered: September 2006
Promising Member
How do you print directly to default printer without the popup printer dialog?

Thanks,

Laurice
Re: Name of a print job is missing [message #6446 is a reply to message #6439] Mon, 13 November 2006 08:39 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Do not call Execute for PrinterJob.

Mirek
Re: Name of a print job is missing [message #6450 is a reply to message #5422] Mon, 13 November 2006 09:14 Go to previous messageGo to next message
laurice is currently offline  laurice
Messages: 22
Registered: September 2006
Promising Member
Hi Mirek,

I tried the following in my code:

PrintJob pd("test");
Draw& w = pd.GetDraw();
w.StartPage();
w.DrawDrawing(500, 500, sz.cx, sz.cy, r.GetPage(0));
w.EndPage();

but it does not print anything. Am I missing anything?
btw, r = Report;

Thanks,

Laurice
Re: Name of a print job is missing [message #6453 is a reply to message #6450] Mon, 13 November 2006 10:09 Go to previous messageGo to next message
zsolt is currently offline  zsolt
Messages: 697
Registered: December 2005
Location: Budapest, Hungary
Contributor
My solution to direct printing:

//CtrlLib/CtrlUtil.h - above struct Win32PrintDlg_; and #ifdef:
Draw * GetDefaultPrintDraw(const String &a_name);




//CtrlLib/PrinterJob.cpp In windows part after PrinterJob& PrinterJob::CurrentPage(int i):
Draw * GetDefaultPrintDraw(const String &a_name)
{
	One<Win32PrintDlg_> pdlg = new Win32PrintDlg_;
	PRINTDLG& dlg = *pdlg;
	dlg.Flags = PD_DISABLEPRINTTOFILE|PD_NOSELECTION|PD_RETURNDC|PD_HIDEPRINTTOFILE
		|PD_PRINTSETUP|PD_ALLPAGES|PD_RETURNDEFAULT;
	dlg.nFromPage = 1;
	dlg.nToPage = 1;
	dlg.nMinPage = 1;
	dlg.nMaxPage = 1;
	dlg.hwndOwner = GetActiveWindow();
	dlg.hDevNames = NULL;
	dlg.hDevMode = NULL;
	if(!PrintDlg(&dlg)) return false;
	return new PrintDraw(dlg.hDC, Nvl(a_name, Ctrl::GetAppName()));
}


//After last method, but in POSIX section:
Draw * GetDefaultPrintDraw(const String &a_name)
{
	String options;
	PrinterDlg dlg;
	options.Clear();
	options << " -d " << ~dlg.printer;
	options << " -o media=" << ~dlg.paper << "," << ~dlg.slot;
	if(dlg.landscape)
		options << " -o landscape";
	options << " -o number-up=" << ~dlg.npage;
	options << " -n " << ~dlg.copies;
	if(dlg.collate)
		options << " -o Collate=True";
	
	Size pgsz;
	pgsz.cx = 6000 * 210 / 254;
	pgsz.cy = 6000 * 297 / 254;

	PrinterDraw *pd = new PrinterDraw(pgsz);
	pd->options = options;
	return pd;
}

Maybe it has a lot of code not needed, but I didn't work too much with it.
Re: Name of a print job is missing [message #6455 is a reply to message #6453] Mon, 13 November 2006 10:20 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Well, but this does not allow to set orientation....

I am currently looking into problem. The trouble is that once hDevMode is set (to set landscape mode), it is no more possible to call PrintDlg with PD_RETURNDEFAULT...

Mirek
Re: Name of a print job is missing [message #6459 is a reply to message #5422] Mon, 13 November 2006 11:02 Go to previous messageGo to next message
laurice is currently offline  laurice
Messages: 22
Registered: September 2006
Promising Member
Hi Mirek,

So how do I use this in my code?
I'll call this method directly ?

Please shed a li'l more tip.

Thanks,

Miches
Re: Name of a print job is missing [message #6460 is a reply to message #6453] Mon, 13 November 2006 11:02 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
OK, first quick fix:

bool PrinterJob::Execute0(bool dodlg)
{
	pdlg = new Win32PrintDlg_;
	PRINTDLG& dlg = *pdlg;
	dlg.Flags = PD_DISABLEPRINTTOFILE|PD_NOSELECTION|PD_RETURNDC|PD_HIDEPRINTTOFILE;
	dlg.nFromPage = current;
	dlg.nToPage = current;
	dlg.nMinPage = from;
	dlg.nMaxPage = to;
	if(from != to)
		dlg.Flags |= PD_ALLPAGES;
	dlg.hwndOwner = GetActiveWindow();
	dlg.Flags |= PD_RETURNDEFAULT;
	if(!PrintDlg(&dlg)) return false;
	if(dlg.hDevMode) {
		DEVMODE *pDevMode = (DEVMODE*)::GlobalLock(dlg.hDevMode);
		pDevMode->dmOrientation = landscape ? DMORIENT_LANDSCAPE : DMORIENT_PORTRAIT;
		::GlobalUnlock(dlg.hDevMode);
	}
	bool b = true;
	if(dodlg) {
		DeleteDC(dlg.hDC);
		dlg.Flags &= ~PD_RETURNDEFAULT;
		b = PrintDlg(&dlg);
	}
	if(b) {
		draw = new PrintDraw(dlg.hDC, Nvl(name, Ctrl::GetAppName()));
		page.Clear();
		if(!(dlg.Flags & PD_PAGENUMS)) {
			dlg.nFromPage = dlg.nMinPage;
			dlg.nToPage = dlg.nMaxPage;
		}
		for(int c = 0; c < ((dlg.Flags & PD_COLLATE) ? dlg.nCopies : 1); c++)
			for(int i = dlg.nFromPage - 1; i <= dlg.nToPage - 1; i++)
				for(int c = 0; c < ((dlg.Flags & PD_COLLATE) ? 1 : dlg.nCopies); c++)
					page.Add(i);
		return true;
	}
	return false;
}


Unfortunately, this still does not solve the problem with landscape mode. Looks like calling CreateDC directly is the only option to achieve required operation...

Mirek
Re: Name of a print job is missing [message #6461 is a reply to message #5422] Mon, 13 November 2006 11:05 Go to previous messageGo to next message
laurice is currently offline  laurice
Messages: 22
Registered: September 2006
Promising Member
thanks Mirek.

Applying the fix in a moment.

- Laurice
Re: Name of a print job is missing [message #6462 is a reply to message #6461] Mon, 13 November 2006 11:49 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
OK this seem to work fine for all cases:

bool PrinterJob::Execute0(bool dodlg)
{
	pdlg = new Win32PrintDlg_;
	PRINTDLG& dlg = *pdlg;
	dlg.Flags = PD_DISABLEPRINTTOFILE|PD_NOSELECTION|PD_HIDEPRINTTOFILE|PD_RETURNDEFAULT;
	dlg.nFromPage = current;
	dlg.nToPage = current;
	dlg.nMinPage = from;
	dlg.nMaxPage = to;
	if(from != to)
		dlg.Flags |= PD_ALLPAGES;
	dlg.hwndOwner = GetActiveWindow();
	dlg.Flags |= PD_RETURNDEFAULT;
	if(!PrintDlg(&dlg)) return false;
	if(dlg.hDevMode) {
		DEVMODE *pDevMode = (DEVMODE*)::GlobalLock(dlg.hDevMode);
		pDevMode->dmOrientation = landscape ? DMORIENT_LANDSCAPE : DMORIENT_PORTRAIT;
		::GlobalUnlock(dlg.hDevMode);
	}
	HDC hdc;
	if(dodlg) {
		dlg.Flags = PD_DISABLEPRINTTOFILE|PD_NOSELECTION|PD_HIDEPRINTTOFILE|PD_RETURNDC;
		if(!PrintDlg(&dlg)) return false;
		hdc = dlg.hDC;
	}
	else {
		DEVNAMES *p = (DEVNAMES *)::GlobalLock(dlg.hDevNames);
		String driver = (const char *)p + p->wDriverOffset;
		String device = (const char *)p + p->wDeviceOffset;
		if(dlg.hDevMode) {
			DEVMODE *pDevMode = (DEVMODE*)::GlobalLock(dlg.hDevMode);
			hdc = CreateDC(driver, device, NULL, pDevMode);
			::GlobalUnlock(dlg.hDevMode);
		}
		else
			hdc = CreateDC(driver, device, NULL, NULL);
	}
	if(dlg.hDevMode)
		::GlobalFree(dlg.hDevMode);
	if(dlg.hDevNames)
		::GlobalFree(dlg.hDevNames);
	if(hdc) {
		draw = new PrintDraw(hdc, Nvl(name, Ctrl::GetAppName()));
		page.Clear();
		if(!(dlg.Flags & PD_PAGENUMS)) {
			dlg.nFromPage = dlg.nMinPage;
			dlg.nToPage = dlg.nMaxPage;
		}
		for(int c = 0; c < ((dlg.Flags & PD_COLLATE) ? dlg.nCopies : 1); c++)
			for(int i = dlg.nFromPage - 1; i <= dlg.nToPage - 1; i++)
				for(int c = 0; c < ((dlg.Flags & PD_COLLATE) ? 1 : dlg.nCopies); c++)
					page.Add(i);
		return true;
	}
	return false;
}


testcase (puttin' that to reference):

#include <CtrlLib/CtrlLib.h>

GUI_APP_MAIN
{
	PrinterJob pj;
	if(PromptYesNo("Landscape?"))
		pj.Landscape();
	if(!PromptYesNo("Use default printer?"))
		pj.Execute();
	Draw& w = pj;
	w.StartPage();
	w.DrawText(0, 0, "Hello world!", Roman(100));
	w.EndPage();
}


Mirek
Re: Name of a print job is missing [message #6463 is a reply to message #6462] Mon, 13 November 2006 12:10 Go to previous message
zsolt is currently offline  zsolt
Messages: 697
Registered: December 2005
Location: Budapest, Hungary
Contributor
Thanks!
Previous Topic: report / qtf to pdf saving
Next Topic: Horizontal scrollbar
Goto Forum:
  


Current Time: Thu Apr 25 18:17:25 CEST 2024

Total time taken to generate the page: 0.02938 seconds