Click here to Skip to main content
15,885,216 members
Articles / Desktop Programming / MFC
Article

Addin Menus in Lotus Notes using MFC/NotesAPI

Rate me:
Please Sign up or sign in to vote.
3.50/5 (5 votes)
9 May 2003CPOL4 min read 189.5K   1K   25   74
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)


      Written By
      Canada Canada
      This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

      Comments and Discussions

       
      Questionis exist any way to get new message id or data? Pin
      s0muel7-Dec-09 0:00
      s0muel7-Dec-09 0:00 
      GeneralMessage Box Error Pin
      s.nanjunda17-Feb-09 23:31
      s.nanjunda17-Feb-09 23:31 
      GeneralProgramatically adding a new button on lotus notes toolbar. [modified] Pin
      ashneet1397-Oct-08 1:31
      ashneet1397-Oct-08 1:31 
      GeneralLotus Notes UI Pin
      alexander.beletsky3-Jul-08 0:06
      alexander.beletsky3-Jul-08 0:06 
      GeneralOpenURL Pin
      multflora24-Jan-08 10:44
      multflora24-Jan-08 10:44 
      QuestionLNSession object causes menu to disappear [modified] Pin
      Member 20404593-Jan-08 21:48
      Member 20404593-Jan-08 21:48 
      AnswerRe: LNSession object causes menu to disappear Pin
      alexander.beletsky1-Jul-08 23:34
      alexander.beletsky1-Jul-08 23:34 
      GeneralRe: LNSession object causes menu to disappear Pin
      alexander.beletsky2-Jul-08 0:03
      alexander.beletsky2-Jul-08 0:03 
      QuestionLotus notes client opens and closes!!!:confused: Pin
      Member 20404591-Jan-08 19:01
      Member 20404591-Jan-08 19:01 
      Generalassign shortcut Pin
      javierjack9-Nov-07 7:28
      javierjack9-Nov-07 7:28 
      Generalextract attachments Pin
      javierjack30-Jul-07 8:50
      javierjack30-Jul-07 8:50 
      GeneralRe: extract attachments Pin
      Tingu Abraham30-Jul-07 9:49
      Tingu Abraham30-Jul-07 9:49 
      GeneralRe: extract attachments Pin
      javierjack30-Jul-07 10:32
      javierjack30-Jul-07 10:32 
      GeneralAddinmenu program for lotus notes Pin
      Member 37104252-Feb-07 19:53
      Member 37104252-Feb-07 19:53 
      GeneralAddinmenu program for lotus notes Pin
      Member 37104252-Feb-07 19:52
      Member 37104252-Feb-07 19:52 
      GeneralAdd a button in the toolbaar Pin
      romeo1112-Jan-07 0:54
      romeo1112-Jan-07 0:54 
      QuestionHow to call new memo using C++? Pin
      mm misa27-Jul-06 16:16
      mm misa27-Jul-06 16:16 
      GeneralAdd-in button for lotus notes Pin
      VinayakChitre30-May-06 2:13
      VinayakChitre30-May-06 2:13 
      GeneralRe: Add-in button for lotus notes Pin
      Tingu Abraham30-May-06 18:59
      Tingu Abraham30-May-06 18:59 
      QuestionRe: Add-in button for lotus notes Pin
      VinayakChitre30-May-06 19:06
      VinayakChitre30-May-06 19:06 
      AnswerRe: Add-in button for lotus notes Pin
      Tingu Abraham30-May-06 19:17
      Tingu Abraham30-May-06 19:17 
      GeneralRe: Add-in button for lotus notes Pin
      VinayakChitre30-May-06 19:27
      VinayakChitre30-May-06 19:27 
      GeneralRe: Add-in button for lotus notes Pin
      Tingu Abraham30-May-06 19:39
      Tingu Abraham30-May-06 19:39 
      GeneralRe: Add-in button for lotus notes Pin
      VinayakChitre30-May-06 21:15
      VinayakChitre30-May-06 21:15 
      GeneralRe: Add-in button for lotus notes Pin
      VinayakChitre15-Jun-06 21:07
      VinayakChitre15-Jun-06 21:07 

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

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