[Q] Using FFI to call standard Windows dialogs

Jarvis, Robert P. (Contingent) Jarvisb at timken.com
Fri Jun 30 12:29:53 UTC 2000


It looks like you're invoking the PrintDlg function, which takes a pointer
to a PRINTDLG structure as its one parameter, not a window handle.  That may
explain the crash.  The PRINTDLG structure looks like this:

	typedef struct tagPD { 
	  DWORD           lStructSize; 
	  HWND            hwndOwner; 
	  HGLOBAL         hDevMode; 
	  HGLOBAL         hDevNames; 
	  HDC             hDC; 
	  DWORD           Flags; 
	  WORD            nFromPage; 
	  WORD            nToPage; 
	  WORD            nMinPage; 
	  WORD            nMaxPage; 
	  WORD            nCopies; 
	  HINSTANCE       hInstance; 
	  LPARAM          lCustData; 
	  LPPRINTHOOKPROC lpfnPrintHook; 
	  LPSETUPHOOKPROC lpfnSetupHook; 
	  LPCTSTR         lpPrintTemplateName; 
	  LPCTSTR         lpSetupTemplateName; 
	  HGLOBAL         hPrintTemplate; 
	  HGLOBAL         hSetupTemplate; 
	} PRINTDLG, *LPPRINTDLG; 

How one would go about representing this in Squeak is beyond me.  A few of
the members of this structure are handles to other Win32 structures (e.g.
hDevMode is a handle to a DEVMODE structure, hDevNames is a handle to a
DEVNAMES structure, etc), which doubtless will increase the joy and fun of
trying to get your print dialog up on the screen.

As to "...how do I get a document to print..." - well, that's up to your
application.  PrintDlg just puts up the dialog, initialized and customized
as per the structure above (and its substructures, such as DEVMODE and
DEVNAMES), captures the user's input, and modifies the data in these
structures appropriately.  Printing is usually done by obtaining a DC
(device context) on the appropriate printer and drawing away to your heart's
content.  An easy way to do this is to specify PD_RETURNDC in the Flags
element of your PRINTDLG structure, which causes PrintDlg to fill in the hDC
element of the PRINTDLG structure with a handle to an appropriate DC.

Personally, I think printing is one of the most God-awful things an
application ever has to do.  It's messy, error-prone, varies from device to
device and driver version to driver version, and is ecologically unsound to
boot!  <grumble>  Let 'em read it on the screen if they want to know what's
going on, that's what I say...  :-)

Bob Jarvis
Compuware @ Timken

> -----Original Message-----
> From: Norton, Chris [mailto:chrisn at Kronos.com]
> Sent: Thursday, June 29, 2000 10:26 PM
> To: Squeak (E-mail)
> Subject: [Q] Using FFI to call standard Windows dialogs
> 
> 
> Hi Folks.
> 
> I was experimenting with FFI on my Windows NT box and I kept 
> crashing my
> image (virtual memory dumps).  Can anybody help me with this call?
> 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~
> Win32Shell>>
> shellPrintDialog: aHWND
>     "Win32Shell new shellPrintDialog: Win32Window getFocus"
> 
>     <apicall: bool 'PrintDlgA' (Win32Window) module: 'comdlg32.dll'>
>     ^self externalCallFailed
> 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> I'm trying to launch the print dialog.
> 
> Thanks for your thoughts!
> 
> ---==> Chris
> 
> PS>  And my next question is, of course, how do I get a 
> document to print
> once I've got the dialog launching from Squeak (e.g. how do I 
> provide the
> dialog with a document to print?)...
> 





More information about the Squeak-dev mailing list