Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to know which printer user selected in ComDlg?
Message
From
20/09/2006 02:28:30
 
 
To
19/09/2006 16:56:18
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
General information
Forum:
Visual FoxPro
Category:
ActiveX controls in VFP
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP1
Miscellaneous
Thread ID:
01155181
Message ID:
01155360
Views:
19
>>>So, question #1: how do I get the printer properties from the hDC? I may just let the dialog set the windows default printer (as the printer doesn't change for VFP if I don't) and then restore it when I'm done, but that's ugly.
>>>
>>>Question #2: how can I filter out the printers it shows? It shows ALL the printers, and I want to kick out any of them that have "PDF" in the name. Or at least can I have a dialog that shows the printer setup for just one given printer name, without the ability to select a printer? Then I'd have a combo with a (filtered) selection elsewhere.
>>
>>Dragan,
>>
>>Maybe not the answer you're after, but still
>>
>>(1) Why not make a ListBox class (rowsourcetype 0) which you populate with selected printers from aprinters()
>
>That's plan A or plan B - I've changed them so many times in the last two days :).
>
>>(2) per printer in aprinters
>>- skip ports a la RPT?: (RedMon port redirector)
>>- skip ports a la FILE:
>>- find the printerdriver for the printer, skip it if you find the driver suspicous (or even if ADOBE $ upper(printerdriver))
>
>Your code gave me lot of hope, but I couldn't get it to work. No matter what I gave it as printer names, the first function always returned a zero, and the by ref parameters also stayed blank.
>
>I tried calling GetPrinterDriver() with a .hdc (also the so-called "information context", whatever that is) for first parameter, but no cigar either.

Yes, there was a typo in the declare of OpenPrinter()

try this. It's part of the code I use to detect postscript drivers
function do_it()
	
	declare integer OpenPrinter in Winspool.drv ;
		string @ pPrinterName, ;
		long @ phPrinter, ;
		Integer 

	declare integer ClosePrinter in Winspool.drv long hPrinter

	declare integer GetPrinterDriver in Winspool.drv ;
			long PrinterHandle, ;
			Integer pEnvironment, ;	&& null for current
			long nLevel, ;
			String @ pDriverInfo, ;	&& driver data buffer
			long cbBuflen, ;
			long @pcbNeeded 
			
	local i, aa[1], PrinterName, PrinterPort, PrinterDriver
	
	for i = 1 to aprinters(aa)
		PrinterName = aa[m.i, 1]
		PrinterPort = aa[m.i, 2]
		
		if( !PrinterDriver_Get(m.PrinterName, @m.PrinterDriver) )
			PrinterDriver = '???'
		endif
		
		?PrinterName, PrinterPort, PrinterDriver
	endfor
endfunc

function PrinterDriver_Get(PrinterName, PrinterDriver)
		
	
	local Success
	Success = TRUE

	local Handle, DriverInfo, pcbNeeded 
	DriverInfo = space(1024)
	

	Handle = 0
	pcbNeeded = 0
	
	do case
	case empty(OpenPrinter(@m.PrinterName, @m.Handle, 0))
		assert FALSE
		Success = FALSE
		
	case empty(GetPrinterDriver(m.Handle, 0, 1, @m.DriverInfo, len(m.DriverInfo), @m.pcbNeeded))
		assert FALSE
		Success = FALSE
		
	otherwise
		
		PrinterDriver = right(m.DriverInfo, m.pcbNeeded-4)
		PrinterDriver = left(m.PrinterDriver, at(chr(0), m.PrinterDriver)-1)
	endcase
	
	
	do case
	case empty(m.Handle)
	
	case empty(ClosePrinter(m.Handle))
		assert FALSE
	
	endcase
	
	return m.Success
	
endfunc
*--------------------------------------------------------------------------
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform