previewpanel and printer settings

TeeChart for ActiveX, COM and ASP
Post Reply
jti
Newbie
Newbie
Posts: 17
Joined: Fri Nov 15, 2002 12:00 am
Contact:

previewpanel and printer settings

Post by jti » Fri Jul 19, 2013 12:22 am

I am writing an MFC program with MDI. I have successfully pulled 4 charts from 4 documents and put them on a TeePreviewPanel. I have not been able to change the printer used by the previewpanel's printpage. What is the TeeChart way to do this?
dialog.jpg
Dialog
dialog.jpg (73.15 KiB) Viewed 30987 times
On the dialog with the TeePreviewPanel, I have a button for Printer Setup (ID_FILE_PRINT_SETUP), so it brings up the printer setup via MFC with no code on my part. The print button on this screen calls m_ctrlPV.PrintPage(), where m_ctrlPV is the preview control.

I have verfied that the ID_FILE_PRINT_SETUP is setting the printer by querying just before the PrintPage with
// Get current printer's settings.
PRINTDLG FAR * pPrintDlg = new PRINTDLG;
if(AfxGetApp()->GetPrinterDeviceDefaults(pPrintDlg))
{
// Get pointers to the two setting structures.
DEVNAMES FAR *lpDevNames = (DEVNAMES FAR *)::GlobalLock(pPrintDlg->hDevNames);
DEVMODE FAR *lpDevMode = (DEVMODE FAR *)::GlobalLock(pPrintDlg->hDevMode );

// Get the specific driver information.
CString csDevice((LPTSTR)lpDevNames + lpDevNames->wDeviceOffset);
}
m_ctrlPV.PrintPage(); // This prints to the system default printer

I have done this with 2013 Evaluation, after failing to get this to work with 5.0.6.0. I have attached a jpeg of my dialog.

Thanks for your help.

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: previewpanel and printer settings

Post by Yeray » Fri Jul 19, 2013 8:23 am

Hi,

TeeChart uses the default printer set in the system. I'm not sure how to change this default printer programmatically. You could try something like "Setting the Application's Default Printer" here
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

jti
Newbie
Newbie
Posts: 17
Joined: Fri Nov 15, 2002 12:00 am
Contact:

Re: previewpanel and printer settings

Post by jti » Mon Jul 22, 2013 8:57 pm

I do not think that we have communicated yet. I have a stripped down project that demonstrates the problem. The upload of the 32 kB zip file has failed three times. How can I get the project to you?

My problem is that the preview panel object only prints to the default printer and not to a printer setup done by the application.

Steps to demonstrate my issue.
1) Load the project in Visual Studio 2012.
2) From project F5, to compile & run in debugger.
3) File->Print Setup. Change the printer to any printer other than your default printer.
4) Alt-R, or Analysis -> Run on menu. This runs creates four charts.
5) Print [Ctrl-P, or File->Print Graphs]
6) Select No, on the message box.
7) Select a checkbox and , then press the Print button. The selected plot now prints on the printer from step 3.
8) Now print again, and select Yes on the message box to get a preview panel..
9) Press the Print button. And the preview prints on the default printer and not the selected printer.

Is this a bug, or am I using TeeChart incorrectly?

Note the Printer Setup on the preview panel shows the selected printer (not the default printer) Also there is code in the CMultiPrint::OnBnClickedOk() that shows the application still knows that the device is selected printer and not the default printer.

My expectation is the any time before the print is done on the preview panel that I should be able to do a print setup and have it use the correct printer. Also if a printer is selected in the application before the preview panel is done, I expect the application to use the selected printer.

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: previewpanel and printer settings

Post by Yeray » Tue Jul 23, 2013 11:19 am

Hi,

You can post your files at our upload page.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

jti
Newbie
Newbie
Posts: 17
Joined: Fri Nov 15, 2002 12:00 am
Contact:

Re: previewpanel and printer settings

Post by jti » Tue Jul 23, 2013 11:58 am

I have tried your upload page with IE9 and Firefox

Server Error in '/' Application.
--------------------------------------------------------------------------------

Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.

Source Error:


Line 24: ASP.NET to identify an incoming user.
Line 25: -->
Line 26: <authentication mode="Windows"/>
Line 27: <!--
Line 28: The <customErrors> section enables configuration


Source File: C:\inetpub\wwwroot\upload\web.config Line: 26


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.4234; ASP.NET Version:2.0.50727.4223

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: previewpanel and printer settings

Post by Yeray » Tue Jul 23, 2013 2:29 pm

Hi,

I'm sorry for the inconvenience. We'll revise it.
If it's only 32kB, you can attach it to a mail and send it to "info at steema dot com".
Just ask to forward it to me, referencing this thread.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: previewpanel and printer settings

Post by Yeray » Wed Jul 24, 2013 10:52 am

