LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Probleme fonction GetPanelMenuBar()

Solved!
Go to solution

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

0 Kudos
Message 1 of 8
(5,365 Views)

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;

}

Message 2 of 8
(5,355 Views)
So, as I understand, there is no way to retrieve the menubar ID resource value (present in the .h  file) by program ??
Eddy DUCHENE
12 F Chemin de Boutary
69300 CALUIRE ET CUIRE

educhene@laposte.net
0 Kudos
Message 3 of 8
(5,350 Views)

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.

 

 

0 Kudos
Message 4 of 8
(5,347 Views)

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 ? ...

0 Kudos
Message 5 of 8
(5,331 Views)
If you want to retrieve menu and menu item names you can do it through GetMenuBarAttribute function: take a look at the attached example, which is a modified version of the "menus" example shipped with CVI; in this example all menu and menu item names are retrieved and printed to the debug output window.


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?
Message 6 of 8
(5,318 Views)

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.

 

0 Kudos
Message 7 of 8
(5,306 Views)
Solution
Accepted by topic author educhene1

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

0 Kudos
Message 8 of 8
(5,290 Views)