Information générale
Catégorie:
Fonctions Windows API
Titre:
Using PrintDlg to return hDC
I have a rather tricky problem and wonder if anyone can suggest a solution.
Below is some straightforward code to display the Windows Printer Dialog
and return an hDC for the selected device and settings. This works fine,
returning a LONG that can be used to send output to the printer. The trouble
is that the LONG is unsigned and in Windows 2000/XP can exceed the magic
figure of 2147483647. The application I'm sending output to is a 32bit ActiveX (OCX) and does not like numbers in excess of this - it returns an OLE error message "Out of Current Range". I've taken this up with the vendors of the ActiveX application and they do not appear to understand my problem, saying "why not set the PrintDlg parameters to return a signed LONG?". I have no idea whether this is possible in VFP, or how.
Any ideas anyone?
Awaiting in hopeful anticipation.
Mike Rothery
Here is my code....
FUNCTION GethDC
declare integer PrintDlg in comdlg32.dll string @
cPD = ""
cPD = cPD + chr(66) + chr(0) + chr(0) + chr(0) && lStructSize
cPD = cPD + chr(0) + chr(0) + chr(0) + chr(0) && hwndOwner
cPD = cPD + chr(0) + chr(0) + chr(0) + chr(0) && hDevMode
cPD = cPD + chr(0) + chr(0) + chr(0) + chr(0) && hDevNames
cPD = cPD + chr(0) + chr(0) + chr(0) + chr(0) && hDC
cPD = cPD + chr(4 + 8) + chr(1) + chr(0) + chr(0) && Flags (see commdlg.h)
cPD = cPD + chr(1) + chr(0) && nFromPage
cPD = cPD + chr(1) + chr(0) && nToPage
cPD = cPD + chr(0) + chr(0) && nMinPage
cPD = cPD + chr(0) + chr(0) && nMaxPage
cPD = cPD + chr(1) + chr(0) && nCopies
cPD = cPD + chr(0) + chr(0) + chr(0) + chr(0) && hInstance
cPD = cPD + chr(0) + chr(0) + chr(0) + chr(0) && lCustData
cPD = cPD + chr(0) + chr(0) + chr(0) + chr(0) && lpfnPrintHook
cPD = cPD + chr(0) + chr(0) + chr(0) + chr(0) && lpfnSetupHook
cPD = cPD + chr(0) + chr(0) + chr(0) + chr(0) && lpPrintTemplateName
cPD = cPD + chr(0) + chr(0) + chr(0) + chr(0) && lpSetupTemplateName
cPD = cPD + chr(0) + chr(0) + chr(0) + chr(0) && PrintTemplate
cPD = cPD + chr(0) + chr(0) + chr(0) + chr(0) && SetupTemplate
if PrintDlg(@cPD) = 0
return .F.
endif
nHDC = DWORDToNum(substr(cPD, 17, 4))
if nHDC = 0
return .F.
endif
FUNCTION DWORDToNum
PARAMETERS tcWord
LOCAL i, lnWord
*-- Ensure word is 4 bytes, 0-filled to right
tcWord = PADR(tcWord, 4, CHR(0))
*-- First byte is least significant
lnWord = 0
FOR i = 1 TO 4
lnWord = lnWord + (ASC(SUBSTR(tcWord, i, 1)) * (2 ^ (8 * (i - 1))))
ENDFOR
RETURN lnWord
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement