Page 1 of 1

Posted: Mon Jul 15, 2002 12:46 pm
by BackupUser
Restored from previous forum. Originally posted by Rings.

and a PagesetupDialog(PageSetupStructure).I have tested this code in 'pure' Purebasic, but i want them as a native Feature (Windows-version of course only)So if the Printrequester have a optional Parameter for the structure we can Set and get those needed Parameters (for example Copies,PageFrom Pageto,Printername,Quality,Color etc..... ) Ihave also include the PageSetupDialog, where you can get information about papersize and margins.
Thise code is a bit tricky, coz it uses Memory for the structure.
An experimental version with globallock can used if you Set Flag to 1

Code: Select all

 ; Extended Printer-Dialog and PageSetup Functions
;
;(C) 2002 by Siegfried Rings (-Codeguru-)

;These structures are not needed
; but i leave them to know how the Orignal are typed
;
Structure PRINTDLG_TYPE
    lStructSize.l 
    hwndOwner.l 
    hDevMode.l 
    hDevNames.l 
    hdc.l 
    Flags.l 
    nFromPage.w 
    nToPage.w 
    nMinPage.w 
    nMaxPage.w 
    nCopies.w 
    hInstance.l 
    lCustData.l 
    lpfnPrintHook.l 
    lpfnSetupHook.l 
    lpPrintTemplateName.s 
    lpSetupTemplateName.s 
    hPrintTemplate.l 
    hSetupTemplate.l 
EndStructure
Structure DEVNAMES_TYPE
    wDriverOffset.w 
    wDeviceOffset.w 
    wOutputOffset.w 
    wDefault.w 
    extra.b[100]
EndStructure
Structure DEVMODE_TYPE
    dmDeviceName.b[32]
    dmSpecVersion.w 
    dmDriverVersion.w 
    dmSize.w 
    dmDriverExtra.w 
    dmFields.l 
    dmOrientation.w 
    dmPaperSize.w 
    dmPaperLength.w 
    dmPaperWidth.w 
    dmScale.w 
    dmCopies.w 
    dmDefaultSource.w 
    dmPrintQuality.w 
    dmColor.w 
    dmDuplex.w 
    dmYResolution.w 
    dmTTOption.w 
    dmCollate.w 
    dmFormName.b[32]
    dmUnusedPadding.w 
    dmBitsPerPel.w 
    dmPelsWidth.l 
    dmPelsHeight.l 
    dmDisplayFlags.l 
    dmDisplayFrequency.l 
EndStructure

;These are the constants For the PrinterDialog

    #DM_DUPLEX = $1000
    #DM_ORIENTATION = $1

    #PD_ALLPAGES = $0
    #PD_COLLATE = $10
    #PD_DISABLEPRINTTOFILE = $80000
    #PD_ENABLEPRINTHOOK = $1000
    #PD_ENABLEPRINTTEMPLATE = $4000
    #PD_ENABLEPRINTTEMPLATEHANDLE = $10000
    #PD_ENABLESETUPHOOK = $2000
    #PD_ENABLESETUPTEMPLATE = $8000
    #PD_ENABLESETUPTEMPLATEHANDLE = $20000
    #PD_HIDEPRINTTOFILE = $100000
    #PD_NONETWORKBUTTON = $200000
    #PD_NOPAGENUMS = $8
    #PD_NOSELECTION = $4
    #PD_NOWARNING = $80
    #PD_PAGENUMS = $2
    #PD_PRINTSETUP = $40
    #PD_PRINTTOFILE = $20
    #PD_RETURNDC = $100
    #PD_RETURNDEFAULT = $400
    #PD_RETURNIC = $200
    #PD_SELECTION = $1
    #PD_SHOWHELP = $800
    #PD_USEDEVMODECOPIES = $40000
    #PD_USEDEVMODECOPIESANDCOLLATE = $40000



Structure PAGESETUPDLG
    lStructSize.l
    hwndOwner.l
    hDevMode.l
    hDevNames.l
    flags.l
    ptPaperSize.POINT
    rtMinMargin.RECT
    rtMargin.RECT
    hInstance.l
    lCustData.l
    lpfnPageSetupHook.l
    lpfnPagePaintHook.l
    lpPageSetupTemplateName.s
    hPageSetupTemplate.l
