Page 1 of 1

Posted: Fri Feb 22, 2002 2:09 am
by BackupUser
Restored from previous forum. Originally posted by FAKEFACTORY.

Hi, anyone knows, why this code snippet is not functional?

I want to open the printer setup dialog via API calls

Code: Select all


Structure PAGESETUPDLG
    lStructSize.l   ; As Long
    hwndOwner.l     ; As Long
    hDevMode.l      ; As Long
    hDevNames.l     ; As Long
    hDC.l
    Flags.l         ; As Long
    nFromPage.l
    nToPage.l
    nMinPage.l
    nMaxPage.l
    nCopies.l
    hInstance.l                 ; As Long
    lCustData.l                 ; As Long
    lpfnPageSetupHook.l         ; As Long
    lpfnPagePaintHook.l         ; As Long
    lpPageSetupTemplateName.l   ; As String
    hPageSetupTemplate.l        ; As Long
EndStructure

 

  psd.PAGESETUPDLG\lStructSize = Sizeof(PAGESETUPDLG)
  psd.PAGESETUPDLG\hwndOwner = WindowID()
  psd.PAGESETUPDLG\hDevMode = #NULL
  psd.PAGESETUPDLG\hDevNames = #NULL
  psd.PAGESETUPDLG\hDC = #NULL
  psd.PAGESETUPDLG\Flags = #PD_ALLPAGES | #PD_COLLATE | #PD_RETURNDC | #PD_NOSELECTION
  psd.PAGESETUPDLG\nCopies = 1
  ReturnVar.l = PageSetupDlg_(*psd)	; <- Nothing happens



Edited by - FAKEFACTORY on 22 February 2002 02:11:05

Posted: Fri Feb 22, 2002 8:39 am
by BackupUser
Restored from previous forum. Originally posted by TronDoc.

I don't know anything about APIs, but why do you have
lpPageSetupTemplateName.l ; As String
Is it a string or a long? -jb

elecTRONics DOCtor
{registeredPB}P150 32Mb w98/DOS/Linux NO DirX NO IE :wink:

Posted: Fri Feb 22, 2002 9:04 am
by BackupUser
Restored from previous forum. Originally posted by fred.

ReturnVar.l = PageSetupDlg_(*psd) ; <- Nothing happens

This line is wrong. *psd is another variable (Pointer). Right lines could be:

ReturnVar.l = PageSetupDlg_(psd) ; <- Nothing happens

or

ReturnVar.l = PageSetupDlg_(@psd) ; <- Nothing happens





Fred - AlphaSND

Posted: Fri Feb 22, 2002 7:51 pm
by BackupUser
Restored from previous forum. Originally posted by Danilo.

Well, FAKEFACTORY...
you mixed some things here.

You used the PRINTDLG structure
with the API function PageSetupDlg_().

PageSetupDlg_() --> PAGESETUPDLG structure
PrintDlg_() --> PRINTDLG structure

I rewrote you structure with big comments,
so you should see whats goin on:
(This example runs as it is, tested on win2k -
default printer should be installed)

Code: Select all


