NppCSharpPluginPack: how to add toolbar buttons?
-
I am developing plugin with 2 commands
Settings
FormatThe 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 modevar 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);}