Hi again,

We've received your project. Thanks for it. However, I'm afraid I can't build it:
Error 1 error LNK1104: cannot open file 'libmmd.lib' \JtiHorizontal\LINK JtiHorizontal
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

jti
Newbie
Newbie
Posts: 17
Joined: Fri Nov 15, 2002 12:00 am
Contact:

Re: previewpanel and printer settings

Post by jti » Wed Jul 24, 2013 8:52 pm

The code that required libmmd.lib has been removed as well as the code that required htmlhelp.lib. These libraries may be removed from Project->Properties->Linker->Input->Additional Dependencies for all configurations.

jti
Newbie
Newbie
Posts: 17
Joined: Fri Nov 15, 2002 12:00 am
Contact:

Re: previewpanel and printer settings

Post by jti » Fri Jul 26, 2013 1:59 pm

The code that required libmmd.lib had been removed as well as the code that required htmlhelp.lib. Removing the references for the libraries in the project will permit the current code to compile. Project->Properties->Linker->Input->Additional Dependencies for all configurations.

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: previewpanel and printer settings

Post by Yeray » Mon Jul 29, 2013 12:15 pm

Hi,

Try setting the chart printer. Ie:

Code: Select all

TChart1.Printer.PrinterIndex = 2
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

jti
Newbie
Newbie
Posts: 17
Joined: Fri Nov 15, 2002 12:00 am
Contact:

Re: previewpanel and printer settings

Post by jti » Mon Jul 29, 2013 11:37 pm

I am not sure where you intend for me to set the printer index. The preview panel (m_ctrlPV) does not have a GetPrinter() method, so I see no way to address the object being printed. I tried the following code with no success in changing the printer.

Code: Select all

void CMultiPrint::OnBnClickedOk()
{
	CPrinter pr;
	pr.SetPrinterIndex(2);

	m_ctrlPV.PrintPage();  // This prints to the system default printer
}

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: previewpanel and printer settings

Post by Yeray » Tue Jul 30, 2013 1:29 pm

Hi,

I'm not sure how to get the index of the printer selected in the "Print Setup..." dialog, but you can assign the index to be used as follows:

Code: Select all

void CMultiPrint::OnBnClickedOk()
{
	m_ctrlChart1->GetPrinter().SetPrinterIndex(2);
	m_ctrlChart2->GetPrinter().SetPrinterIndex(2);
	m_ctrlChart3->GetPrinter().SetPrinterIndex(2);
	m_ctrlChart4->GetPrinter().SetPrinterIndex(2);

	m_ctrlPV.PrintPage();
}
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

jti
Newbie
Newbie
Posts: 17
Joined: Fri Nov 15, 2002 12:00 am
Contact:

Re: previewpanel and printer settings

Post by jti » Tue Jul 30, 2013 5:59 pm

That certainly sent it to a different printer, not the printer selected from page setup. Armed with a little knowledge on how to set a printer I wrote the following work around, which makes the program work.

Code: Select all

void CMultiPrint::OnBnClickedOk()
{
	PRINTDLG FAR * pPrintDlg = new PRINTDLG;
	CString csDevice;

	// Get current printer's settings.
	if(AfxGetApp()->GetPrinterDeviceDefaults(pPrintDlg))
	{
		// Get pointers to the two setting structures.
		DEVNAMES FAR *lpDevNames = (DEVNAMES FAR *)::GlobalLock(pPrintDlg->hDevNames);
		DEVMODE  FAR *lpDevMode  = (DEVMODE  FAR *)::GlobalLock(pPrintDlg->hDevMode );
			
		// Get the specific driver information.
		csDevice = CString ((LPTSTR)lpDevNames + lpDevNames->wDeviceOffset);

		int nP = m_ctrlChart1->GetPrinter().GetPrinterCount();
		CString csPD;
		for (int i = 0; i<nP; i++)
		{
			csPD = m_ctrlChart1->GetPrinter().GetPrinterDescription(i);
			if (csPD == csDevice)
			{
				m_ctrlChart1->GetPrinter().SetPrinterIndex(i);
				m_ctrlChart2->GetPrinter().SetPrinterIndex(i);
				m_ctrlChart3->GetPrinter().SetPrinterIndex(i);
				m_ctrlChart4->GetPrinter().SetPrinterIndex(i);
				i = nP;
			}
		}

		m_ctrlPV.PrintPage();

		::GlobalUnlock(pPrintDlg->hDevNames);
		::GlobalUnlock(pPrintDlg->hDevMode);
	}
	delete pPrintDlg;

// CDialogEx::OnOK();  // makes the dialog to go away after OK
}

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: previewpanel and printer settings

Post by Yeray » Wed Jul 31, 2013 7:29 am

Hi,

Great!
Thanks for sharing the solution!
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply