Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getprinter() vs. report form printer prompt
Message
General information
Forum:
Visual FoxPro
Category:
Reports & Report designer
Miscellaneous
Thread ID:
01685257
Message ID:
01685260
Views:
77
Likes (3)
>Ok, we're not using ReportBehavior 90 aka the ReportListener.
>
>I need to let the user select a printer to print, say, labels to. And they want the fancy rich printer dialog that allows setting the number of copies and things like that. So, for that you'd use something like "report form myreport to printer prompt". In that command the printer dialog is a rich dialog that allows setting number of copies.
>
>But, the problem is we need to get the name of the printer for auditing purposes.
>
>So, then you got the old getprinter() where the user can select the name of the printer followed by a "set printer to". Ok, but the user cannot specify number of copies and other settings.
>
>Question: How can we have our cake and eat it to by letting the user pick a printer and set their fancy settings and we get the name of the printer?
>
>I've looked at some VBA examples and Windows C examples and really don't want to go down the C avenue. I couldn't get this one VBA to work.
>
>Help!
#Define SIZEOF_PRINTDLGEX     84
#Define SIZEOF_PRINTPAGERANGE  8
** nFlag options
#Define PD_ALLPAGES                  0x00000000
#Define PD_SELECTION                 0x00000001
#Define PD_PAGENUMS                  0x00000002
#Define PD_NOSELECTION               0x00000004
#Define PD_NOPAGENUMS                0x00000008
#Define PD_COLLATE                   0x00000010
#Define PD_PRINTTOFILE               0x00000020
#Define PD_PRINTSETUP                0x00000040
#Define PD_NOWARNING                 0x00000080
#Define PD_RETURNDC                  0x00000100
#Define PD_RETURNIC                  0x00000200
#Define PD_RETURNDEFAULT             0x00000400
#Define PD_SHOWHELP                  0x00000800
#Define PD_USEDEVMODECOPIES          0x00040000
#Define PD_USEDEVMODECOPIESANDCOLLATE 0x00040000
#Define PD_DISABLEPRINTTOFILE        0x00080000
#Define PD_HIDEPRINTTOFILE           0x00100000
#Define PD_NONETWORKBUTTON           0x00200000
#Define PD_CURRENTPAGE               0x00400000
#Define PD_NOCURRENTPAGE             0x00800000
#Define START_PAGE_GENERAL    Bitlshift(0xffffffff,0)
#Define GMEM_FIXED       0x00
#Define GMEM_ZEROINIT    0x40
#Define GPTR             (GMEM_FIXED+GMEM_ZEROINIT)
#Define DM_OUT_BUFFER  2
#Define DM_IN_PROMPT   4
#Define CCHDEVICENAME 32
#Define CCHFORMNAME   32
#Define PD_RESULT_CANCEL               0
#Define PD_RESULT_PRINT                1
#Define PD_RESULT_APPLY                2

 

Declare Long GlobalAlloc In WIN32API Long uFlags, Long uBytes
Declare Long GlobalLock In WIN32API Long Hmem
Declare Long GlobalUnlock In WIN32API Long Hmem
Declare Long GlobalFree In WIN32API Long Hmem
Declare Integer PrintDlg In comdlg32.Dll Long lppd
Declare Integer PrintDlgEx In comdlg32.Dll Long lppd
Declare Long DeleteDC In WIN32API Long hdc

 

Local hPRINTDLG, hPageRanges, hdc, hResult, nFlagsm, hResult
Local hGDevMode, hGDevNames, nPageRange, hPageRange, lnAction
Local lcDeviceName, lcFormName, hDevMode, hDevNames

** Allocate memory for the PRINTDLGEX structure

hPRINTDLG = GlobalAlloc(GPTR,SIZEOF_PRINTDLGEX)
** Allocate memory for 10x PRINTPAGERANGE structures
hPageRanges = GlobalAlloc(GPTR,SIZEOF_PRINTPAGERANGE*10)
hdc = 0
hResult = 0
** Initialize the PRINTPAGERANGE structure
nFlags = Bitor(PD_RETURNDC,PD_ALLPAGES)
Sys(2600,hPageRanges,8,BinToC(1,"4rs")+BinToC(1,"4rs"))
** Initialize the PRINTDLGEX structure
Sys(2600,hPRINTDLG+ 0,4,BinToC(SIZEOF_PRINTDLGEX,"4rs")) && lStructSize
Sys(2600,hPRINTDLG+ 4,4,BinToC(_vfp.HWnd,"4rs"))         && hwndOwner
Sys(2600,hPRINTDLG+20,4,BinToC(nFlags,"4rs"))            && Flags
Sys(2600,hPRINTDLG+32,4,BinToC(0,"4rs"))                 && nPageRanges
Sys(2600,hPRINTDLG+36,4,BinToC(10,"4rs"))                && nMaxPageRanges
Sys(2600,hPRINTDLG+40,4,BinToC(hPageRanges,"4rs"))       && lpPageRanges
Sys(2600,hPRINTDLG+44,4,BinToC(1,"4rs"))                 && nMinPage
Sys(2600,hPRINTDLG+48,4,BinToC(1000,"4rs"))              && nMaxPage
Sys(2600,hPRINTDLG+52,4,BinToC(1,"4rs"))                 && nCopies
Sys(2600,hPRINTDLG+76,4,BinToC(START_PAGE_GENERAL,"4rs")) && nStartPage