EndStructure
#PSD_DEFAULTMINMARGINS ;Sets the minimum values that the user can specify For the page margins To be the minimum ;margins allowed by the printer. This is the default. This flag is ignored If the #PSD_MARGINS And PSD_MINMARGINS flags are also specified.
#PSD_DISABLEMARGINS ;Disables the margin controls, preventing the user from setting the margins.
#PSD_DISABLEORIENTATION;Disables the orientation controls, preventing the user from setting the page orientation.
#PSD_DISABLEPAGEPAINTING;Prevents the dialog box from drawing the contents of the sample page. If you enable a ;PagePaintHook hook procedure, you can still draw the contents of the sample page.
#PSD_DISABLEPAPER ;Disables the paper controls, preventing the user from setting page parameters such as the ;Mpaper size And source.
#PSD_DISABLEPRINTER;Disables the Printer button, preventing the user from invoking a dialog box that contains ;additional printer setup information.
#PSD_ENABLEPAGEPAINTHOOK ;Enables the hook Procedure specified in the lpfnPagePaintHook member. 
#PSD_ENABLEPAGESETUPHOOK ;Enables the hook Procedure specified in the lpfnPageSetupHook member.
#PSD_ENABLEPAGESETUPTEMPLATE;Indicates that the hInstance And lpPageSetupTemplateName members specify a dialog box ;template To use in place of the Default template.
#PSD_ENABLEPAGESETUPTEMPLATEHANDLE ;Indicates that the hPageSetupTemplate member identifies a Data block that contains a ;preloaded dialog box template. The system ignores the lpPageSetupTemplateName member If ;this flag is specified. 
#PSD_INHUNDREDTHSOFMILLIMETERS ;Indicates that hundredths of millimeters are the unit of measurement For margins And ;paper size. The values in the rtMargin, rtMinMargin, And ptPaperSize members are in ;hundredths of millimeters. You can set this flag on input To override the Default unit of ;measurement For the user's locale. When the function returns, the dialog box sets this ;flag To indicate the units used.
#PSD_INTHOUSANDTHSOFINCHES ;Indicates that thousandths of inches are the unit of measurement For margins And paper ;size. The values in the rtMargin, rtMinMargin, And ptPaperSize members are in thousandths ;of inches. You can set this flag on input To override the Default unit of measurement For ;the user's locale. When the function returns, the dialog box sets this flag To indicate ;the units used.
#PSD_INWININIINTLMEASURE ;Not implemented.
#PSD_MARGINS ;Causes the system To use the values specified in the rtMargin member as the initial widths ;For the left, top, right, And bottom margins. If PSD_MARGINS is Not set, the system sets ;the initial widths To one inch For all margins. 
#PSD_MINMARGINS;Causes the system To use the values specified in the rtMinMargin member as the minimum ;allowable widths For the left, top, right, And bottom margins. The system prevents the ;user from entering a width that is less than the specified minimum. If PSD_MINMARGINS is ;Not specified, the system sets the minimum allowable widths To those allowed by the ;printer. 
#PSD_NOWARNING ;Prevents the system from displaying a warning message when there is no Default printer.
#PSD_RETURNDEFAULT;PageSetupDlg does Not display the 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 ;NULL.
#PSD_SHOWHELP ;Causes the dialog box To display the Help button. The hwndOwner member must specify the ;window To receive the HELPMSGSTRING registered messages that the dialog box sends when ;the user clicks the Help button.


#GMEM_MOVEABLE = $2
#GMEM_ZEROINIT = $40

Procedure PrintDialog(hwnd,*pd.PRINTDLGAPI,*DevModeCopy.DEVMODE)
Flag=0
myDevNames.DEVNAMES
If Flag=0
 MyMemory=AllocateMemory(1,SizeOf(DEVMODE),0)
