Community
    • Login

    NppCSharpPluginPack: how to add toolbar buttons?

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    1 Posts 1 Posters 36 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Z
      ZedZipDev
      last edited by

      I am developing plugin with 2 commands
      Settings
      Format

      The plugin is added to the Notepad++ and I see it in the
      plugins->
      PMF ->
      Settings
      Format
      And click on these menus call the corresponding function. It is ok.
      Now I want to add 2 toolbar buttons.
      They were added with icons. But no tooltips and click has no reaction. What I do wrong?
      Here is my 2 functions
      public static void CommandMenuInit()
      {
      IsCmdMenuInitCalled=true;
      int index = 0;
      PMFPanelId = index++;
      PMFSettingsId = PMFSettingsId;
      PluginBase.SetCommand(PMFPanelId = index++, “PMF Format”, ExecuteFormatting);
      PluginBase.SetCommand(PMFPanelId = index++, “PMF Settings”, ShowSettingsWindow);

      SetToolbarImage(XPoorTSQLFormatter.NPP.Resources.Resource.pmf_format, 1);
      SetToolbarImage(XPoorTSQLFormatter.NPP.Resources.Resource.pmf_settings, 2);
      

      }
      static public void SetToolbarImage(Bitmap image, int pluginId)
      {
      var tbIcons = new toolbarIcons();
      tbIcons.hToolbarBmp = image.GetHbitmap();
      tbIcons.hToolbarIcon = tbIcons.hToolbarBmp; // same icon for light mode
      tbIcons.hToolbarIconDarkMode = tbIcons.hToolbarBmp; // same icon for dark mode

       var iz = Marshal.SizeOf(tbIcons);
       var iz2 = Marshal.SizeOf(tbIcons.hToolbarIcon);
      // MessageBox.Show($"SetToolbarImage: {pluginId}");
      
       //MessageBox.Show($"{pluginId}: Size of toolbarIcons struct: {iz2} bytes");
      
       IntPtr pTbIcons = Marshal.AllocHGlobal(iz);
       Marshal.StructureToPtr(tbIcons, pTbIcons, false);
      
       Win32.SendMessage(
           PluginBase.nppData._nppHandle,
           (uint)NppMsg.NPPM_ADDTOOLBARICON,
           (IntPtr)PluginBase._funcItems.Items[pluginId-1]._cmdID, 
           pTbIcons);
      
       Marshal.FreeHGlobal(pTbIcons);
      

      }

      1 Reply Last reply Reply Quote 0
      • First post
        Last post
      The Community of users of the Notepad++ text editor.
      Powered by NodeBB | Contributors