LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

more than one menu bar

Using LabWindows/CVI 7.1 with Windows XP.
Have a main gui panel that requires a 'full' menu and a 'short' menu bar. Idea is that short menu is presented sometimes and full menu other times.
Short menu is a subset of full menu with same callbacks.
Have used Edit- MenuBars to copy and paste to create short menu but cannot get any "Menu Bars, Menus and Menu Items" code to be generated into the .h header file.
The callbacks are produced OK when produced by Code - Generate - Menu Callbacks.
 
Ideally would like to use DiscardMenuBar and LoadMenuBar when swapping between menus.
 
First up .. is scenario as described the right way to go about this ?
Is it possible ?
Do I have to get down to the menu item level and enable tem individually ?
 
thanks for any help,
Andrew. 
0 Kudos
Message 1 of 9
(4,024 Views)
A possible way to accomplish this task is to use InstallMenuDimmerCallback on the panel: this function is called whenever the user clicks on the menu and is executed BEFORE the menu is displayed. This way, you can programmatically decide how the menu bar will be displayed depending on program conditions: you can hide and display menu items and/or dim or undim them.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 9
(4,001 Views)
Thanks for that Roberto.

I need menu bars to react to various events. I need to make the change to the menu bar after the event has occured and without having to click the menu again.
For the moment I am dimming the unwanted/illegal menu items for my app. when they are not available.
Would still prefer to present a shortened menu.

A.

0 Kudos
Message 3 of 9
(3,991 Views)
Given your situation, I could suggest you dynamically install the proper menu bar on the panel using LoadMenuBar and DiscardMenuBar. I realized a simple project showing you a possible solution: take a look and see if it can fulfill your needs.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 9
(3,981 Views)
Would SetPanelMenuBar() work for you?
-----------------------
/* Nothing past this point should fail if the code is working as intended */
0 Kudos
Message 5 of 9
(3,979 Views)
SetPanelMenuBar permits to assign a menu bar (already loaded in memory with LoadMenuBar) to an existing panel. This can be useful to assign the same menu bar to more than one panel, but in case you only have one panel using LoadMenuBar is better.
I also noticed that is not necessary to discard the previously loaded menu bar prior to assigning a new one to the panel, so the operation simply reduces to assignin the correct menu bar to the panel when program conditions need to.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 9
(3,974 Views)
Roberto,

Your solution works, of course, but CVI-User has a point. Using SetPanelMenuBar would be more efficient, since it avoids having to reload the menubar from file each time. The way you do it is to load both menubars ahead of time, without associating them with any panel:

    mnu1Handle = LoadMenuBar (0, "ChgMenu.uir", mnu1);
    mnu2Handle = LoadMenuBar (0, "ChgMenu.uir", mnu2);

Then, whenever you want to use them, you just call
SetPanelMenuBar with the desired handle.

Of course, this also means that you don't have to (you can't, actually) discard the previous menubar before you replace it with the new one.

Luis

Message 7 of 9
(3,963 Views)

Luis, you're right: repetitively accessing the UIR file can reduce program efficiency especially (I suppose) if the UIR file is huge and/or contains several panels and menu bars.

What about resource usage? I.e. where is the menu bar loaded? I made some test on my test program and found that dynamic memory is not affected by the number of menu bars loaded (at least I see no effects on the data returned by CVIDynamicMemoryInfo)...



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 8 of 9
(3,944 Views)
The CVIDynamicMemoryInfo function only tracks memory that you yourself allocate, via malloc. The memory that the CVI run-time engine requires in order to store panels, controls, menus, etc is managed by CVI itself and is not made visible to the CVI application. Whenever CVI needs more memory, it will obtain it from the system.

In this case, the memory required to keep the extra menubar in memory is pretty negligible. I think it's definitely preferrable to loading the new one each time.

Luis
0 Kudos
Message 9 of 9
(3,934 Views)