How to capture a key pressed event while a menu item is highlighted (in Lazarus) - menuitem

In Lazarus, I want to programmatically delete a menu item (say under the File menu) during runtime. The user will open the File menu to list all its items, then use the arrow keys to go to a specific (deletable) item, like a recently used file, and press Del key to delete that menu item from the File menu.
How can I capture the event of Del key being pressed while a specific menu item is selected (highlighted) by the user?
Please note that I am coding for both Windows and Linux (GTK2) at the same time. So, I would need a "standard" (Lazarus-way of) solution that will work on both systems: Suggested Windows-related answers are not appropriate in my case.

Related

Setting a window menu with set_menubar(), is there an 'activated' signal I can connect to run custom code when a menu is opened from the bar?

Gtk 3.0 application (with C++ and GtkMM). I use set_menubar() to set the menu bar for the main window (loaded from a resource file, i.e. a "*.ui" XML file).
At run time, I want to be able to enable/disable (gray out) menu items in accordance with availability. I know that I can use "add_action()" and "remove_action()" to associate/dissociate the actions, which will have the desired effect. However it is complicated and expensive to add/remove the actions dynamically considering that the only time it matters which actions are available is when the user has opened the menu and is looking at it.
So I was thinking that I should be able to connect to an "activate" signal of the menu bar items to adjust the appearance of their menu each time the user clicks on an item, just before the corresponding menu is displayed to the user. Any idea how I can get to the signal from the Gio::Menu resource? Is this possible in theory but an unfortunate omission in the Glib API? Or is there something I don't understand?

How to dynamically insert a menu on CMFCMenuBar?

There are already some menus on CMFCMenuBar, now I want to dynamically add a menu item to CMFCMenuBar and keep the original menu
I used m_wndMenuBar.CreateFromMenu(m_pXmlMenu->m_wndMainMenu);
I found that the original menu would be deleted. How can I solve it?
If you put your Mainframe's message map to respond to ON_WM_INITMENUPOPUP you can process the insert of menus every time the user will open a top level menu, assuming you are using a CFMCMenuBar.
If you are using menus the old way, you will have to respond to ON_WM_INITMENU

Replace system menu popup on windows

I want to replace the default sys menu(Restore, Move, Size etc.) with my custom entries. The menu I'm talking about can be opened either by clicking left button on window icon or by clicking right button on window title.
I can remove all the items and populate this menu with my own entries. But if I remove all entries then minimize, maximize and close buttons become inactive. So they depend on those menu items.
I want to have min, max, close buttons working as usual but system menu which contains my own items(like it is done in Windows Media Player).
I'm using Qt, but I'm almost sure it can't be done with it so any solution would be appreciated.
Do not remove Min/Max/Close items from system menu. It's much better to process WM_SYSCOMMAND message instead (SC_MINIMIZE, SC_MAXIMIZE, SC_RESTORE, SC_CLOSE).

How to gray out a menu item in Qt

I'm building a small program in Qt with menu bars (menuBar) using C++ and I would like to know how to gray out (eg. disable) an item of the menu when a certain variable is activated. Is it possible?
If you know an index of the corresponding QAction :
QMenu::actions.at(i).setEnabled(false);
P.S. As kindly prompted below, setEnabled(bool) and setDisabled(bool) are slots (so is toggle()), so they can be connected to a signal indicating a need to change the availability of the action.
Looking for the index of the action is not necessarily convenient. If you have built the interface with QtCreator's form editor then you will have an action for each menu item. Their names are based on the text that you first give to the actions. For example if you interactively enter a menu item with title Foo Bar then an action named actionFoo_Bar is created for you. Just type ui->action in the code editor and watch what "name completion" QtCreator will propose.
In such a case I would consider a call like this:
ui->actionFoo_Bar.setEnabled(false);
You can even make the menu item disappear with
ui->actionFoo_Bar.setVisible(false);

What triggers LBN_SELCANCEL?

I'm trying to understand the listbox notification LBN_SELCANCEL. MSDN says "Notifies the application that the user has canceled the selection in a list box." OK, but how exactly does a user "cancel the notification"? I've got LBS_NOTIFY set, and I've tried selecting another item, clicking outside the listbox, clicking another window, and none of these trigger LBN_SELCANCEL.
Anyone know what specifically triggers this notification?
I believe LBN_SELCANCEL only applies to ComboBox controls because they also use lists.
It should be called when you open the drop down hover over an element then press ESC.