Else
 MyMemory=GlobalAlloc_(#GMEM_MOVEABLE|#GMEM_ZEROINIT, SizeOf(DEVMODE))
EndIf

 If MyMemory
       
       *pd.PRINTDLGAPI
       *pd\lStructSize = SizeOf(PRINTDLGAPI) 
       *pd\hWndOwner = hWnd 
       *pd\hDevMode = MyMemory;Devmode;@Devmode;#NULL 
       *pd\hDevNames = #NULL;@DevNames;#NULL 
       *pd\hInstance = 0;GetModuleHandle_(0);hInstance.l 
       *pd\lpfnSetupHook = #NULL 
       *pd\lpPrintSetupTemplateName = #NULL 
       *pd\lpfnPrintHook = #NULL 
       *pd\lpPrintTemplateName = #NULL 

       ;Setting up the special Printermode
       ;*DevmodeCopy\dmSize=SizeOf(DEVMODE)
       ;*DevModeCopy\dmFields = #DM_ORIENTATION | #DM_DUPLEX
       ;MessageRequester("Info",Str(*DevModeCopy\dmCopies),0)
       ;*DevModeCopy\dmCopies =2 
       
       If Flag=1
        lpDevMode=GlobalLock_(MyMemory)
        If lpDevMode
         Result=CopyMemory(*DevModeCopy.DEVMODE,MyMemory,SizeOf(DEVMODE))
         Result=CopyMemory(MyMemory,lpDevMode, SizeOf(DEVMODE))
         bReturn =GlobalunLock_(MyMemory)
        EndIf 
       Else
        Result=CopyMemory(*DevModeCopy.DEVMODE,MyMemory,SizeOf(DEVMODE))
       EndIf 
       ResultDLG =PrintDlg_(*pd) 
       
       If Flag=1
        lpDevMode=GlobalLock_(MyMemory)
        If lpDevMode
         Result=CopyMemory(lpDevMode,MyMemory,  SizeOf(DEVMODE))
         Result=CopyMemory(MyMemory,*DevModeCopy.DEVMODE,SizeOf(DEVMODE))
         Result =GlobalunLock_(MyMemory)
        EndIf 
        Result = GlobalFree_(MyMemory)
       Else
        Result=CopyMemory(MyMemory,*DevModeCopy.DEVMODE,SizeOf(DEVMODE))
        FreeMemory(1)
       EndIf
       
       ProcedureReturn ResultDLG
 EndIf
 
EndProcedure

Procedure PageSetupDialog(*PGSDLG.PAGESETUPDLG)
Flag=0
If Flag
 PGSMemory=GlobalAlloc_(#GMEM_MOVEABLE|#GMEM_ZEROINIT, SizeOf(PAGESETUPDLG))
Else
 PGSMemory=AllocateMemory(1,SizeOf(PAGESETUPDLG),0)
EndIf
If PGSMemory
  If flag=1 

   lpDevMode=GlobalLock_(PGSMemory)
   Result=CopyMemory(*PGSDLG.PAGESETUPDLG,PGSMemory,SizeOf(PAGESETUPDLG))    
   Result=CopyMemory(PGSMemory,lpDevMode,SizeOf(PAGESETUPDLG))
   bReturn =GlobalunLock_(PGSMemory)
   
   Result=PageSetupDlg_(PGSMemory)
   
   lpDevMode=GlobalLock_(PGSMemory)
   Result=CopyMemory(lpDevMode,*PGSDLG.PAGESETUPDLG,SizeOf(PAGESETUPDLG))
   bReturn =GlobalunLock_(PGSMemory)
   bReturn = GlobalFree_(PGSMemory)
  Else
   Result=CopyMemory(*PGSDLG.PAGESETUPDLG,PGSMemory,SizeOf(PAGESETUPDLG))    
   Result=PageSetupDlg_(PGSMemory)
   Result=CopyMemory(PGSMemory,*PGSDLG.PAGESETUPDLG,SizeOf(PAGESETUPDLG))    
   FreeMemory(1) 
  EndIf
Else
 MessageRequester("Info","cannot allocate memory",0)
EndIf 
ProcedureReturn Result
EndProcedure
 
hwnd= OpenWindow(0, 10, 10, 100, 200, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget, "PureBasic Window")
If hwnd

 pd.PRINTDLGAPI
 pd\nFromPage = 3 
 pd\nToPage = 5
 pd\nMinPage = 1 
 pd\nMaxPage = 100 
 pd\nCopies = 13
                          ;If you set Flags=#PD_RETURNDEFAULT the Requester i snewer called
 pd\Flags =  0;#PD_RETURNDC |#PD_HIDEPRINTTOFILE |#PD_PAGENUMS| #PD_USEDEVMODECOPIES ;    #PD_ALLPAGES ;#PD_RETURNDC ;| #PD_PRINTSETUP 
 DevModeCopy.DEVMODE
 Result=PrintDialog(hwnd,pd,DevModeCopy)
 If Result
  Info.s="" 
  Info.s=Info.s + "     Copies="+Str(DevModeCopy\dmCopies)+Chr(13)
  Info.s=Info.s + "Orientation="+Str(DevModeCopy\dmOrientation)+Chr(13)
  Info.s=Info.s + "   FromPage="+Str(pd\nFromPage  ) +Chr(13)
  Info.s=Info.s + "     ToPage="+Str(pd\nToPage ) +Chr(13)
  Info.s=Info.s + "    Quality="+Str(DevModeCopy\dmPrintQuality)+Chr(13) 
  Info.s=Info.s + "      Color="+Str(DevModeCopy\dmColor)+Chr(13) 
  MessageRequester("Info",Info,0) 
 Else
  MessageRequester("Info","Aborted",0)
 EndIf 

 PGSDLG.PAGESETUPDLG
 PGSDLG\lStructSize=SizeOf(PAGESETUPDLG)
 PGSDLG\hwndOwner=hwnd
 PGSDLG\hDevMode=0;DevModeCopy
 PGSDLG\rtMargin\left=3000
 PGSDLG\hInstance=0 ;fails -> GetModuleHandle_(0)
 
 PGSDLG\flags=#PSD_MARGINS|#PSD_DISABLEPRINTER 
 Result=PageSetupDialog(PGSDLG)

 Info.s=         "     Result="+Str(Result)+Chr(13)
 Info.s=Info.s + "      Flags="+Str(PGSDLG\flags)+Chr(13)
 Info.s=Info.s + " PapersizeX="+Str(PGSDLG\ptPaperSize\x)+" PapersizeY="+Str(PGSDLG\ptPaperSize\y)+Chr(13)
 Info.s=Info.s + "  MinMargin="+Str(PGSDLG\rtMinMargin\left)+":"+Str(PGSDLG\rtMinMargin\top)+":"+Str(PGSDLG\rtMinMargin\right)+":"+Str(PGSDLG\rtMinMargin\bottom)+Chr(13)
 Info.s=Info.s + "     Margin="+Str(PGSDLG\rtMargin\left)+":"+Str(PGSDLG\rtMargin\top)+":"+Str(PGSDLG\rtMargin\right)+":"+Str(PGSDLG\rtMargin\bottom)+Chr(13)
 MessageRequester("Info",Info,0) 

Its a long way to the top if you wanna .....CodeGuru

Posted: Thu Nov 04, 2004 6:23 pm
by Karbon
Does anyone have a more straight forward way to get the options from a PrintRequester()? This code doesn't directly work in the latest PB because of the memory lib changes but I'd like to get something more simple nailed down if possible!

Posted: Thu Nov 04, 2004 8:55 pm
by Rings
3.92 compatible, removed the 2. memory model

Code: Select all

 
 ; Extended Printer-Dialog and PageSetup Functions
;
;(C) 2002 by Siegfried Rings (-Codeguru-)

;These structures are not needed
; but i leave them to know how the Orignal are typed
;
Structure PRINTDLG_TYPE
    lStructSize.l 
    hwndOwner.l 
    hDevMode.l 
    hDevNames.l 
    hdc.l 
    Flags.l 
    nFromPage.w 
    nToPage.w 
    nMinPage.w 
    nMaxPage.w 
    nCopies.w 
    hInstance.l 
    lCustData.l 
    lpfnPrintHook.l 
    lpfnSetupHook.l 
    lpPrintTemplateName.s 
    lpSetupTemplateName.s 
    hPrintTemplate.l 
    hSetupTemplate.l 
EndStructure
Structure DEVNAMES_TYPE
    wDriverOffset.w 
    wDeviceOffset.w 
    wOutputOffset.w 
    wDefault.w 
    extra.b[100]
EndStructure
Structure DEVMODE_TYPE
    dmDeviceName.b[32]
    dmSpecVersion.w 
    dmDriverVersion.w 
    dmSize.w 
    dmDriverExtra.w 
    dmFields.l 
    dmOrientation.w 
    dmPaperSize.w 
    dmPaperLength.w 
    dmPaperWidth.w 
    dmScale.w 
    dmCopies.w 
    dmDefaultSource.w 
    dmPrintQuality.w 
    dmColor.w 
    dmDuplex.w 
    dmYResolution.w 
    dmTTOption.w 
    dmCollate.w 
    dmFormName.b[32]
    dmUnusedPadding.w 
    dmBitsPerPel.w 
    dmPelsWidth.l 
    dmPelsHeight.l 
    dmDisplayFlags.l 
    dmDisplayFrequency.l 
EndStructure

;These are the constants For the PrinterDialog

    #DM_DUPLEX = $1000
    #DM_ORIENTATION = $1

    #PD_ALLPAGES = $0
    #PD_COLLATE = $10
    #PD_DISABLEPRINTTOFILE = $80000
    #PD_ENABLEPRINTHOOK = $1000
    #PD_ENABLEPRINTTEMPLATE = $4000
    #PD_ENABLEPRINTTEMPLATEHANDLE = $10000
    #PD_ENABLESETUPHOOK = $2000
    #PD_ENABLESETUPTEMPLATE = $8000
    #PD_ENABLESETUPTEMPLATEHANDLE = $20000
    #PD_HIDEPRINTTOFILE = $100000
    #PD_NONETWORKBUTTON = $200000
    #PD_NOPAGENUMS = $8
    #PD_NOSELECTION = $4
    #PD_NOWARNING = $80
    #PD_PAGENUMS = $2
    #PD_PRINTSETUP = $40
    #PD_PRINTTOFILE = $20
    #PD_RETURNDC = $100
    #PD_RETURNDEFAULT = $400
    #PD_RETURNIC = $200
    #PD_SELECTION = $1
    #PD_SHOWHELP = $800
    #PD_USEDEVMODECOPIES = $40000
    #PD_USEDEVMODECOPIESANDCOLLATE = $40000



Structure PAGESETUPDLG
    lStructSize.l
    hwndOwner.l
    hDevMode.l
    hDevNames.l
    flags.l
    ptPaperSize.POINT
    rtMinMargin.RECT
    rtMargin.RECT
    hInstance.l
    lCustData.l
    lpfnPageSetupHook.l
    lpfnPagePaintHook.l
    lpPageSetupTemplateName.s
    hPageSetupTemplate.l
EndStructure
#PSD_DEFAULTMINMARGINS ;Sets the minimum values that the user can specify For the page margins To be the minimum ;margins allowed by the printer. This is the default. This flag is ignored If the #PSD_MARGINS And PSD_MINMARGINS flags are also specified.
#PSD_DISABLEMARGINS ;Disables the margin controls, preventing the user from setting the margins.
#PSD_DISABLEORIENTATION;Disables the orientation controls, preventing the user from setting the page orientation.
#PSD_DISABLEPAGEPAINTING;Prevents the dialog box from drawing the contents of the sample page. If you enable a ;PagePaintHook hook procedure, you can still draw the contents of the sample page.
#PSD_DISABLEPAPER ;Disables the paper controls, preventing the user from setting page parameters such as the ;Mpaper size And source.
#PSD_DISABLEPRINTER;Disables the Printer button, preventing the user from invoking a dialog box that contains ;additional printer setup information.
#PSD_ENABLEPAGEPAINTHOOK ;Enables the hook Procedure specified in the lpfnPagePaintHook member. 
#PSD_ENABLEPAGESETUPHOOK ;Enables the hook Procedure specified in the lpfnPageSetupHook member.
#PSD_ENABLEPAGESETUPTEMPLATE;Indicates that the hInstance And lpPageSetupTemplateName members specify a dialog box ;template To use in place of the Default template.
#PSD_ENABLEPAGESETUPTEMPLATEHANDLE ;Indicates that the hPageSetupTemplate member identifies a Data block that contains a ;preloaded dialog box template. The system ignores the lpPageSetupTemplateName member If ;this flag is specified. 
#PSD_INHUNDREDTHSOFMILLIMETERS ;Indicates that hundredths of millimeters are the unit of measurement For margins And ;paper size. The values in the rtMargin, rtMinMargin, And ptPaperSize members are in ;hundredths of millimeters. You can set this flag on input To override the Default unit of ;measurement For the user's locale. When the function returns, the dialog box sets this ;flag To indicate the units used.
#PSD_INTHOUSANDTHSOFINCHES ;Indicates that thousandths of inches are the unit of measurement For margins And paper ;size. The values in the rtMargin, rtMinMargin, And ptPaperSize members are in thousandths ;of inches. You can set this flag on input To override the Default unit of measurement For ;the user's locale. When the function returns, the dialog box sets this flag To indicate ;the units used.
#PSD_INWININIINTLMEASURE ;Not implemented.
#PSD_MARGINS ;Causes the system To use the values specified in the rtMargin member as the initial widths ;For the left, top, right, And bottom margins. If PSD_MARGINS is Not set, the system sets ;the initial widths To one inch For all margins. 
#PSD_MINMARGINS;Causes the system To use the values specified in the rtMinMargin member as the minimum ;allowable widths For the left, top, right, And bottom margins. The system prevents the ;user from entering a width that is less than the specified minimum. If PSD_MINMARGINS is ;Not specified, the system sets the minimum allowable widths To those allowed by the ;printer. 
#PSD_NOWARNING ;Prevents the system from displaying a warning message when there is no Default printer.
#PSD_RETURNDEFAULT;PageSetupDlg does Not display the 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 ;NULL.
#PSD_SHOWHELP ;Causes the dialog box To display the Help button. The hwndOwner member must specify the ;window To receive the HELPMSGSTRING registered messages that the dialog box sends when ;the user clicks the Help button.


#GMEM_MOVEABLE = $2
#GMEM_ZEROINIT = $40

Procedure PrintDialog(hwnd,*pd.PRINTDLGAPI,*DevModeCopy.DEVMODE)
myDevNames.DEVNAMES
MyMemory=AllocateMemory(SizeOf(DEVMODE))
If MyMemory
       
       *pd.PRINTDLGAPI
       *pd\lStructSize = SizeOf(PRINTDLGAPI) 
       *pd\hWndOwner = hWnd 
       *pd\hDevMode = MyMemory;Devmode;@Devmode;#NULL 
       *pd\hDevNames = #NULL;@DevNames;#NULL 
       *pd\hInstance = 0;GetModuleHandle_(0);hInstance.l 
       *pd\lpfnSetupHook = #NULL 
       *pd\lpPrintSetupTemplateName = #NULL 
       *pd\lpfnPrintHook = #NULL 
       *pd\lpPrintTemplateName = #NULL 

       ;Setting up the special Printermode
       ;*DevmodeCopy\dmSize=SizeOf(DEVMODE)
       ;*DevModeCopy\dmFields = #DM_ORIENTATION | #DM_DUPLEX
       ;MessageRequester("Info",Str(*DevModeCopy\dmCopies),0)
       ;*DevModeCopy\dmCopies =2 
       
       Result=CopyMemory(*DevModeCopy.DEVMODE,MyMemory,SizeOf(DEVMODE))
       ResultDLG =PrintDlg_(*pd) 
       Result=CopyMemory(MyMemory,*DevModeCopy.DEVMODE,SizeOf(DEVMODE))
       FreeMemory(MyMemory)
 
       ProcedureReturn ResultDLG
 EndIf
EndProcedure

Procedure PageSetupDialog(*PGSDLG.PAGESETUPDLG)
PGSMemory=AllocateMemory(SizeOf(PAGESETUPDLG))
If PGSMemory
 Result=CopyMemory(*PGSDLG.PAGESETUPDLG,PGSMemory,SizeOf(PAGESETUPDLG))    
 Result=PageSetupDlg_(PGSMemory)
 Result=CopyMemory(PGSMemory,*PGSDLG.PAGESETUPDLG,SizeOf(PAGESETUPDLG))    
 FreeMemory(PGSMemory) 
Else
 MessageRequester("Info","cannot allocate memory",0)
EndIf 
ProcedureReturn Result
EndProcedure
 
hwnd= OpenWindow(0, 10, 10, 100, 200, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget, "PureBasic Window")
If hwnd
 pd.PRINTDLGAPI
 pd\nFromPage = 3 
 pd\nToPage = 5
 pd\nMinPage = 1 
 pd\nMaxPage = 100 
 pd\nCopies = 13
                          ;If you set Flags=#PD_RETURNDEFAULT the Requester i snewer called
 pd\Flags =  0;#PD_RETURNDC |#PD_HIDEPRINTTOFILE |#PD_PAGENUMS| #PD_USEDEVMODECOPIES ;    #PD_ALLPAGES ;#PD_RETURNDC ;| #PD_PRINTSETUP 
 DevModeCopy.DEVMODE
 Result=PrintDialog(hwnd,pd,DevModeCopy)
 If Result
  Info.s="" 
  Info.s=Info.s + "     Copies="+Str(DevModeCopy\dmCopies)+Chr(13)
  Info.s=Info.s + "Orientation="+Str(DevModeCopy\dmOrientation)+Chr(13)
  Info.s=Info.s + "   FromPage="+Str(pd\nFromPage  ) +Chr(13)
  Info.s=Info.s + "     ToPage="+Str(pd\nToPage ) +Chr(13)
  Info.s=Info.s + "    Quality="+Str(DevModeCopy\dmPrintQuality)+Chr(13) 
  Info.s=Info.s + "      Color="+Str(DevModeCopy\dmColor)+Chr(13) 
  MessageRequester("Info",Info,0) 
 Else
  MessageRequester("Info","Aborted",0)
 EndIf 

 PGSDLG.PAGESETUPDLG
 PGSDLG\lStructSize=SizeOf(PAGESETUPDLG)
 PGSDLG\hwndOwner=hwnd
 PGSDLG\hDevMode=0;DevModeCopy
 PGSDLG\rtMargin\left=3000
 PGSDLG\hInstance=0 ;fails -> GetModuleHandle_(0)
 
 PGSDLG\flags=#PSD_MARGINS|#PSD_DISABLEPRINTER 
 Result=PageSetupDialog(PGSDLG)

 Info.s=         "     Result="+Str(Result)+Chr(13)
 Info.s=Info.s + "      Flags="+Str(PGSDLG\flags)+Chr(13)
 Info.s=Info.s + " PapersizeX="+Str(PGSDLG\ptPaperSize\x)+" PapersizeY="+Str(PGSDLG\ptPaperSize\y)+Chr(13)
 Info.s=Info.s + "  MinMargin="+Str(PGSDLG\rtMinMargin\left)+":"+Str(PGSDLG\rtMinMargin\top)+":"+Str(PGSDLG\rtMinMargin\right)+":"+Str(PGSDLG\rtMinMargin\bottom)+Chr(13)
 Info.s=Info.s + "     Margin="+Str(PGSDLG\rtMargin\left)+":"+Str(PGSDLG\rtMargin\top)+":"+Str(PGSDLG\rtMargin\right)+":"+Str(PGSDLG\rtMargin\bottom)+Chr(13)
 MessageRequester("Info",Info,0) 
EndIf
End

Posted: Thu Nov 04, 2004 9:24 pm
by Karbon
Looks like you can get the printer name that was selected with :

Code: Select all

name$=""
      
      For tmp=0 To 31
        name$+Chr(DevModeCopy\dmDeviceName[tmp])
      Next
      Debug name$
Thanks Paul :-)

Posted: Sun Nov 07, 2004 1:13 am
by Karbon
What contorls the start position of the print dialog window? It seems to start in a rather odd place on different machines!

Posted: Sun Nov 07, 2004 6:54 am
by Sparkie
@Karbon - Not sure if there's a better way, but this code should center the Print Dialog on the screen.

Code: Select all

screenW = GetSystemMetrics_(#SM_CXSCREEN)
screenH = GetSystemMetrics_(#SM_CYSCREEN)
Global screenW, screenH

Procedure myPrintDlgCallback(hdlg, msg, wparan, lparam)
  Select msg
    Case #WM_INITDIALOG 
      GetWindowRect_(hdlg, @dlg.RECT)
      dlgWidth = dlg\right-dlg\left
      dlgHeight = dlg\bottom-dlg\top
      dlgX = (screenW-dlgWidth)/2
      dlgY = (screenH-dlgHeight)/2
      MoveWindow_(hdlg, dlgX, dlgY, dlgWidth, dlgHeight, 1)
  EndSelect
  ProcedureReturn 0
EndProcedure

OpenWindow(0, 0, 0, 200, 250, #PB_Window_SystemMenu,"Print Dialog Centered")
CreateGadgetList(WindowID(0)); or use InitCommonControlsEx()
pDlg.PRINTDLGAPI
pDlg\lStructSize = SizeOf(PRINTDLGAPI)
pDlg\flags = #PD_ENABLEPRINTHOOK
pDlg\hwndOwner = WindowID(0)
pDlg\lpfnPrintHook = @myPrintDlgCallback()
PrintDlg_(pDlg)
Repeat: Until WaitWindowEvent() = #PB_Event_CloseWindow 
End

Posted: Mon Nov 08, 2004 2:40 pm
by Karbon
Sorry Sparkie, forgot to say thanks! I'll try it out today!

Posted: Wed Dec 08, 2004 7:47 pm
by Karbon
Using the code below if I show a print dialog a few times it always crashes. The debugger doesn't catch anything.

Code: Select all

Procedure PrintDialog(hwnd,*pd.PRINTDLGAPI,*DevModeCopy.DEVMODE)
  myDevNames.DEVNAMES
  MyMemory=AllocateMemory(SizeOf(DEVMODE))
  If MyMemory
    
    *pd.PRINTDLGAPI
    *pd\lStructSize = SizeOf(PRINTDLGAPI)
    *pd\hwndOwner = hwnd
    *pd\hDevMode = MyMemory;Devmode;@Devmode;#NULL
    *pd\hDevNames = #Null;@DevNames;#NULL
    *pd\hInstance = 0;GetModuleHandle_(0);hInstance.l
    *pd\lpfnSetupHook = #Null
    *pd\lpPrintSetupTemplateName = #Null
    *pd\lpfnPrintHook = @myPrintDlgCallback()
    *pd\lpPrintTemplateName = #Null
    result=CopyMemory(*DevModeCopy.DEVMODE,MyMemory,SizeOf(DEVMODE))
    ResultDLG =PrintDlg_(*pd)
    result=CopyMemory(MyMemory,*DevModeCopy.DEVMODE,SizeOf(DEVMODE))
    FreeMemory(MyMemory)
    
    ProcedureReturn ResultDLG
  EndIf
EndProcedure
And the callback :

Code: Select all

Procedure myPrintDlgCallback(hdlg, msg, wparan, lParam)
  Select msg
    Case #WM_INITDIALOG
      GetWindowRect_(hdlg, @dlg.RECT)
      dlgWidth = dlg\right-dlg\Left
      dlgHeight = dlg\Bottom-dlg\top
      dlgX = (screenW-dlgWidth)/2
      dlgY = (screenH-dlgHeight)/2
      MoveWindow_(hdlg, dlgX, dlgY, dlgWidth, dlgHeight, 1)
  EndSelect
  ProcedureReturn 0
EndProcedure 
Does the above code not properly free the dialog or something, perhaps?

Posted: Mon Dec 20, 2004 2:05 pm
by Karbon
Still hving trouble with this if anyone has any ideas..

Posted: Mon Dec 20, 2004 3:54 pm
by Rings
Karbon wrote:Still hving trouble with this if anyone has any ideas..
works without problems here :

Code: Select all

  Procedure myPrintDlgCallback(hdlg, msg, wparan, lParam)
  Select msg
    Case #WM_INITDIALOG
      GetWindowRect_(hdlg, @dlg.RECT)
      dlgWidth = dlg\right-dlg\Left
      dlgHeight = dlg\Bottom-dlg\top
      dlgX = (screenW-dlgWidth)/2
      dlgY = (screenH-dlgHeight)/2
      MoveWindow_(hdlg, dlgX, dlgY, dlgWidth, dlgHeight, 1)
  EndSelect
  ProcedureReturn 0
EndProcedure

 Procedure PrintDialog(hwnd,*pd.PRINTDLGAPI,*DevModeCopy.DEVMODE)
  myDevNames.DEVNAMES
  MyMemory=AllocateMemory(SizeOf(DEVMODE))
  If MyMemory
   
    *pd.PRINTDLGAPI
    *pd\lStructSize = SizeOf(PRINTDLGAPI)
    *pd\hwndOwner = hwnd
    *pd\hDevMode = MyMemory;Devmode;@Devmode;#NULL
    *pd\hDevNames = #Null;@DevNames;#NULL
    *pd\hInstance = 0;GetModuleHandle_(0);hInstance.l
    *pd\lpfnSetupHook = #Null
    *pd\lpPrintSetupTemplateName = #Null
    *pd\lpfnPrintHook = @myPrintDlgCallback()
    *pd\lpPrintTemplateName = #Null
    result=CopyMemory(*DevModeCopy.DEVMODE,MyMemory,SizeOf(DEVMODE))
    ResultDLG =PrintDlg_(*pd)
    result=CopyMemory(MyMemory,*DevModeCopy.DEVMODE,SizeOf(DEVMODE))
    FreeMemory(MyMemory)
   
    ProcedureReturn ResultDLG
  EndIf
EndProcedure


 
For I=1 To 20
 printdialog(0,pd.printdlgapi,dv.devmode)
Next I

Posted: Mon Dec 20, 2004 3:58 pm
by Karbon
It doesn't look like you did - but did you change anything from what I posted?

Posted: Mon Dec 20, 2004 4:12 pm
by El_Choni
Karbon, you're missing this:

Code: Select all

*pd\Flags = #PD_ENABLEPRINTHOOK
And make sure screenW and screenH are properly set. Don't know about the crash, though. With these changes, it works ok here.

Posted: Mon Dec 20, 2004 4:41 pm
by Karbon
Looks like I was setting flags instead of Flags, seems to work after that! Thanks Rings!

I wonder why I wasn't getting a "structure member not found" error.. *shrug*

Posted: Fri Mar 11, 2005 1:40 am
by Karbon
How about a method of detecting the "All" radio button? :-)