Disabling menu items

  • pnd09

    pnd09 - 2013-10-03

    Hello all. I am new to this forum and Notepad++ plug-in development. I'm a college student trying to make NPP interface with a refactoring engine developed at my University.

    Right now I'm trying to find out how to populate the plug-in submenu based on the type of the currently displayed file. So (1) is there a way to add or remove items from the submenu on the go? Or (2) could I deactivate menu items even if they are visible?

    Any help would be greatly appreciated!

  • Predelnik

    Predelnik - 2013-10-03

    Yes you can, probably I'm not doing this in most optimal way, but I guess if someone would say the better way, that would help me also.

    At first you have to find your plugin's menu, by using something like this (YOUR_PLUGIN_NAME is const string equal to your plugin's name and YourPluginMenu is HMENU result):

      HMENU PluginsMenu = (HMENU) SendMessage (NppHandle, NPPM_GETMENUHANDLE, NPPPLUGINMENU, 0);
      HMENU YourPluginMenu = 0;
      int Count = GetMenuItemCount (PluginsMenu);
      int StrLen = 0;
      TCHAR *Buf = 0;
      for (int i = 0; i < Count; i++)
        StrLen = GetMenuString (PluginsMenu, i, 0, 0, MF_BYPOSITION);
        Buf = new TCHAR[StrLen + 1];
        GetMenuString (PluginsMenu, i, Buf, StrLen + 1, MF_BYPOSITION);
        if (_tcscmp (Buf, YOUR_PLUGIN_NAME) == 0)
          MENUITEMINFO Mif;
          Mif.fMask = MIIM_ID;
          Mif.cbSize = sizeof (MENUITEMINFO);
          BOOL Res = GetMenuItemInfo (PluginsMenu, i, TRUE, &Mif);
          YourPluginMenu = (HMENU) Mif.wID;
          delete [] (Buf);
        delete [] (Buf);
    return YourPluginMenu

    After that you can just use SetMenuItemInfo with corresponding parameters and needed menu index to make it disabled.

    The other approach would be I guess to get submenu of item found by string comparison and just completely rebuild it, using ids obtained by NPPM_ALLOCATECMDID command and then parse it's result by yourself in MessageProc on WM_COMMAND. That way you can build completely your own menu and change it however you like.

    Last edit: Predelnik 2013-10-03

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks