Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Capture Selections From "To Printer Prompt" 1

Status
Not open for further replies.

Auguy

Programmer
May 1, 2004
1,206
US
Is there any way to capture the selections made in the print dialog called when a user clicks the printer icon when using
Code:
Report Form ReportName To Printer Prompt
I have previously used GetPrinter(), but that always returns an empty string so you do not know the user selected cancel. The problem I have is that I'm printing invoices that require a lot of processing and each invoice is a separate report. Also, there is another report that needs to be printed immediately after each invoice. Using GetPrinter() I only had to invoke it once and the set printer to ... I like the print dialog that is displayed using "To Printer Prompt", but now the user has to respond to the print dialog for each invoice and the following report. I would like to capture the printer name from this dialog the first time the user sees it, but not sure how to get it. Alternately, is there another command or Sys() function that calls that same dialog?

Auguy
Northwest Ohio
 
The best you're going to be able to do is roll your own dialog.

Although, you might be able to chain your reports into a single printjob so the TO PRINTER PROMPT is only on the first REPORT FORM command. Does your version of VFP's help file include NOPAGEEJECT?
 
Thanks Mike for being so diplomatic, I was wrong, it does not always return an empty string. Boy I must be getting old because I don't know how I came up with that conclusion. By the way, did you ever make that trip to Ohio?

Thanks Dan, I have thought about using a print job, but didn't want to change code. Yes this is VFP 9. If I get some time to play, I'll try the print job, maybe it will be easier that I think.

Auguy
Northwest Ohio
 
DO NOT confuse my suggestion with the PRINTJOB/ENDPRINTJOB commands. Those haven't had any relevance since Foxpro/DOS.

Just look up the NOPAGEEJECT clause of REPORT FORM.
 
Auguy,

I agree with Dan about NOPAGEEJECT. It's usually the best way to chain reports. Just be sure that the last report in the chain does not have NOPAGEEJECT, otherwise the print job will not finish.

By the way, did you ever make that trip to Ohio?

Not yet, but it's still possible. I've just got a new chunk of work from that client, so will probably have to get myself over there soon. I assume the snow will be gone by now?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Auguy

This code will give you all the settings of the printer including the Printer Name selecting, that you could use with SET PRINTER afterwards.
This from Bo Durban

Code:
#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: [URL unfurl="true"]http://msdn2.microsoft.com/en-us/library/ms535771.aspx[/URL]
      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



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
Dan, Thanks for the renminder, I will look into the NOPAGEEJECT.

Mike Lewis, Yes the snow is gone, but April in Northern Ohio is always fun. One day 65 and sunny, next day 40 rainy and windy.

Mike Gagnon and Bo Durban. Thanks, this looks like great stuff. I will do some testing and see how I can use it.

Thanks again to everyone.

Auguy
Northwest Ohio
 
Another thought. I will look into using multiple detail bands to print the secondary report that I need after each invoice. The secondary report is what caused this problem in the first place. I've done something like this in the past using PrintWhen, but the multiple detail bands might just be what I need in this case.

Auguy
Northwest Ohio
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top