LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I call a function before a menu is displayed?

InstallMenuDimmerCallback() allows a function to be called when any menu item is selected.
I only want to call the function when one particular menu item is selected.
I really want a version of InstallMenuDimmerCallback() with the menu item as a parameter as well as the menu bar handle.
Or is there something I can do inside my callback function to establish which menu item has been selected?
0 Kudos
Message 1 of 7
(3,999 Views)
Margaret,

The purpose of the dimmer callback isn't really to notify you when a user selects a menu item. Its purpose is to allow you to decide which items in a menu should be dimmed, based on the state of your program. This allows you to not have to always be dimming and undimming menu items whenever something changes, and instead concentrate all the dimming logic in a single place.

It sounds as if what you are looking for is a simple notification whenever the user operates a menu item. For that purpose, you need only use the standard callback function that is associated with the menu item. The way you create that association can be one of the following:

1. If you create the menu in the UI editor, specify your function in the "Callback Function" control of the Edit Menu Bar dialog.
2. If you create the menu or the menu item programmatically, specify your function as the "Event Function" parameter of the NewMenuItem function.
3. If you want to set or change the association after the menu item has been created, you can use the InstallMenuCallback function.

The function you specify will be called whenever the user selects your menu item.

Luis
NI
0 Kudos
Message 2 of 7
(3,995 Views)
Hi Luis
I think you've misunderstood what I want to do, so I will explain more fully.
One of my menu items is "Comms".
When a user selects this, I want to check which comms ports are currently available and display them as a submenu, for the user to check the port he wants to use.
In the UI editor, I have assigned a callback function to "Comms", but this does not get called if the menu item has a submenu.
If I were to remove the submenu items when the user had selected his comm port, I would get an exclamation mark after the "Comms" - which I don't want.
Any ideas?

Regards,
Margaret
0 Kudos
Message 3 of 7
(3,992 Views)
Margaret,

Let me see if understand correctly.

You have a menu bar that contains several menus. One of the menus is called "Comms". You want to populate this menu with various menu items whenever the user attempts to display this menu. However, you never want the menu to be empty, otherwise it becomes an immediate action menu (with the exclamation mark).

If that is correct, then you should use the dimmer callback to populate the menu. But make sure that there is always one item in there. It doesn't matter which, since the user will never see it. The point is only to prevent the exclamation mark from appearing; whenever the user operates the menu you can then replace this dummy entry with the actual list of comm ports.

Yes, it will be the case that this dimmer callback will be called not only when the user activates the Comms menu, but also any other menu in the menu bar. This doesn't affect the correctness program, as long as you *always* update your menu regardless of which menu the user selected. But you might have performance concerns, in case it takes time to do this. If that's the case I have a possible solution: there's an undocumented function (in other words, buyer beware...) that allows you to restrict dimmer events to a single menu. To use it, you'll have to add the following code to your program:

typedef void (__cdecl * MenuDimmerExCallbackPtr)(int menuBar, int menu, int menuItem, int panel, int event, void *callbackData, int eventData);

extern int InstallMenuDimmerCallbackEx (int menuBar, int menu, MenuDimmerExCallbackPtr dimmerFunction, void *callbackData);

Then, call InstallMenuDimmerCallbackEx instead of InstallMenuDimmerCallback to assign the callback, passing it the ID for the "Comms" menu.


- luis
0 Kudos
Message 4 of 7
(3,969 Views)
Hi Luis,

Yes, you have understood correctly, and your soultion is just what I want.
Unfortunately, when I try to implement it, I get a linker error: Undefined Symbol 'InstallMenuDimmerCallbackEx'
I tried searching for InstallMenuDimmerCallbackEx in the MeasurementStudio directory, but found nothing.

Margaret
0 Kudos
Message 5 of 7
(3,958 Views)
Hmmm... since you mention "MeasurementStudio directory" I suspect you might be using version 6.0 of CVI. If that's the case, you're out of luck, since we only added InstallMenuDimmerCallbackEx in version 7.0.

I guess you have to go back to rebuilding your menu on each use of the menubar...

- luis
0 Kudos
Message 6 of 7
(3,949 Views)
How frustrating - so near and yet so far!!
I am using v5.5.1 of CVI. Maybe I should think about upgrading.
Anyway, many thanks for your help.

Happy Christmas!
Margaret
0 Kudos
Message 7 of 7
(3,943 Views)