08-10-2012 03:25 AM
I have an item in the menu with the properties checked activated. I do not manage to have the properties of checked. Do I have to use GetCtrlVal and SetCtrlVal to get and set the propertie checked ? At each time the user click on this menu entry, I would like to change the status of checked/not checked.
See the attached file.
Thanks for the support.
Solved! Go to Solution.
08-10-2012 03:42 AM
Hi,
1) in the UI editor you set the initial attributes, i.e. when the program starts up your menu item will be checked.
2) If you want to change an attribute (dimmed, checked,...) at run time, you can use the function
SetMenuBarAttribute ( menu_bar_handle, menu_item_id, ATTR_CHECKED, 0 (or 1) );
Note that you are a setting an attribute (hence the name Set...Attribute), not a value; also you want to address a menu (hence the name SetMenuBarAttribute) and not a UI control
08-10-2012 03:52 AM
... and if you want to change the attribute every time a user clicks on this menu entry, you will need to use a menu callback such as
void CVICALLBACK EnableFMCLogFileMenuBar ( int menuBar, int menuItem, void *callbackData, int panel )
{
fmc_log = !fmc_log;
SetMenuBarAttribute ( menuBar, menuItem, ATTR_CHECKED, fmc_log );
return;
}
08-10-2012 04:34 AM
Ok, I want to use GetMenuBarAttribute to get the status : here is my code
void CVICALLBACK EnableFMCLogFileMenuBar (int menuBar, int menuItem, void *callbackData,int panel)
{
int Value;
Value = GetMenuBarAttribute(menuBar, menuItem, MAIN_M_BAR_FMCLOG_LOG_FMC, &Value);
At execution, I have the following error message : "The attribute passed is not valid"
I dot not know what use for attribute instead of MAIN_M_BAR_FMCLOG_LOG_FMC
08-10-2012 05:01 AM
Obviously, your function call is wrong as it does not contain a valid attribute....
@sfla wrote:
Value = GetMenuBarAttribute(menuBar, menuItem, MAIN_M_BAR_FMCLOG_LOG_FMC, &Value);
At execution, I have the following error message : "The attribute passed is not valid"
Your MAIN_M_BAR_FMCLOG_LOG_FMC is not an attribute but probably your menuItem...A valid attribute, for example, is ATTR_CHECKED, so the function call should look like:
GetMenuBarAttribute ( menuBar, menuItem, ATTR_CHECKED, &Value );
08-10-2012 05:05 AM
I have tried, but I have always Value = 0 (whatever the initial configuration checked or not)...
08-10-2012 05:19 AM
That's because of a second mistake: you assign Value twice...as attribute, and as status:
Value = GetMenuBarAttribute ( menuBar, menuItem, ATTR_CHECKED, &Value );
so in this case Value = 0 means that the function returned without error (at the price that you overwrote your attribute value)
So change it so something like:
status = GetMenuBarAttribute ( menuBar, menuItem, ATTR_CHECKED, &Value );
08-15-2012 11:34 PM
Hi,
I am wondering if your question got resolved. If so, you could mark one of my answer as the solution, thanks.
08-16-2012 04:55 AM
Ok, I was on vacation. It works now ! Thanks a lot for your help !
08-16-2012 04:59 AM - edited 08-16-2012 05:00 AM
You're welcome - but as a side note, you should have marked the post that solved your problem, not your own thank you