Tip #11: some Win32 stuff 01 Apr, 2003
Background
As you can see from the "Further reading" section, I've published a few articles on this site that cover Lotusscript versions of Win32 API calls. This kind of stuff can be really useful. For example, you can use the Windows API to:
- get a handle on and change the current machine's registry
- add navigation options to your applications (e.g. pop-up menus)
- change other machine environment options such as printer settings
- browse for folders using a standard OS dialog box
- provide a functional version of
SendKeys
Getting started
There are many more applications for the API, and I would recommend getting hold of something like the AllAPI reference to see what calls are available to you. In dealing with API calls, my current favoured approach is to wrap the Windows functions in standard Lotusscript functions. Yes, it's another layer of abstraction, but there are no real penalties in terms of performance, and it makes things far simpler in the long run.
Many of the functions typically used result in some kind of string: a directory path, a file name, and so on. In these instances, the Windows functions often add a trailing space to the result, which needs to be trimmed to be of any use to you. It's nice to have a standard function to get rid of this, and you'll find one in the attached file.
Adapting code for Lotusscript
Lotusscript is broadly compatible with Visual Basic, and so most functions can be fairly easily tweaked to work from Lotusscript. Read through the Win32 API articles here, and look at code posted either in the Sandbox or the forums at the Lotus Developer Domain to see more examples. Once you've done a couple, I think you'll find it that "translating" the Win32 functions becomes a handy addition to your toolset. Also, bear in mind that you'll need the very simple GetActiveWindow function for just about everything. ;-)
What's attached
So, what am I offering today? The attached Lotusscript source file contains all the declarations, code and functions to do two things. It demonstrates how a standard Win32 call, GetUserProfileDirectory, has been wrapped in Lotusscript, together with a simple function to trim excess white space from the resulting string buffer, as mentioned above. The getUserProfileDir function returns the current user's home directory path (e.g. "c:\documents & settings\%USER%"), which I've found to be a great when dealing with attachments or Notes-based installers. The other function, the one that trims the white space, is called trimBuffer and constitutes a handy addition to one's code "toolbox". Have fun!
Ed Wrenbeck#
Hi Ed.
Actually, you don't need to use an undocumented function like that at all from R5.x onwards. If you want a file browse function, use the NotesUIWorkspace method "OpenFileDialog"
;-)
The reason I still have a Win32 API call for doing this posted is to support those not yet witrh R5, let alone ND6. Also, the Windows code is supported and documented in VB, so it should be more stable!
Ben Poole#(First, please excuse my poor english !)
The OpenFileDialog method has a size limit which prevented me from selecting many files or long "network" file path by truncating the result.
I had to use the WIN32 GetOpenFileName method instead.
And doing so, added filters to please the users !
Great site, by the way !Stéphane TIPREZ#