Powerbuilder PrintSetup  Mar 20, 2001
-----------------------
Contact Info:    Mark C. Jones
                 Fortress Medical Systems, Inc.
                 310 7th Ave. N
                 Hopkins, MN 55343
                 mjones@scc.net or mjones@www.fortressmedical.com

This software is freeware and can be used in any application with 
no restrictions.                                        


The sample application can be used to programatically change the Powerbuilder
printer driver from code.  Unlike other solutions to this problem, this
method does not change the windows printer driver.

The technique used is to instantiate a shared object (i.e. an object that
runs in a different thread).  This can be used to interact with the standard
PB printsetup dialog box in the main thread.  The shared object interrogates the 
PB printsetup listbox to get a list of printers,  sets the specified the printer
in the printsetup listbox and clicks the OK button.

A small amount of flicker is visible as the printsetup dialog box is displayed and 
the default printer is changed.  For most reasonably fast machines this is 
negligible.

Objects that will need to be added to your application:

dw_dummy  Dummy external datawindow used for determining PB default printer
nvo_printsetup_client
    NVO with all the client functions:
            string uf_get_pb_default_printer ()
                   Gets the current PB printer
            string uf_remove_on_from_printername (string arg_s_printername)
                   Removes the device from the end of the printer name
                   e.g. HP LaserJet ON LPT1:  ->  HP LaserJet
            integer uf_printsetup (string arg_s_printername)
                   Calls extended print setup 
            integer uf_load_printerlist ()
                   Loads instance variables with a list of available printers
            integer uf_printselect (string arg_s_printername)
                   Selects the specified printers as the PB default.

nvo_printsetup_shared
            Used by nvo_printsetup_client.   Must be instantiated in the
            application open event before any DB connection is made (This
            is because of PB 6.5 bug with shared objects in interpreted mode)


Add the following code to your application:
//Application open event:
/*********************************************************************/
// Create the response window key pusher.  This must be done
// before the database connection to avoid bugs in interpreted mode.
/*********************************************************************/
SharedObjectRegister("nvo_printsetup_shared", "printsetup_shared")
SharedObjectGet("printsetup_shared",gnvo_printsetup_shared)

//Application close event:
// Unregister the printsetup shared object
SharedObjectUnRegister("printsetup_shared")
if isvalid(gnvo_printsetup_shared) then
	destroy gnvo_printsetup_shared
end if


// Code to change the default printer
nvo_printsetup_client lnvo_printsetup_client
lnvo_printsetup_client=create nvo_printsetup_client
integer rtn
rtn=lnvo_printsetup_client.uf_printselect("your printer name")
if rtn < 1 then
	messagebox("Unable to find specified printer","your printer name")
end if
destroy lnvo_printsetup_client





// Code to get a list of default printers.
// Any call to nvo_printsetup_client.uf_printselect or uf_printsetup
// will automatically refresh the printer list otherwise it can
// be loaded explicitly
nvo_printsetup_client lnvo_printsetup_client
lnvo_printsetup_client=create nvo_printsetup_client

integer rtn
rtn=invo_printsetup_client.uf_load_printerlist()

lb_printers.reset()

long i
for i=1 to invo_printsetup_client.il_printerlist_count
	messagebox("printer",invo_printsetup_client.is_printerlist[i])
next
destroy lnvo_printsetup_client

