Re: Setting Default Values for Printer



Use the PAGESETUPDLG function (not PrinterProperties.) This is the name of
the function as well as the structure. Works perfectly in all of my apps
dating back to Windows 95 (and yes it works in XP.)

"Doug van Vianen" <courses@xxxxxxxx> wrote in message
news:efPUUiRCGHA.2036@xxxxxxxxxxxxxxxxxxxxxxx
> Hi,
>
> In a VB6 program I have a button which when pressed is supposed to cause
> the printer options box to show so that the user can change the printer
> settings such as Print Mode, Paper Size etc. When I first wrote the
> program my computer had Windows 98 and the coding below worked fine.
> However, I recently changed to a new computer with WindowsXP and the
> coding no longer works. Instead it presents a box with the message "To
> change the default device settings select 'Printer Preferences' rather
> than 'Properties' when right clicking on the printer icon in the printer's
> folder."
>
> Of course, I would like the program to work on both Windows98 and
> WindowsXP computers.
>
> Can someone tell me what coding I should be using?
>
> The current coding I use is as follows:
>
> Option Explicit
>
> Private Declare Function PrinterProperties Lib "winspool.drv" _
> (ByVal hwnd As Long, ByVal hPrinter As Long) As Long
>
> Private Declare Function OpenPrinter Lib "winspool.drv" _
> Alias "OpenPrinterA" (ByVal pPrinterName As String, _
> phPrinter As Long, pDefault As PRINTER_DEFAULTS) As Long
>
> Private Declare Function ClosePrinter Lib "winspool.drv" _
> (ByVal hPrinter As Long) As Long
>
> Private Type PRINTER_DEFAULTS
> pDatatype As Long ' String
> pDevMode As Long
> pDesiredAccess As Long
> End Type
>
> Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
> Private Const PRINTER_ACCESS_ADMINISTER = &H4
> Private Const PRINTER_ACCESS_USE = &H8
> Private Const PRINTER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or _
> PRINTER_ACCESS_ADMINISTER Or PRINTER_ACCESS_USE)
>
> The following code is for the button:
>
> Dim retVal As Long, hPrinter As Long
> Dim PD As PRINTER_DEFAULTS
>
> PD.pDatatype = 0
> ' Note that you cannot request more rights than you have as a user
> PD.pDesiredAccess = STANDARD_RIGHTS_REQUIRED Or PRINTER_ACCESS_USE
> PD.pDevMode = 0
> retVal = OpenPrinter(Printer.DeviceName, hPrinter, PD)
> If retVal = 0 Then
> MsgBox "OpenPrinter Failed!"
> Else
> retVal = PrinterProperties(Me.hwnd, hPrinter)
> retVal = ClosePrinter(hPrinter)
> End If
>
> Thank you.
>
> Doug van Vianen
>


.


Quantcast