Click here to Skip to main content
Licence CPOL
First Posted 9 May 2003
Views 127,591
Bookmarked 25 times

Addin Menus in Lotus Notes using MFC/NotesAPI

By | 9 May 2003 | Article
Creating Add-in Menus in Lotus Notes using Lotus C APIs and MFC.

Introduction

This is a simple dll program that is used to add menus in Lotus Notes Action Menu using Lotus Notes C API 4.6.2.

Using the code

Menu Add-in funtions in NotesAPI allow you to customize the Notes Actions menu, so that users can run your API programs by selecting one of the menu items added. This will take you through a step by step procedure on how to create a Notes AddinMenu dll.

Step 1: Create New Workspace

Run the VC New Projects wizard. Select MFC AppWizard(dll) and specify a project name as MenuAddin (for eg.). Cick on OK to proceed to the other dialogs and check the Regular Dll with MFC statically linked option in the wizard.

Step 2: Workspace Settings

1. Go to Project Settings (ALT+F7). In the C/C++ tab in preprocessor definitions, add 'NT' or 'W32' at the end of the preprocessor list. 2. In the Link tab. In General, in Output file name, specify [NOTESPATH]\MenuAddin.dll. [NOTESPATH] is the path in which Notes executable resides your system. For eg. it would be Drive:\Lotus\Notes. 3. For Object/Library modules, enter notes.lib in the field. 4. Go to Tools->Options Menu. In the Directories Tab, select Include files and specify the path of the Notes API Include Directory. For eg. in my case it was D:\Notes C API 4.6\INCLUDE. 5. Select Library files and specify the path for the Lib files for your OS. For eg. in my case it was D:\Notes C API 4.6\LIB\MSWIN32.

Step 3: Coding

Ok now we got the whole environment setup. Lets begin the coding part of it. There are 2 header files that need to be included for this dll to compile.

#include <global.h>
#include <addinmen.h> 
global.h contains the global information and addinmen.h contains the structures you need for creating a add-in menu dll. The Dll Class is now void of any entry point methods. NotesAddinMenu dlls must must have this as the entry point:

extern "C" NAMRESULT LNCALLBACK ActionsMenuProc(WORD wMsg, PVOID pParam)

wMsg indicates an addin menu operation and pParam will contain specific information, depending on the value of wMsg.

There are 4 possible messages that are sent from the Notes Workstation to the DLL. These messages are defined in addinmen.h. They are NAMM_INIT,NAMM_INITMENU,NAMM_COMMAND and NAMM_TERM. Complete reference on these message types will be available in the Notes API Reference. The Complete code for the ActionMenuProc will be as follows:

WORD gwStartingID;

extern "C" NAMRESULT LNCALLBACK ActionsMenuProc(WORD wMsg, PVOID pParam)
{ 
    // This function is called three times. 
    // 1. to init/to get the menu item name.
    // 2. to enable/disable menu based on the context
    //    like view,doc,workspace
    // 3. to do the actual command work.
    switch (wMsg)
    {
    case NAMM_INIT:
        // Set up the new addin menu items
        {
            NAM_INIT_INFO*  pInitInfo;
            pInitInfo = (NAM_INIT_INFO *) pParam;

            // Save the starting ID of the First item appended to menu
            if (pInitInfo->wMenuItemNumber == 0)
                /* first time through */
                gwStartingID = pInitInfo->wStartingID;

            // Give Notes our menu id 
            pInitInfo->wMenuID = IDS_MENU_NAME;

            // Give Notes our menu item name
            CString strAppName;
            strAppName.LoadString(IDS_MENU_NAME);          
            _tcscpy(pInitInfo->MenuItemName, (LPCSTR)strAppName);
            return (NAM_INIT_STOP);
        }
    case NAMM_INITMENU:
        // Called each time Action Menu is dropped down
        {

            NAM_INITMENU_INFO*  pInitMenuInfo;
            WORD                wFlags;

            pInitMenuInfo = (NAM_INITMENU_INFO *) pParam;
            wFlags = MF_ENABLED | MF_BYCOMMAND;

            // Set Menu Item State 
            EnableMenuItem(pInitMenuInfo->hMenu, gwStartingID
                + IDS_MENU_NAME, wFlags);

        }

        return (NAM_NOERROR);
    case NAMM_COMMAND:
        // Called when user clicks the Menu Item
        {
            // do the actual command work here
            CString strAppName;
            strAppName.LoadString(IDS_APP_NAME);
            AfxMessageBox("Menu Item Clicked",IDS_APP_NAME,MB_OK);

            return (NAM_NOERROR);
        }
    case NAMM_TERM:
    default:
        return (NAM_NOERROR);
    }
}