** Display the Print dialog
hResult = PrintDlgEx(hPRINTDLG)
** Pull updated values from PRINTDLGEX structure
hGDevMode = CToBin(Sys(2600,hPRINTDLG+8,4),"4rs")
hGDevNames = CToBin(Sys(2600,hPRINTDLG+12,4),"4rs")
hdc = CToBin(Sys(2600,hPRINTDLG+16,4),"4rs")
nFlags = CToBin(Sys(2600,hPRINTDLG+20,4),"4rs")
lnAction = CToBin(Sys(2600,hPRINTDLG+80,4),"4rs")
If hResult = 0
** Lock movable memory
   hDevMode = GlobalLock(hGDevMode)
   hDevNames = GlobalLock(hGDevNames)
** Display Action taken by user
   Do Case
      Case lnAction = PD_RESULT_CANCEL
         ?"Action: CANCEL"
      Case lnAction = PD_RESULT_PRINT
         ?"Action: PRINT"
      Case lnAction = PD_RESULT_APPLY
         ?"Action: APPLY"
   Endcase

 

** Display print range selection
   Do Case
      Case lnAction != PD_RESULT_PRINT
** No Printing
      Case Bitand(nFlags,PD_SELECTION)=PD_SELECTION
         ?" Selection"
      Case Bitand(nFlags,PD_CURRENTPAGE)=PD_CURRENTPAGE
         ?" Current Page"
      Case Bitand(nFlags,PD_PAGENUMS)=PD_PAGENUMS
         ?" Page Ranges"
         nPageRanges = CToBin(Sys(2600,hPRINTDLG+32,4),"4rs")
         For nPageRange = 0 To nPageRanges-1
            hPageRange = hPageRanges+(nPageRange*SIZEOF_PRINTPAGERANGE)
            nFrom = CToBin(Sys(2600,hPageRange,4),"4rs")
            nTo = CToBin(Sys(2600,hPageRange+4,4),"4rs")
            ?"   From: "+Transform(nFrom)+" To: "+Transform(nTo)
         Endfor
      Otherwise
         ?" All Pages"
   Endcase

 

 

** Display the DEVMODE structure, showing printing preferences

   If hDevMode <> 0
      ?"DEVMODE:"
** DEVMODE: http://msdn2.microsoft.com/en-us/library/ms535771.aspx
      lcDeviceName = Sys(2600,hDevMode+0,CCHDEVICENAME)
      lcDeviceName = " "+Left(lcDeviceName, At(0h00,lcDeviceName)-1)
      ?" Device Name: ",   lcDeviceName
      ?" Orientation: ",   CToBin(Sys(2600,hDevMode+44,2),"2rs")
      ?" Paper Size: ",    CToBin(Sys(2600,hDevMode+46,2),"2rs")
      ?" Paper Length: ",  CToBin(Sys(2600,hDevMode+48,2),"2rs")
      ?" Paper Width: ",   CToBin(Sys(2600,hDevMode+50,2),"2rs")
      ?" Paper Scale: ",   CToBin(Sys(2600,hDevMode+52,2),"2rs")
      ?" Paper Copies: ",  CToBin(Sys(2600,hDevMode+54,2),"2rs")
      ?" Default Source: ",CToBin(Sys(2600,hDevMode+56,2),"2rs")
      ?" Print Qualilty: ",CToBin(Sys(2600,hDevMode+58,2),"2rs")
      ?" Color: ",         CToBin(Sys(2600,hDevMode+60,2),"2rs")
      ?" Duplex: ",        CToBin(Sys(2600,hDevMode+62,2),"2rs")
      ?" Y Resolution: ",  CToBin(Sys(2600,hDevMode+64,2),"2rs")
      ?" TT Option: ",     CToBin(Sys(2600,hDevMode+66,2),"2rs")
      ?" Collate: ",       CToBin(Sys(2600,hDevMode+68,2),"2rs")
      lcFormName = Sys(2600,hDevMode+70,CCHFORMNAME)
      lcFormName = " "+Left(lcFormName, At(0h00,lcFormName)-1)
      ?" Form Name: ",      lcFormName
      ?" LogPixels: ",      CToBin(Sys(2600,hDevMode+102,2),"2rs")
      ?" BitsPerPixel: ",   CToBin(Sys(2600,hDevMode+104,2),"2rs")
      ?
   Endif

** Unlock movable memory
   GlobalUnlock(hGDevMode)
   GlobalUnlock(hGDevNames)
Else
   ?"ERROR: "+Transform(hResult,"@0")
Endif
** Clean up allocated memory
If hGDevMode <> 0
   GlobalFree(hGDevMode)
Endif
If hGDevNames <> 0
   GlobalFree(hGDevNames)
Endif
GlobalFree(hPageRanges)
GlobalFree(hPRINTDLG)
If hdc <> 0
   DeleteDC(hdc)
Endif
Return
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform