<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[NppCSharpPluginPack: how to add toolbar buttons?]]></title><description><![CDATA[<p dir="auto">I am developing plugin with 2 commands<br />
Settings<br />
Format</p>
<p dir="auto">The plugin is added to the Notepad++ and I see it in the<br />
plugins-&gt;<br />
PMF -&gt;<br />
Settings<br />
Format<br />
And click on these menus call the corresponding  function. It is ok.<br />
Now I want to add 2 toolbar buttons.<br />
They were added with icons. But no tooltips and click has no reaction. What I do wrong?<br />
Here is my 2 functions<br />
public static void CommandMenuInit()<br />
{<br />
IsCmdMenuInitCalled=true;<br />
int index = 0;<br />
PMFPanelId = index++;<br />
PMFSettingsId = PMFSettingsId;<br />
PluginBase.SetCommand(PMFPanelId = index++, “PMF Format”, ExecuteFormatting);<br />
PluginBase.SetCommand(PMFPanelId = index++, “PMF Settings”, ShowSettingsWindow);</p>
<pre><code>SetToolbarImage(XPoorTSQLFormatter.NPP.Resources.Resource.pmf_format, 1);
SetToolbarImage(XPoorTSQLFormatter.NPP.Resources.Resource.pmf_settings, 2);
</code></pre>
<p dir="auto">}<br />
static public void SetToolbarImage(Bitmap image, int pluginId)<br />
{<br />
var tbIcons = new toolbarIcons();<br />
tbIcons.hToolbarBmp = image.GetHbitmap();<br />
tbIcons.hToolbarIcon = tbIcons.hToolbarBmp;        // same icon for light mode<br />
tbIcons.hToolbarIconDarkMode = tbIcons.hToolbarBmp; // same icon for dark mode</p>
<pre><code> 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);
</code></pre>
<p dir="auto">}</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/27450/nppcsharppluginpack-how-to-add-toolbar-buttons</link><generator>RSS for Node</generator><lastBuildDate>Thu, 17 Sep 2026 00:21:21 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/27450.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 13 Mar 2026 08:40:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to NppCSharpPluginPack: how to add toolbar buttons? on Fri, 20 Mar 2026 15:23:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mark-olson" aria-label="Profile: Mark-Olson">@<bdi>Mark-Olson</bdi></a> You are  right, thanx Mark.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/105001</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/105001</guid><dc:creator><![CDATA[ZedZipDev]]></dc:creator><pubDate>Fri, 20 Mar 2026 15:23:19 GMT</pubDate></item><item><title><![CDATA[Reply to NppCSharpPluginPack: how to add toolbar buttons? on Wed, 18 Mar 2026 15:36:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/zedzipdev" aria-label="Profile: ZedZipDev">@<bdi>ZedZipDev</bdi></a></p>
<p dir="auto">Core maintainer of <a href="https://github.com/molsonkiko/NppCSharpPluginPack" rel="nofollow ugc">NppCSharpPluginPack</a> here.</p>
<p dir="auto">It’s pretty hard for me to diagnose your problem if you don’t share a link to your full codebase with me. However, it looks to me like you’re calling <code>SetToolbarImage</code> in the <code>CommandMenuInit</code> method, which I don’t think you should do. In the current version of the plugin pack, you may notice that in <a href="https://github.com/molsonkiko/NppCSharpPluginPack/blob/3064129c29588a7b382fad95fded6d8b4e18aa79/NppCSharpPluginPack/PluginInfrastructure/UnmanagedExports.cs#L50" rel="nofollow ugc">the beNotified method of <code>UnmanagedExports.cs</code></a>, the <a href="https://github.com/molsonkiko/NppCSharpPluginPack/blob/3064129c29588a7b382fad95fded6d8b4e18aa79/NppCSharpPluginPack/Main.cs#L137" rel="nofollow ugc"><code>SetToolbarIcons</code> method</a> is called, which initializes all the toolbar icons for the plugin.</p>
<p dir="auto">Truth be told, I have never studied the relevant sections of the Notepad++ codebase well enough to fully understand what’s going on with toolbar icons. I’ve just mostly gone with what worked in <a href="https://github.com/kbilsted/NotepadPlusPlusPluginPack.Net" rel="nofollow ugc">the old NotepadPlusPlusPluginPack.Net</a> in this instance.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/104981</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/104981</guid><dc:creator><![CDATA[Mark Olson]]></dc:creator><pubDate>Wed, 18 Mar 2026 15:36:23 GMT</pubDate></item></channel></rss>