How to get printer list?
-
- Knows some wx things
- Posts: 42
- Joined: Wed Nov 24, 2004 9:04 am
- Location: Berlin, Germany
- Contact:
How to get printer list?
Hello Group!
I hhope, someone can help. The printing functionality in wxWindows is great but am I to blind to see how to get a list of system printers.
I can set the used printer by it's name in wx... but the names of the printers in my program i get with a little delphi-dll under MSW. There must be another way!? And what's the way under linux?
Thanx for help
I hhope, someone can help. The printing functionality in wxWindows is great but am I to blind to see how to get a list of system printers.
I can set the used printer by it's name in wx... but the names of the printers in my program i get with a little delphi-dll under MSW. There must be another way!? And what's the way under linux?
Thanx for help
Re: How to get printer list?
Do you mean how do you present the user with a list of installed printers? Like the dialog which sits under the "Printers..." button on Print Preview?MartinSfromB wrote:am I to blind to see how to get a list of system printers.
From th eprinting sample 2.5.3
Code: Select all
wxPrintDialogData printDialogData(* g_printData);
wxPrintDialog printerDialog(this, & printDialogData);
printerDialog.GetPrintDialogData().SetSetupDialog(true /*show print setup dialog*/);
printerDialog.ShowModal();
(*g_printData) = printerDialog.GetPrintDialogData().GetPrintData();
Follow the development of my screenplay authoring program at http://wxscreenplaywriter.blogspot.com/
-
- Knows some wx things
- Posts: 42
- Joined: Wed Nov 24, 2004 9:04 am
- Location: Berlin, Germany
- Contact:
Re: How to get printer list?
I know this is an old thread, but I have the same problem. Neither the standard print dialog or the page setup dialog make any sense with the application that I am developing. As a result, I'd like to create my own custom print dialog.
In order to create a custom print dialog, I need to be able to get a list of available printers. I'd also need to be able to open the system printer settings dialog (i.e., have a "Preferences" button next to the printer selection dialog), and preferably also be able to query which page types the currently selected printer supports.
Does wxWidgets support this?
Hans
In order to create a custom print dialog, I need to be able to get a list of available printers. I'd also need to be able to open the system printer settings dialog (i.e., have a "Preferences" button next to the printer selection dialog), and preferably also be able to query which page types the currently selected printer supports.
Does wxWidgets support this?
Hans
Seeing as this wasn't currently supported, I wrote something that provides this feature myself.
Hans
Hans
This snippet quickly gets msw printers local and remote
The problem with all the versions I've seen to date is that they only get local printers. If I've set up a remote printer, it didn't show up.
I finally found the magic invocation. One secret is to use PRINTER_INFO_4, the other is to use PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS.
With that, the net printer I'd set up on this machine showed up.
As the #defines and #errors say, this is Windows only.
Enjoy.
void CPrinterSetupDialog::GetPrinterList()
{
#if defined(__WXMSW__)
// When Name is NULL, setting Flags to PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS
// enumerates printers that are installed on the local machine. These printers include
// those that are physically attached to the local machine as well as remote printers to
// which it has a network connection.
DWORD dwFlags = PRINTER_ENUM_CONNECTIONS | PRINTER_ENUM_LOCAL;
LPTSTR Name = NULL;
DWORD dwNeeded = 0;
DWORD dwReturned = 0;
// First, find out how much space we need for the return buffers
if(::EnumPrinters(dwFlags, Name, 4, 0, 0, & dwNeeded, & dwReturned)) {
throw CLogicError(ERR_POS);
}
DWORD LastError = ::GetLastError();
if(LastError != ERROR_INSUFFICIENT_BUFFER) {
throw CLogicError(ERR_POS);
}
// Allocate the buffer
PRINTER_INFO_4 * PrinterInfo = (PRINTER_INFO_4 *)malloc(dwNeeded);
if( ! PrinterInfo) {
throw CLogicError(ERR_POS);
}
if( ! ::EnumPrinters(dwFlags, Name, 4, (unsigned char *)PrinterInfo, dwNeeded, & dwNeeded, & dwReturned)) {
throw CLogicError(ERR_POS);
}
for(int i = 0; i < (int)dwReturned; i++) {
m_PrinterName.push_back(PrinterInfo.pPrinterName);
}
free(PrinterInfo);
#else
#error CPrinterSetupDialog::GetPrinterList() has not been implemented for this platform
#endif
}
I finally found the magic invocation. One secret is to use PRINTER_INFO_4, the other is to use PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS.
With that, the net printer I'd set up on this machine showed up.
As the #defines and #errors say, this is Windows only.
Enjoy.
void CPrinterSetupDialog::GetPrinterList()
{
#if defined(__WXMSW__)
// When Name is NULL, setting Flags to PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS
// enumerates printers that are installed on the local machine. These printers include
// those that are physically attached to the local machine as well as remote printers to
// which it has a network connection.
DWORD dwFlags = PRINTER_ENUM_CONNECTIONS | PRINTER_ENUM_LOCAL;
LPTSTR Name = NULL;
DWORD dwNeeded = 0;
DWORD dwReturned = 0;
// First, find out how much space we need for the return buffers
if(::EnumPrinters(dwFlags, Name, 4, 0, 0, & dwNeeded, & dwReturned)) {
throw CLogicError(ERR_POS);
}
DWORD LastError = ::GetLastError();
if(LastError != ERROR_INSUFFICIENT_BUFFER) {
throw CLogicError(ERR_POS);
}
// Allocate the buffer
PRINTER_INFO_4 * PrinterInfo = (PRINTER_INFO_4 *)malloc(dwNeeded);
if( ! PrinterInfo) {
throw CLogicError(ERR_POS);
}
if( ! ::EnumPrinters(dwFlags, Name, 4, (unsigned char *)PrinterInfo, dwNeeded, & dwNeeded, & dwReturned)) {
throw CLogicError(ERR_POS);
}
for(int i = 0; i < (int)dwReturned; i++) {
m_PrinterName.push_back(PrinterInfo.pPrinterName);
}
free(PrinterInfo);
#else
#error CPrinterSetupDialog::GetPrinterList() has not been implemented for this platform
#endif
}
Thanks rogue. I'm a little surprised that your installed network printers didn't show, as mine did. It might be something to do with how I set mine up. Anyway, I have updated the code (and the archive on my website) to use PRINTER_INFO_4 as your code snippet shows.
Perhaps you could test the new version to confirm that it shows your remote printers.
Hans
Perhaps you could test the new version to confirm that it shows your remote printers.
Hans
-
- Earned some good credits
- Posts: 119
- Joined: Wed May 19, 2021 11:17 pm
- Contact:
Re: How to get printer list?
Given a specific printer,
how do you query its capabilities?
The equivalent of wxSystemSettings::GetMetrics
which is for querying the system.
For example the dpi for each of its quality settings?
how do you query its capabilities?
The equivalent of wxSystemSettings::GetMetrics
which is for querying the system.
For example the dpi for each of its quality settings?