PreviousNext…

Win32 API Menu Demo

Background

R5 introduced nice cascading action bar buttons. But did you know you can have cascading menu items everywhere courtesy of the Win32 API?

The application

The attached database, in zip format, is a simple demonstration of this functionality. A combination of Win32 API calls are used to provide cascading menus in any Notes client application. See the screenshot below for more of an idea of what this application does:

Win32 pop-up menus screenshot

Note that the example database uses action bar buttons stored in a "placeholder" page to demonstrate the menu items, but they could be triggered by all kinds of click events in the Notes client. The code has also been tinkered with in the R4.x client, so cascading action bars in R4 here we come!

Functions used

All this code makes use of a number of Win32 functions, and these are…

  • GetActiveWindow - the main stay of all Win32 API coding in Notes; you have to have a handle on the calling window for any code.

    Then, for building the menu itself…

    • GetCursorPos
    • CreatePopupMenu
    • AppendMenu
    • TrackPopupMenu

    Clean up…

    • DestroyMenu
    • GetMessage

    Structuring your menus

    The code is the simple bit; by far the most complex issue is structuring your cascading menus. Which option should be greyed-out and when? How many levels could / should a menu go to? All such questions need to be addressed. The database code contains some sample guidelines with regards menu construction.

    The example database is coded so that via a messagebox, it prompts the user with the name of the menu item selected — it does nothing more than that. Effectively this code provide you with a model for generating menus and performing an — albeit crude — system of event handling.

    The rest is up to you!

    Further reading

    Downloads

  • Comments

    1. Excellent piece of code. An good example of extending Notes through the use of Windows itself.

      Question
      I cannot get MF_DISABLED or MF_GRAYED to work with Windows 2000. MF_CHECKED works.

      Now here's the kicker. I copied the code into VB and it works, including MF_DISABLED and MF_GRAYED.

      Any ideas why?
      John Burgman#
    2. Thanks for dropping by! You've reminded me of one of my "to-dos", i.e. sorting out why the greyed-out option doesn't work. I started to investigate this some time back, and was on the verge of re-writing the wrapper to use the latest Win32 menu code, which is quite different (this stuff was done in the days of Win95). I really should re-visit that.

      As to why… hmmm. In the past, when I've had Win32 code that doesn't work in Lotusscript (or even stuff that doesn't work between versions of Notes — see my GetOpenFilename article), it's usually down to dodgy structures or buffers. That may be one place to look. To be honest, I hadn't even tried this code directly in VB, so had no idea that those additional options worked there!Ben Poole#
    3. If you discover something, Ben, drop me a line. Due to problems with getting stuff to work directly within Notes, I used Visual Basic to create an ActiveX EXE which I call from Notes with

      CreateObject("VB2Notes.Application")

      This allows me to do various things like running ADO queries, using Excel, etc. working with the VB app space which directly in Notes caused memory leaks, BRBs, etc. Now I can safely do all that with little or no problems. And all this while still using Notes version 4.67a.

      Move to version 6? I'm working on it but for the moment I have pretty much everything needed to keep my company's business moving along just fine.
      John Burgman#
    4. how can i get the script in the lss file including in a domino database!
      and i have not the lss file!punk#
    5. Chris,

      I like the Win32 API popup menu but…

      Disabled and Greyed do not seem to work. I have copied and pasted the code into Visual Basic and these 2 options work so I'm back guessing that somehow, since the menu must be related to the active window, the Notes window is not allowing the popup menu to correctly use those 2 options.

      FYI: I am using Notes version 4.6.7a

      Any idea why?John Burgman#
    6. Has anyone found why the MF_GRAYED param doesn't work when calling this API in Lotus Notes ?David#

    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
    win32menu.zip