Page 1 of 1
previewpanel and printer settings
Posted: Fri Jul 19, 2013 12:22 am
by 6926758
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
- dialog.jpg (73.15 KiB) Viewed 31017 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.
Re: previewpanel and printer settings
Posted: Fri Jul 19, 2013 8:23 am
by yeray
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
Re: previewpanel and printer settings
Posted: Mon Jul 22, 2013 8:57 pm
by 6926758
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.
Re: previewpanel and printer settings
Posted: Tue Jul 23, 2013 11:19 am
by yeray
Hi,
You can post your files at our
upload page.
Re: previewpanel and printer settings
Posted: Tue Jul 23, 2013 11:58 am
by 6926758
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
Re: previewpanel and printer settings
Posted: Tue Jul 23, 2013 2:29 pm
by yeray
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.
Re: previewpanel and printer settings
Posted: Wed Jul 24, 2013 10:52 am
by yeray
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
Re: previewpanel and printer settings
Posted: Wed Jul 24, 2013 8:52 pm
by 6926758
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.
Re: previewpanel and printer settings
Posted: Fri Jul 26, 2013 1:59 pm
by 6926758
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.
Re: previewpanel and printer settings
Posted: Mon Jul 29, 2013 12:15 pm
by yeray
Hi,
Try setting the chart printer. Ie:
Re: previewpanel and printer settings
Posted: Mon Jul 29, 2013 11:37 pm
by 6926758
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
}
Re: previewpanel and printer settings
Posted: Tue Jul 30, 2013 1:29 pm
by yeray
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();
}
Re: previewpanel and printer settings
Posted: Tue Jul 30, 2013 5:59 pm
by 6926758
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
}
Re: previewpanel and printer settings
Posted: Wed Jul 31, 2013 7:29 am
by yeray
Hi,
Great!
Thanks for sharing the solution!