I had an email requesting how to obtain details of the
current printer. The following code is used in the class library
which I use to develop my utility programs. If anyone has some nicer
code that does not involve the use of API commands then please send
me
the details. The lines highlighted is the code that populates my printer
dialogue window's datawindow which shows the printer details to the
user. You will need to change these to work with your own
application. /********************************************************************
SetPrinterInfo
<DESC> Examine the registry for the current printer details and
set them into the datawindow that display the options.
</DESC>
<ACCESS> Protected
<USAGE> this.SetPrinterInfo()
********************************************************************/
String ls_Server, ls_Printer, ls_Driver, ls_Location, ls_Section
Constant String ls_Providers = &
'HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Providers\'
Long ll_ServerStart, ll_ServerEnd, ll_PrinterEnd
ls_Printer = idw_print.Object.Datawindow.Printer
dw_Print.SetItem( 1, 'currentprinter', ls_Printer )
ll_ServerStart = 3
ll_ServerEnd = Pos( ls_Printer, '\', ll_ServerStart )
ll_PrinterEnd = Pos( ls_Printer, ' ', ll_ServerEnd )
ls_Server = Mid( ls_Printer, ll_ServerStart, &
ll_ServerEnd - ll_ServerStart )
ls_Printer = Mid( ls_Printer, ll_ServerEnd + 1, &
ll_PrinterEnd - ll_ServerEnd - 1 )
ls_Section = ls_Providers + 'LanMan Print Services\Servers\' &
+ ls_Server + '\Printers\' + ls_Printer
RegistryGet( ls_Section, 'Location', ls_Location )
RegistryGet( ls_Section, 'Printer Driver', ls_Driver )
dw_Print.SetItem( 1, 'location', ls_Location )
dw_Print.SetItem( 1, 'driver', ls_Driver )
|