Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sat Dec 07, 2019 8:40 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Display printer properties
PostPosted: Thu Feb 23, 2012 8:15 am 
Offline

Joined: Thu Nov 08, 2007 4:59 am
Posts: 392
Location: Germany
Hello,

I try to display the properties for a printer
For this I use the WINAPI function "PrinterProperties"
http://msdn.microsoft.com/en-us/library/dd162837(v=vs.85).aspx

My problem is that instead of the printerproperties I only get the printer version-information.
But I have an idea of what the problem might be. I use this API-Call :
iReturn=OpenPrinter(sPrintername, iPrinterHandle, 0)


I think that instead of 0 I need to pass a "PRINTER_DEFAULTS" structure\memoryblock to the function and set "DesiredAccess=PRINTER_ALL_ACCESS"
http://msdn.microsoft.com/en-us/library/dd162839

The "PRINTER_DEFAULTS" structure has reference to another structure: DEVMODE
http://msdn.microsoft.com/en-us/library/dd183565

So I need some input about how to pass the PRINTER_DEFAULTS / DEVMODE to OpenPrinter()

Here my code:
Declare Function OpenPrinter _
Lib "winspool.drv" Alias "OpenPrinterA" ( _
PrinterName As Cstring, _
byRef phPrinter As integer, _
pDefault As integer) As integer


Declare Function ClosePrinter _
Lib "winspool.drv" ( _
hPrinterhandle As integer ) As integer


Declare Function PrinterProperties _
Lib "winspool.drv" ( _
windowHandle As Integer, Printerhandle As Integer) As Integer


dim iReturn as integer
dim iPrinterHandle as Integer
dim sPrintername as String

sPrintername = EditField1.Text //"EPSON Stylus Series"
iReturn = OpenPrinter(sPrintername, iPrinterHandle, 0) // <------------------ the 0 here may be the problem

'**iReturn is <>0 so the OpenPrinter call works


'**this should open the printer properties dialogbox....but it only displays Printer/Driver Version
'iReturn = PrinterProperties (window1.Handle,iPrinterHandle)
iReturn = PrinterProperties (0,iPrinterHandle)


iReturn= closePrinter (iPrinterHandle)


I use XP

Heinz


Top
 Profile  
Reply with quote  
 Post subject: Re: Display printer properties
PostPosted: Fri Feb 24, 2012 11:35 am 
Offline
User avatar

Joined: Wed May 10, 2006 2:42 pm
Posts: 2985
Location: Germany
What are you doing?
I have a lot of print related classes for windows in our plugin and I could add you this function easily.

Greetings
Christian

_________________
See you in Orlando, Florida for Real World 2013
More details and registration here:
http://www.realsoftware.com/community/realworld.php


Top
 Profile  
Reply with quote  
 Post subject: Re: Display printer properties
PostPosted: Fri Feb 24, 2012 12:49 pm 
Offline

Joined: Thu Nov 08, 2007 4:59 am
Posts: 392
Location: Germany
Hello,

I need to change printer properties like tray or papersize etc.
For this I want to display the "printer properties dialog" or optionally the "printer setup dialog"
(This is selectable with "PD_PRINTSETUP")

The changes to the properties should be for the next print job and optionally I need the changes to be saved permanently
(I'm not sure but here it seems that the DEVMODE structure comes into play?)

I've found "PrintDlg" API function :
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646940(v=vs.85).aspx

But with PrintDlg the changes made in the printer properties are only for a particular print job and not permanent
("Displays a Print Dialog Box or a Print Setup dialog box. The Print dialog box enables the user to specify the properties of a particular print job.")

But I'd need an option that allows to save the changes permanently


There is another Function "PrintDlgEx" :
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646942(v=vs.85).aspx

But like PrinterDlg the change made to the properties are not permanent but only for "a particular print job")
("Displays a Print property sheet that enables the user to specify the properties of a particular print job")


And there is also a function "DocumentProperties" which allows to change printer settings, too
Maybe this is the way to go ?
(at least in the description I can not find anything abgut a "particular print job")
http://msdn.microsoft.com/en-us/library/windows/desktop/dd183576(v=vs.85).aspx

maybe we need a combination of PrintDlg / PrintDlgEx and DocumentProperties ?

Heinz

_________________
Living in Southern-Germany?
Join our usergroup for Baden-Württemberg here :
http://groups.google.com/group/RealstudioUGBW?hl=de


Top
 Profile  
Reply with quote  
 Post subject: Re: Display printer properties
PostPosted: Fri Feb 24, 2012 9:17 pm 
Offline
User avatar

Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
Here's a function I had laying around. It gets the name of the default printer and opens the printer properties dialog for that printer. If you already have code to get the names of printers other than the default then you can easily modify this code to work with arbitrary printer names.

A few notes:
This function returns an integer. 0 = success; anything else is the last error code reported by Windows. For example, if the Print Spooler service isn't running, this function returns error 1722.

You can pass a window to this function. The passed window then serves as the parent window of the printer dialog window.
If no window is passed then the desktop serves as the parent window.

Declare Function GetLastError Lib "Kernel32" () As Integer
Declare Function GetDefaultPrinterW Lib "WinSpool.Drv" (buffer As Ptr, ByRef bufferSize As Integer) As Boolean
Declare Function OpenPrinterW Lib "WinSpool.Drv" (PrinterName As WString, ByRef PrinterHandle As Integer, defaults As Ptr) As Boolean
Declare Function PrinterProperties Lib "WinSpool.Drv" (ParentWindow As Integer, PrinterHandle As Integer) As Boolean
Declare Function ClosePrinter Lib "WinSpool.Drv" (PrinterHandle As Integer) As Boolean

Dim requiredSize As Integer
Dim parentHandle As Integer
If ParentWindow <> Nil Then parentHandle = ParentWindow.Handle
Call GetDefaultPrinterW(Nil, requiredSize) //First call GetDefaultPrinter with Nil to get the length of the printer's name
requiredSize = requiredSize * 2
Dim mb As New MemoryBlock(requiredSize) //Then make our buffer the right size
If GetDefaultPrinterW(mb, requiredSize) Then
Dim printerHandle As Integer
If OpenPrinterW(mb.WString(0), printerHandle, Nil) Then //Get a handle to the printer
Call PrinterProperties(parentHandle, printerHandle)
Call ClosePrinter(printerHandle)
Return 0
End If
End If

Return GetLastError()

_________________
Boredom Software


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group