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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Canceling printing 2

Status
Not open for further replies.

michel392

Programmer
Dec 17, 2001
54
BR
I put the SET DEVICE TO PRINTER PROMPT command in a program in order to choose the printer, number of copies, etc I want when printing a report. It works well if I choose these options but if I click on the CANCEL button, the printing occurs instead of cancelling the printing. I would like the CANCEL button in the Printer Setup Dialog Box to be effective.

The GETPRINTER() function works fine but it doesn't give the options of which pages I want to print, number of copies, etc. GETPRINTER() shows only a small windows which allows to change just the printer name !

I tried to use PRINTSTATUS(), SYS(13), PRTINFO() functions after the SET DEVICE TO PRINTER PROMPT command in the program, but I failed to get a result.

Michel
 
What you are basically saying is that the Microsoft PRINT routine does not work. Right ?

You may wish to re-examine that.

I just tried what you described (VFP 7) and it worked fine.



Don


 
Whoops ! My apologies.

I just noticed you said ... SET DEVICE TO printer prompt.

I thought it was REPORT FORM to printer prompt.


I have no comment on SET DEVICE TO other than to wonder why you would still be using @SAY commands at this late date in the world of Visual Foxpro.



Don


 
Don,

I use Visual FoxPro programatically, because certain reports is easier to create in this way. Others reports I think is very difficult to generate using the REPORT FORM.

So, I still need help about how to make the CANCEL button to be effective in the SET DEVICE TO PRINTER PROMPT command
(I use Visual FoxPro 6.0).

Thanks anyway for the advice about using REPORT FORM.

Michel

 
Michel,

If you want to give the choice of portrait vs landscape, paper source or paper size, try SYS(1037).

To give the choice of number of copies ... you will have to write your own printer dialogue. Get the required number from the user, and loop round your prining code that number of times.

Alternatively, use PRINTJOB / ENDPRINTJOB in conjunction with the _PCOPIES system variable.

MIke



Mike Lewis
Edinburgh, Scotland
 
You could use PrintDlg API call...this function will return 0 if the user clicks cancel. I think it is the same API that VFP is using when you issue SET DEVICE TO PRINTER PROMPT, though VFP doesn't provide a way to get the return value back as you have pointed out. If the user doesn't click cancel you will then have a device context for further operations. It is gonna be some work creating the PRINTDLG structure and such, but sure beats not having a way for the user to cancel printing. Also, with PrintDlg function you can rest assured that the dialog will come up everytime.

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
Hi

I am sure, there will be some way to tray the Cancel button pressed. The problem is, I dont remember now, how that was done and if that was in VFp.

But a quick suggestion..

LOCAL lcPrinter
lcPrinter = ''
lcPrinter = GETPRINTER()
IF lcPrinter = ''
** Printer not chosen and cancelled
ELSE
** do your printing
ENDIF

*** If you want to provide as an option.. may be..
*****************************************************
DEFINE POPUP SetReport SHORTCUT RELATIVE ;
FROM MROW(),MCOL() ;
STYLE "BOLDITALIC" FONT "Arial",12 COLOR SCHEME 2 ;
TITLE "Report Options" MARGIN

DEFINE BAR 1 OF SetReport PROMPT &quot;Set Printer \<Options&quot;
DEFINE BAR 2 OF SetReport PROMPT &quot;How \<Many Copies?&quot;
DEFINE BAR 3 OF SetReport PROMPT &quot;\<Canecl Printing&quot;
DEFINE BAR 4 OF SetReport PROMPT &quot;Send Report to \<Printer&quot;
ON SELECTION POPUP SetReport DEACTIVATE POPUP
*****************************************************
DO WHILE .T.
ACTIVATE POPUP SetReport
IF BAR() = 1
SYS(1037)
ENDIF
IF BAR() = 2
LOCAL nCopies
nCopies = ''
nCopies = VAL(INPUTBOX(&quot;Specify Number of Copies ?&quot;,&quot;&quot;,&quot;1&quot;))
IF nCopies < 1
=MESSAGEBOX(&quot;Specify Number of Copies as number&quot;,0+16,&quot;Error&quot;)
KEYBOARD '{M}'
ENDIF
_pCopies = nCopies
ENDIF
IF BAR() = 3
SET DEVICE TO SCREEN
EXIT
ENDIF
IF BAR() = 4
** SET DEVICE ... without Prompt
** DO PRINTING JOB
** Set device to screen
EXIT
ENDIF
ENDDO
********************************************