Description

Now this is not as complicated as it looks. Notes APIs provide with a lot of structures. I suggest you refer the Notes API Reference for more information on those structures. To start away with, the NAMM_INIT tells the DLL that the Notes Client Actions menu needs to be initialized with the menu items defined in the menu add-in program. When this messgae is encountered, your program should initialize the menu using the NAMM_INIT_INFO structure.
    NAM_INIT_INFO*  pInitInfo;
    pInitInfo = (NAM_INIT_INFO *) pParam;

    // Save the starting ID of the First item appended to menu
    if (pInitInfo->wMenuItemNumber == 0)    /* first time through */
        gwStartingID = pInitInfo->wStartingID;

    // Give Notes our menu id 
        pInitInfo->wMenuID = IDS_MENU_NAME;

.....

    _tcscpy(pInitInfo->MenuItemName, (LPCSTR)strAppName);
wStartingID is the NotesID for the first add-in menu item. The program must save the starting ID the first time the message is processed. wMenuID is a value that is assigned to each add-in menu. MenuItemName is the string to displayed in the menu as the menu option name.

Each time the Action Menu item is selected in Lotus Notes, the message NAMM_INITMENU is sent to the DLL. This is where we enable, disable, check or gray the add-in menu items. This is done through the NAM_INITMENU_INFO structure.

    NAM_INITMENU_INFO*  pInitMenuInfo;
    WORD                wFlags;

    pInitMenuInfo = (NAM_INITMENU_INFO *) pParam;
    wFlags = MF_ENABLED | MF_BYCOMMAND;

    // Set Menu Item State 
    EnableMenuItem(pInitMenuInfo->hMenu, gwStartingID
        + IDS_MENU_NAME, wFlags);

When a user selects a add-in menu item from the Actions menu, the NAMM_COMMAND is sent to the DLL for processing. The DLL populates the NAM_COMMAND_INFO structure. From the structure, you can proceed with calling functions and other API programs that are appropriate to the menu item selected. For this example I have not populated the NAM_COMMAND_INFO structure because we are creating only one add-in menu. In cases where we are adding more than one add-in menu, the structure values can be used to determine which one of the add-in menus was invoked.

After all the processing is done in NAMM_COMMAND it should always return NAM_NOERROR.

Configuring Notes

