LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to display selected popup menu Item

Hi,
I am novice to the labwindows... My problem is that I have made a popup menu. The menu gets its items from a file. I want that when i click on any of the item, the specific text gets displayed on the control. Here is what I am trying
/*-----------------------------------------------------------------------------------*/
int CVICALLBACK quick_command (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
new_menu = NewMenu(command_menu,"Hello",0);
fileHandle = OpenFile("commands.txt",VAL_READ_ONLY,VAL_OPEN_AS_IS,VAL_ASCII);
line_buff = 0;
while (line_buff>-2)
{
line_buff = ReadLine(fileHandle,buffer_line,-1);
addMenu = NewMenuItem(command_menu,new_menu,buffer_line,-1,0,menu_Handle_CB,0);
InstallMenuCallback(command_menu,new_menu,menu_Handle_CB,0);
}

CloseFile(fileHandle);
GetCtrlAttribute(panelHandle,PANEL_QUICK_COMMAND,ATTR_LEFT,&command_left);
GetCtrlAttribute(panelHandle,PANEL_QUICK_COMMAND,ATTR_TOP,&command_top);

RunPopupMenu(command_menu,new_menu,panelHandle,command_top,command_left,0,0,0,0);

break;
default:

break;
}
return 0;
}

void CVICALLBACK menu_Handle_CB (int menuBarHandle, int menuItemID,
void *callbackPtr, int panelHandle)
{
char buf[10];
sprintf(buf,"%d",menuItemID);
SetCtrlAttribute(panelHandle,PANEL_QUICK_COMMAND,ATTR_LABEL_TEXT,buf);

}
/*-----------------------------------------------------------------------------------*/
Can anybody help me.... please....
Spark
0 Kudos
Message 1 of 2
(2,540 Views)
Hi Spark,
If I have correctly understood your problem, you want to display in a string control the exact text you have loaded from the file and displayed in the popup menu.

Here you find a modified version of your source that displays the text in a message box: you can modify it to adapt to your needs. In the code it is not necessary to install a callback for menu items.

This is the source code for your quick_command callback:
switch (event) {
case EVENT_COMMIT:
command_menu = NewMenuBar (0);
new_menu = NewMenu(command_menu,"Hello",0);
for (i = 0; i < 5; i++) {
sprintf (msg, "Menu item #%d", i + 1);
addMenu = NewMenuItem (command_menu, new_menu, msg, -1, 0, 0, 0);
}

GetCtrlAttribute(panel,control,ATTR_LEFT,&left);
GetCtrlAttribute(panel,control,ATTR_TOP,&top);

i = RunPopupMenu(command_menu,new_menu,panel,top,left,0,0,0,0);
GetMenuBarAttribute (command_menu, i, ATTR_ITEM_NAME, msg);
MessagePopup ("Menu", msg);

break;
default:

break;
}


But, after considering it for a while, I wonder why you are not using a ring control that executes the exact thing you are trying to mimic with the popup menu...

Hope this helps
Roberto


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 2 of 2
(2,523 Views)