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

How to determine Cancel was used with the printer prompt

API Functions

How to determine Cancel was used with the printer prompt

by  Mike Gagnon  Posted    (Edited  )
This function is similar to the SYS(1037) function, but it allows you to catch the lcStruct value that determines if the user used the Cancel button or the Print button:
Code:
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("The user chose the print button")
Else
	Messagebox("The user chose the cancel button.")
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

Some of this code came from Anatoliy Mogylevets

Mike Gagnon
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top