I provided the loop since you are using text based codes.


ramani :)
(Subramanian.G)
 
Hi sorry for an error in above. You can use this code..

*****************************************************
DEFINE POPUP SetReport SHORTCUT RELATIVE ;
FROM MROW(),MCOL() ;
TITLE &quot;Report Options&quot; MARGIN

DEFINE BAR 1 OF SetReport PROMPT &quot;Set Printer \<Options&quot;
DEFINE BAR 2 OF SetReport PROMPT &quot;How \<Many Copies?&quot;
DEFINE BAR 3 OF SetReport PROMPT &quot;\<Canecl Printing&quot;
DEFINE BAR 4 OF SetReport PROMPT &quot;Send Report to \<Printer&quot;
ON SELECTION POPUP SetReport DEACTIVATE POPUP
*****************************************************
DO WHILE .T.
ACTIVATE POPUP SetReport
IF BAR() = 1
SYS(1037)
ENDIF
IF BAR() = 2
LOCAL nCopies
nCopies = ''
nCopies = VAL(INPUTBOX(&quot;Specify Number of Copies ?&quot;,&quot;&quot;,&quot;1&quot;))
IF ! nCopies => 1
=MESSAGEBOX(&quot;Specify Number of Copies as number&quot;,0+16,&quot;Error&quot;)
KEYBOARD '{M}'
nCopies = 1
ELSE
nCopies = 1
ENDIF
_pCopies = nCopies
ENDIF
IF BAR() = 3
SET DEVICE TO SCREEN
EXIT
ENDIF
IF BAR() = 4
** DO PRINTING JOB
EXIT
ENDIF
ENDDO
********************************************


ramani :)
(Subramanian.G)
 
ramani,

That's a pretty neat little piece of code. Star worthy.

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
Yes, as Slighthaze said above, ramani's code is a neat piece of program.
But I would like to use the same Print Dialog used in most Windows application (the same common printer dialog box used when we send a WordPerfect file to printer).
If the Cancel button is not effective after clicking on it (in the SET DEVICE TO PRINTER PROMPT command) or there is no function to detect it, I think there is a bug on VFP 6.
Thank you all for your help.
Michel
 
michel392,

Well perhaps not the functionality you were hoping for, but not a bug. I would like to say again that using the PrintDlg API function will allow you to have the dialog you are looking for and detect whether cancel was clicked by the user. It seems to me to be the only truly workable solution given your requirements.

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
Slighthaze, you suggestion is correct. I have the copy of Mike Gagnons code, but dont have the thread reference.
That is a nice piece of code from Mike Gagnon, I am reproducing below.

SET DEVICE TO PRINTER PROMPT can be avoided. Instead use the routine exactly except incorporating the
SET DEVICE TO PRINTER or SET DEVICE TO SCREEN and carry on with further code to print or exit from the routines.

*****************************************
Do setPrinterPrompt

#Define PD_ALLPAGES 0
#Define PD_RETURNDC 256
#Define PD_USEDEVMODECOPIESANDCOLLATE 262144 && 0x40000
#Define PD_RETURNDEFAULT 1024 && 0x400

