PreviousNext…

Tip #11: some Win32 stuff

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!

Further reading

Downloads

Comments

  1. You don't need to go all the way out to the Win32 API to find a file browse function. There is one closer to home in the notes API that I use all of the time. Plus, its pretty easy to deal with. I just tested it in 6.0.1 to make sure it was still there. Here is some sample code:
    
    Declare Function NEMGetFile Lib "nnotesws"(wUnk As Integer,_
    Byval szFileName As String, Byval szFilter As String,_
    Byval szTitle As String) As Integer
    
    
    Dim szFileName As String*256
    Dim theTitle As String
    
    Dim theFilter As String
    Dim ws As New notesuiworkspace
    Dim ui As notesuidocument
    
    Set ui = ws.currentdocument
    szFilename = Chr(0)
    
    theTitle = "Pick a File"
    
    theFilter = "All Files |*.*|"
    
    
    If NEMGetFile(0, szFileName, szFilter, szTitle) <> 0 Then
       
    Call ui.FieldSetText("theFileName", szFileName)
    End If
    Ed Wrenbeck#
  2. 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#
  3. You are correct, which now has me scratching my head as to why I looked for this solution to begin with. There must have been some reason or limitation with the OpenFileDialog method, but its beyond me at this point.Ed Wrenbeck#
  4. Well, if memory serves, you can't "tweak" the various properties (filters and so forth) of the NotesUIWorkspace dialog box as well as the native Windows one… but I could be wrong.Ben Poole#
  5. Hi,

    (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#

Comments on this post are now closed.

About

I’m a software architect / developer / general IT wrangler specialising in web, mobile web and middleware using things like node.js, Java, C#, PHP, HTML5 and more.

Best described as a simpleton, but kindly. You can read more here.

";
File Attachment Icon
getUserProfileDir.lss