[Q] Using FFI to call standard Windows dialogs

Torsten.Bergmann at phaidros.com Torsten.Bergmann at phaidros.com
Fri Jun 30 09:02:12 UTC 2000


Ohhh no - you try to call the API with a window handle as a parameter, 
but the the API is defined like the following:

	BOOL PrintDlg(
	  LPPRINTDLG lppd   // initialization data
	);

So you have to call it with the address of a PRINTDLG structure.
This structure contains informations used to initialize the dialog box
(including the handle to the owner window).

See
http://www.msdn.microsoft.com/library/default.asp?URL=/library/psdk/winui/co
mmdlg3_7xwy.htm

How to do it in Squeak: 
 - create a new subclass Win32PRINTDLG of ExternalStructure
 - implement the class method #fields to define the fields of the struct
like:
 Win32PRINTDLG(class)>>fields
	   "Win32PRINTDLG defineFields"
	   ^#( #(#lStructSize 'long')
		 #(#hwndOwner   'long')  
		 ...
	    )  
   see
http://www.msdn.microsoft.com/library/default.asp?URL=/library/psdk/winui/co
mmdlg3_7xwy.htm	
   for the structure definition (note that any structure member is a long (4
bytes), except nFromPage, nToPage, 
   nMinPage, nMaxPage, nCopies (only two bytes)
 - evaluate "Win32PRINTDLG defineFields" to create accessor methods on the
instance side
 - create an API call method
	shellPrintDialog: aWin32PRINTDLG
	    "Displays a print dialog box"
	    <apicall: bool 'PrintDlgA' (Win32PRINTDLG*) module:
'comdlg32.dll'>
	    ^self externalCallFailed
	
This should work. If the API call goes wrong it returns FALSE (= 0).

I personally dont like the way Squeak calls API functions. In Smalltalk MT
you only write:
	WINAPI PrintDlg: PRINTDLG new

That's a little bit easier ;)

Hope this helps
Torsten

BTW: It's interesting that you mail address is Kronos.com - my nickname is
Cronos

-----Original Message-----
From: Norton, Chris [mailto:chrisn at Kronos.com]
Sent: Freitag, 30. Juni 2000 04:26
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