Register each click on a menu



We have a migrated PB12.5.2 app, with a MDI-form and a main menu which contains 950 or so menuitems.

I would like to create a function/event which gets the name (or another unique id) each time each menuitem is clicked.

This would be used to sort the menu so that the least used menuitems are hidden over time.

Also it would be used for internal statistics.

I've looked into the pbm_* event ID's, but I cannot find one that is called each time a menuitem is clicked.


Thanks in advance.


Bjarne Anker

Maritech Systems AS

Question Tags: 


Olan Knight answered Register each click on a menu


If Roland's answer works, please let us know!

I did something similar a while back. I created a function on the base menu object that LOGs the name of the menu and the menu item selected.

In every descendent menu item that you might want to log, you call this function and pass it the info you want logged. Simple.

You can log the data to a database, which is the preferred method; or you can log to a text file.


Good Luck,


Bjarne Anker answered Register each click on a menu


Hi, and thanks for the great feedback.

I got this working now.

I declared a local external function like this:

FUNCTION ulong GetMenuString(ulong hMenu,uint uItem,REF String lpString,uint nMaxCount,uint uFlags) LIBRARY "user32.dll" ALIAS FOR "GetMenuStringA;Ansi"

(I guess you can alias "GetMenuStringW" as well, but I haven't tested this yet).

Then I added an event for my MDI-window, referring to the pbm_menuselect event ID.

And called the local external function like this:

ls_menuname = space(128)
i = 128

ll_ret = GetMenuString(hmenu,itemid,ls_menuname,i,flags)

ll_ret returns the number of characters in the menuitem, and ls_menuname contains the name itself.

I will look into the different flags and other values to try to filter out when you just hover over a menu without clicking it.


Thanks a lot!

Bjarne Anker answered Register each click on a menu


Hi again.


I kinda looks like the pbm_menuselect event is not suited for my need.

Being that it fires every time I hover over a menu, even without selecting/clicking it. I just want to record each time a menu is clicked.

Do you have similar problems and perhaps a solution?

It doesn't look like "flags" can help me. And "hmenu" have different values each time my application runs.

So there really isn't much to filter the results from.