09-02-2009 10:33 AM
Bonjour,
je dois récupérer l'ID de menubar associé à un panel. La menubar associée au panel est indiquée dans l'interface du panel (.uir : Edit Panel->Panel Settings->Menu Bar).
Le panel est chargé en mémoire par LoadPanel.
Lorsque j'appelle la fonction GetPanelMenuBar en lui passant mon handle de panel, celle ci me retourne toujours la valeur 2 (correspondant au premier item (menu) de mon menu) et non pas l'Id de menubar.
Ainsi, en créant 3 menubar et en changeant l'association de celle-ci dans le .uir du panel, bien que le bon menu soit affiché, j'obtiens toujours la valeur 2 (alors que la fonction devrait me retourner 1, 2 ou 3 selon la menubar associée au panel).
LabWindows CVI 8.5.1
Voici par exemple les ID de menubar/menusitem présents dans le .h associé au .uir :
#define MENUBAR 1
#define MENUBAR_MENU1 2
#define MENUBAR_MENU1_ITEM1 3
#define MENUBAR_MENU1_ITEM1_SUBMENU 4
#define MENUBAR_MENU1_ITEM1_ITEM2 5
#define MENUBAR_MENU1_ITEM1_ITEM4 6
#define MENUBAR_Edit 7
#define MENUBAR_Edit_ITEM5 8
#define MENUBAR_Edit_ITEM6 9
#define MENUBAR_2 2
#define MENUBAR_2_MENU2 2
#define MENUBAR_2_MENU2_2 3
#define MENUBAR_3 3
#define MENUBAR_3_MENU1 2
#define MENUBAR_3_MENU2 3
#define MENUBAR_3_MENU3 4
#define MENUBAR_3_MENU4 5
#define MENUBAR_3_MENU4_ITEM1 6
#define MENUBAR_3_MENU4_ITEM1_SUBMENU 7
#define MENUBAR_3_MENU4_ITEM1_ITEM2 8
#define MENUBAR_3_MENU4_ITEM1_ITEM2_SUBMENU 9
#define MENUBAR_3_MENU4_ITEM1_ITEM2_ITEM3 10
#define MENUBAR_3_MENU4_ITEM1_ITEM2_ITEM4 11
#define MENUBAR_3_MENU4_ITEM1_ITEM2_ITEM5 12
#define MENUBAR_3_MENU4_ITEM1_ITEM2_ITEM6 13
#define MENUBAR_3_MENU4_ITEM1_ITEM2_ITEM6_SUBMENU 14
#define MENUBAR_3_MENU4_ITEM1_ITEM2_ITEM6_ITEM7 15
#define MENUBAR_3_MENU4_ITEM1_ITEM2_ITEM6_ITEM7_SUBMENU 16
#define MENUBAR_3_MENU4_ITEM1_ITEM2_ITEM6_ITEM7_ITEM8 17
Solved! Go to Solution.
09-02-2009 02:50 PM
Bonjour educhene:
Please forgive me for not responding in French.
You are seeing the expected behavior, but I think that you are confusing the menu bar handle, the resource ID for the menu bar, and the resource ID for the menu item. The menu bar handle is a variable which is dynamically created at run time. The resource ID's are constants and are created at design time and stored in the UIR .h file.
GetPanelMenuBar() returns the handle to the menu bar, not the resource ID for the menu bar shown in the uir .h file. The function returns 2 because the menu bar is the second item to be assigned a handle. Your main panel is assigned the handle of 1 because it is the first item assigned a handle (by the LoadPanel() function). After LoadPanel() assigns the handle for the panel, it then sees that you have specified a menu bar in the UIR and assigns the next available handle (2) to the menu bar, regardless of which menu bar it is.
The value 2 returned by GetPanelMenuBar() does not refer to the value of any item on your menu.
If you want to be able to change the menu bar on your main panel under program control, you can load all the menu bars using LoadMenuBar(), then use SetPanelMenuBar() to set the active menu bar.
If you want to specify the first menu bar using the UIR editor (by editing the panel and selecting the Menu Bar from the pulldown list), you should save that handle using GetPanelMenuBar(), and pass a panel handle of 0 to the calls to LoadMenuBar(). If you pass the panel handle, the active menu bar will be the last one you loaded.
For example:
static int panelHandle;
static int hMenubar;
static int hMenubar2;
int main (int argc, char *argv[])
{
char menubarName[256];
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "myMenu.uir", PANEL)) < 0)
return -1;
// the panel was edited to assign MENUBAR as the active Menu Bar for the panel
// save the handle of the current menu bar
hMenubar = GetPanelMenuBar (panelHandle);
// get the name of the current menu bar for demonstration purposes
GetPanelAttribute (panelHandle, ATTR_PANEL_MENU_BAR_CONSTANT, menubarName);
// load MENUBAR_2 without assigning it to the panel
hMenubar2 = LoadMenuBar (0, "myMenu.uir", MENUBAR_2);
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
return 0;
}
// call these functions when needed to change menu bars
int setMenu1(void)
{
SetPanelMenuBar (panelHandle, hMenubar);
return 0;
}
int setMenu2(void)
{
SetPanelMenuBar (panelHandle, hMenubar2);
return 0;
}
09-02-2009 04:56 PM
09-02-2009 05:23 PM
Eddy:
If you need the value, you can use the constant name.
MENUBAR is a constant, value = 1 (as shown in your UIR .h file).
MENUBAR is what you would use in LoadMenuBar() for example.
To find the value of any resource ID, you just need to know the constant name. You don't need to retrieve the value: it is already associated with the value by the UIR .h file.
Except for debugging purposes, I don't think you need to know the value of any resource ID in your program, you just use the constant to refer to it. And take note that if you modify the UIR in the UIR editor, it may reassign some constant values. If you use the constant name in your program, you don't care that the value in the UIR .h file was changed.
09-03-2009 06:00 AM
In fact, I can't use the constant name because I'm developping a library which must retrieve all the menu (and sub-items) used in any application dynamically.
The goal of that library is to retrieve all the text in order to translate them rapidly.
Effectively, even if I could retrieve the constant value of the menubar, it can't help me : because we can have the same constant name and value of menubar in different uir in a project.
I don't know how to do ? ...
09-03-2009 11:05 AM
09-03-2009 03:26 PM
Eddy:
If you want to translate menu strings, have you looked at using the CVI UI Localizer?
The tool is available from the CVI menu under Tools >> User Interface Localizer.
Here's an article that steps you though it. http://zone.ni.com/devzone/cda/tut/p/id/4036
Look at the intgraph.prj example project that ships with CVI. It doesn't have French as an option, but check the CVI install disk to see if it has a French language dictionary file.
09-04-2009 07:09 AM
I don't want to use the CVI UI Localizer : I found this tool not appropriate to what I want to do.
I will try to use another method or choose this solution at the last.
Thanks for your support.
Eddy