Local lcStruct, hDc, lnFlags
lnFlags = PD_USEDEVMODECOPIESANDCOLLATE + PD_RETURNDC
lcStruct = num2dword(66) +;
num2dword(0) +;
num2dword(0) +;
num2dword(0) +;
num2dword(0) +;
num2dword(lnFlags) +;
num2word(65535) +;
num2word(65535) +;
num2word(1) +;
num2word(65535) +;
num2word(1) +;
num2dword(0) +;
num2dword(0) +;
num2dword(0) +;
num2dword(0) +;
num2dword(0) +;
num2dword(0) +;
num2dword(0) +;
num2dword(0) +;
num2dword(0)
If PrintDlg (@lcStruct) <> 0
hDc = buf2dword (Substr (lcStruct, 17, 4))
= DeleteDC (hDc)

Messagebox(&quot;The user chose the print button&quot;)

Else

Messagebox(&quot;The user chose the cancel button.&quot;)

Endif

Function num2dword (lnValue)
#Define m0 256
#Define m1 65536
#Define m2 16777216
Local b0, b1, b2, b3
b3 = Int(lnValue/m2)
b2 = Int((lnValue - b3 * m2)/m1)
b1 = Int((lnValue - b3*m2 - b2*m1)/m0)
b0 = Mod(lnValue, m0)
Return Chr(b0)+Chr(b1)+Chr(b2)+Chr(b3)

Function num2word (lnValue)
Return Chr(Mod(m.lnValue,256)) + Chr(Int(m.lnValue/256))

Function buf2dword (lcBuffer)
Return Asc(Substr(lcBuffer, 1,1)) + ;
Asc(Substr(lcBuffer, 2,1)) * 256 +;
Asc(Substr(lcBuffer, 3,1)) * 65536 +;
Asc(Substr(lcBuffer, 4,1)) * 16777216

Procedure SetPrinterPrompt
Declare Integer DeleteDC In gdi32 Integer hdc
Declare Integer PrintDlg In comdlg32;
STRING @ lppd
***********************************************
Credit to Mike Gagnon.. and may be he was having tight time that he did not respond to this thread.

:)


ramani :)
(Subramanian.G)
 

I am going to try the Mike Gagnons code provided above.
Slighthaze said above that PrintDlg API function will allow me to have the dialog I am &quot;looking for and detect whether cancel was clicked by the user&quot;.
Which commands will I have to issue to activate this PrintDlg API ?
Thank you all.
Michel
 
Michel,

Gagnon's code shows how to use the PrintDlg() API call.

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 

Thanks for all, the routine from Mike Gagnon, provided by Ramani, worked fine.

I think there should be a printer variable which changes its value if we click on OK or on Cancel button (CancelPrint=&quot;.T. or CancelPrint=&quot;.F., for example).

Then after the command SET DEVICE TO PRINTER PROMPT I could use a command like:
IF CancelPrint=&quot;.F.&quot;
CLOSE DATA
RETURN
ENDIF

Is there such printer state variable in Visual FoxPro ?

Michel


 
The routine from Mike Gagnon, provided by Ramani, worked fine, except it does not work when I choose a network printer in the printer dialog window !

Michel


 
I am also using Vfp6 and 7
In Visual FoxPro 8.0, this enhancement has been added.

Calling the SYS(2040) function returns.
one = report is being previewed
two = the report is printing
zero = no report is being previewed or printed

Microsoft has always kept me employed by having me create workarounds for features they put in the next version.
 
Justamistere:

I'm using VPF 6.0 yet, but I tested the SYS(2040) function, but I have no result.

Tkanks anyway,

Michel
 
After many tests, and help from you, I had the Cancel problem solved:

PrintWhich = &quot;&quot;
PrintWhich = GETPRINTER( ) && Displays the Windows Printer Dialog
IF(EMPTY(PrintWhich))
DEACTIVATE WINDOW MyProgram
RETURN
ENDIF

SET PRINTER TO NAME (PrintWhich) && Prints to the desired printer !

SET CONSOLE OFF
SET DEVICE TO PRINT

Thank you all.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top