You have to be sure to declare the AddinMenuProc and assign it the ordinal value of 1 in the EXPORTS section of the .def file. Now compile the program into a dll. After this is done you have the follow the following steps to configure Notes to load the DLL when Notes is launched.

  • Place the MenuAddin.dll in the Notes folder. This will be DriveLetter:/Lotus/Notes.
  • Configure the Notes workstation by placing the AddinMenus variable in the NOTES.INI file. The format is:
    AddinMenus = [<drive>]:[<directory>\<addname1.dll>,
        [<drive>]:[<directory>\<addname2.dll>
        ...
    
    If the Dll is placed inside the Notes folder, you needn't specify the path. In our case it would be,
    AddinMenus = MenuAddin.dll
    
    If there is more than one dll you could use commas to separate them.

      Thats It!

      If everything has gone well, Notes will now have a new Menu Item in the Actions Menu.

      What Next?

      We have now seen how to create a single Menu add-in in the Action Menu of Lotus Notes. The next step would be to create multiple add-in menus and handling status of each of the add-in menu items.
    • License

      This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

      About the Author

      Tingz Abraham



      United States United States

      Member

      When Tingz Abraham was old enough to realize that computers were going to invade the world, he decided to pursue a career that would keep him close to computers. That landed him a job as an IT Solutions Consultant in Seattle, USA where he currently works. He believes he can program in many languages, including English. Ctrl+C and Ctrl+V are his favorite keys on the keyboard.
       
      After he found he sucked real bad at playing the violin, he just stuck to the guitar and piano. He has a ravishing need for speed and takes a fancy to anything with wheels, including his black Mustang which he's aptly named 'Tingzmobile'.
       
      At work you can constantly hear him say - "Oh! The things I learn after I know it all!" He keeps himself very busy, and in his spare time he keeps wondering why '24 hours a day is just not enough'.
       
      He exists at www.Tingzabraham.com

      Sign Up to vote   Poor Excellent
      Add a reason or comment to your vote: x
      Votes of 3 or less require a comment

      Comments and Discussions

       
      You must Sign In to use this message board. (secure sign-in)
       
      Search this forum  
       FAQ
          Noise  Layout  Per page   
        Refresh
      Questionis exist any way to get new message id or data? Pinmembers0muel0:00 7 Dec '09  
      GeneralMessage Box Error PinmemberNanjuSw23:31 17 Feb '09  
      GeneralProgramatically adding a new button on lotus notes toolbar. [modified] Pinmemberashneet1391:31 7 Oct '08  
      GeneralLotus Notes UI Pinmemberalexander.beletsky0:06 3 Jul '08  
      GeneralOpenURL Pinmembermultflora10:44 24 Jan '08  
      QuestionLNSession object causes menu to disappear [modified] PinmemberMember 204045921:48 3 Jan '08  
      AnswerRe: LNSession object causes menu to disappear Pinmemberalexander.beletsky23:34 1 Jul '08  
      GeneralRe: LNSession object causes menu to disappear Pinmemberalexander.beletsky0:03 2 Jul '08  
      QuestionLotus notes client opens and closes!!!:confused: PinmemberMember 204045919:01 1 Jan '08  
      Generalassign shortcut Pinmemberjavierjack7:28 9 Nov '07  
      Generalextract attachments Pinmemberjavierjack8:50 30 Jul '07  
      GeneralRe: extract attachments PinmemberTiNgZ aBrAhAm9:49 30 Jul '07  
      GeneralRe: extract attachments Pinmemberjavierjack10:32 30 Jul '07  
      Hi Abraham,
       
      Thank you very much for the immediate response. Well actually I have no problem with Lotus Script-approach. I can add a menu and embed some functionality whatever I wanna do by using Lotus Notes Designer. I've done that already. What I really want to do is to do this by using Addin Menu approach.
       
      Well, thank you very much once again for giving time just to reply about the matter. I will now try to research about the handle you said.
       
      Thanks.
       
      -Jack-
      GeneralAddinmenu program for lotus notes PinmemberMember #371042519:53 2 Feb '07  
      GeneralAddinmenu program for lotus notes PinmemberMember #371042519:52 2 Feb '07  
      GeneralAdd a button in the toolbaar Pinmemberromeo110:54 12 Jan '07  
      QuestionHow to call new memo using C++? Pinmembermm misa16:16 27 Jul '06  
      GeneralAdd-in button for lotus notes PinmemberVinayakChitre2:13 30 May '06  
      GeneralRe: Add-in button for lotus notes PinmemberTiNgZ aBrAhAm18:59 30 May '06  
      QuestionRe: Add-in button for lotus notes PinmemberVinayakChitre19:06 30 May '06  
      AnswerRe: Add-in button for lotus notes PinmemberTiNgZ aBrAhAm19:17 30 May '06  
      GeneralRe: Add-in button for lotus notes PinmemberVinayakChitre19:27 30 May '06  
      GeneralRe: Add-in button for lotus notes PinmemberTiNgZ aBrAhAm19:39 30 May '06  
      GeneralRe: Add-in button for lotus notes PinmemberVinayakChitre21:15 30 May '06  
      GeneralRe: Add-in button for lotus notes PinmemberVinayakChitre21:07 15 Jun '06  

      General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

      Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

      Permalink | Advertise | Privacy | Mobile
      Web04 | 2.5.120529.1 | Last Updated 10 May 2003
      Article Copyright 2003 by Tingz Abraham
      Everything else Copyright © CodeProject, 1999-2012
      Terms of Use
      Layout: fixed | fluid