Structure PAGESETUPDLG

    lStructSize.l               ; Size of this Structure

    hwndOwner.l                 ; Handle to owner-window (0 = no owner)

    hDevMode.l                  ; Handle to a global DEVMODE structure
                                ;   On Input:   if a handle is specified,
                                ;               the values in the DEVMODE
                                ;               structure are used to init
                                ;               the controls in the dialog
                                ;               box.
                                ;   On Output:  The dialog box sets the
                                ;               hDevMode to a global memory
                                ;               handle for a DEVMODE structure
                                ;               that contains values specifying
                                ;               the user's selection.
                                ;               If the user's selections are
                                ;               not available, hDevMode is 0.

    hDevNames.l                 ; Handle to a global DEVNAMES structure.
                                ; This structure contains 3 strings that
                                ; specify the driver name, the printer name,
                                ; and the output port name.
                                ;   On Input:   if a handle is specified, the
                                ;               strings in the DEVNAMES struc
                                ;               are used to init controls in
                                ;               the dialog box.
                                ;   On Output:  The dialog box sets hDevNames
                                ;               to a global memory handle for
                                ;               a DEVNAMES structure that
                                ;               contains strings specifying
                                ;               the user's selections.
                                ;               If the user's selections are
                                ;               not available, hDevNames is 0.

    Flags.l                     ; Flags for the Dialog (see: PSD_* flags)

    ptPaperSize.POINT           ; Dimension of the paper selected by the user
                                ; The   PSD_INTHOUSANDTHSOFINCHES
                                ; or    PSD_INHUNDREDTHSOFMILLIMETERS
                                ; flag indicates the units of measurement.

    rtMinMargin.RECT            ; Specifys the minimum allowable widths for
                                ; left, top, right and bottom margins
                                ; The system ignores this member if the
                                ; PSD_MINMARGINS flag is not set.

    rtMargin.RECT               ; Specifies the widths of the
                                ; left, top, right and bottom margins
                                ;   On Input:   If you set the PSD_MARGINS flag,
                                ;               rtMargin specifies the initial
                                ;               margin values.
                                ;   On Output:  rtMargin contains the widths
                                ;               selected by the user.
                                ; The   PSD_INTHOUSANDTHSOFINCHES
                                ; or    PSD_INHUNDREDTHSOFMILLIMETERS
                                ; flag indicates the units of measurement.

    hInstance.l                 ; hInstance, only needed for
                                ; PSD_ENABLEPAGESETUPTEMPLATE flag

    lCustData.l                 ; application defined data for the WM_INITDIALOG
                                ; message that is sent to lpfnPageSetupHook

    lpfnPageSetupHook.l         ; pointer to a PageSetupHook hook procedure
                                ; that can process messages intended for
                                ; dialog box. This member is ignored unless
                                ; PSD_ENABLEPAGESETUPHOOK flag is set.

    lpfnPagePaintHook.l         ; pointer to a PagePaintHook hook procedure
                                ; that receives WM_PSD_* messages from the
                                ; dialog box whenever the sample page is
                                ; redrawn. By processing the messages, the
                                ; hook procedure can customize the appearance
                                ; of the sample page. This member is ignored
                                ; unless the PSD_ENABLEPAGEPAINTHOOK flag is set.

    lpPageSetupTemplateName.l   ; pointer to a string that names the dialog box
                                ; template resource in the module identified by
                                ; the hInstance member. This member is ignored
                                ; unless the PSD_ENABLEPAGESETUPTEMPLATE flag
                                ; is set.

    hPageSetupTemplate.l        ; if the PSD_ENABLEPAGESETUPTEMPLATEHANDLE flag
                                ; is set, hPageSetupTemplate is a handle to a
                                ; memory object containing the dialog box template.
EndStructure

  psd.PAGESETUPDLG\lStructSize = SizeOf(PAGESETUPDLG)
  psd.PAGESETUPDLG\hwndOwner = WindowID()
  psd.PAGESETUPDLG\hDevMode = #NULL
  psd.PAGESETUPDLG\hDevNames = #NULL

 ;--------------------------------------------------------------------------------------------
 ; try this different flags:
 ; (you can also use multiple flags)
 ;
  psd.PAGESETUPDLG\Flags = 0

 ;psd.PAGESETUPDLG\Flags = #PSD_DISABLEMARGINS             ; disable margins selection

 ;psd.PAGESETUPDLG\Flags = #PSD_DISABLEORIENTATION         ; disable orientation selection

 ;psd.PAGESETUPDLG\Flags = #PSD_DISABLEPAGEPAINTING        ; shows empty preview-page only

 ;psd.PAGESETUPDLG\Flags = #PSD_DISABLEPAPER               ; disable paper selection

 ;psd.PAGESETUPDLG\Flags = #PSD_DISABLEPRINTER             ; disable printer selection button

 ;psd.PAGESETUPDLG\Flags = #PSD_INHUNDREDTHSOFMILLIMETERS  ; Millimeter

 ;psd.PAGESETUPDLG\Flags = #PSD_INTHOUSANDTHSOFINCHES      ; Inches

 ;psd.PAGESETUPDLG\Flags = #PSD_SHOWHELP                   ; show HELP-button

 ;psd.PAGESETUPDLG\Flags = #PSD_NOWARNING                  ; No Warning message if no
                                                           ; default printer is installed

 ;psd.PAGESETUPDLG\Flags = #PSD_RETURNDEFAULT              ; do not display a dialog box.
                                                           ; Instead, it sets the
                                                           ; hDevNames and hDevMode
                                                           ; members to handles to DEVMODE
                                                           ; and DEVNAMES structures that
                                                           ; are initialized for the system
                                                           ; default printer.
                                                           ; PageSetupDlg_() returns an error
                                                           ; if either hDevNames or hDevMode
                                                           ; is not 0.
 ;--------------------------------------------------------------------------------------------




  ReturnVar.l = PageSetupDlg_(psd)

  ; ReturnVar = 1: "OK"-Button clicked
  ; ReturnVar = 0: "CANCEL"-Button clicked
  MessageRequester("ReturnValue:",Str(ReturnVar),0)
cya,
...Danilo

(registered PureBasic user)

Posted: Fri Feb 22, 2002 8:58 pm
by BackupUser
Restored from previous forum. Originally posted by FAKEFACTORY.

Danilo, your're great! Many thanks!

Vielen Dank! Jetzt hast du was gut bei mir - hab mir fast die Zähne ausgebrochen an diesem Code.

Registered PureBasic Coder

Posted: Fri Feb 22, 2002 9:02 pm
by BackupUser
Restored from previous forum. Originally posted by Danilo.

welcome...

(registered PureBasic user)