Unable to check a toolbar button on startup
I’ve developing a plugin where I want to save the checked state of a menu item & toolbar button. When Notepad++ loads I want to restore the state that was previously saved.
I’m running into an issue when on load I can restore the checked state of the menu item, but the checked state of the toolbar button is not restored.
In my beNotified method I check for NPPN_TBMODIFICATION. This is when I add my icon to the toolbar.
Immediately after I add my icon to the toolbar I call:
SendMessage(handle, NPPM_SETMENUITEMCHECK, menuCommand, 1);
After this SendMessage command is run I end up with the menu item checked, but the button on the toolbar is not checked.
If I call this SendMessage command later on then both the menu item and the toolbar button will be checked.
Is there a reason why the toolbar button doesn’t get checked at this point in time?
Is there a notification I should be listening to in order to check my toolbar button?
Every menu item should have a Boolean property similar to the
_init2Checkmember of the
FuncIteminterface type. Setting this to
truemakes the checkmark appear.
Assuming your plugin initializes its menu items in a constructor, the
::setInfofunction is where you would assign the restored state to each item’s
_init2Checkmember, or whatever your implementation calls it. One of my own plugins does exactly that by reading values from an *.ini file.
::setInfois called by N++ before
::getFuncsArray, and long before the toolbar gets drawn. Up to now you’ve been calling a window procedure, but your menu items need to be created and configured even before there is any window to receive messages.