03-12-2010 03:39 PM
I have a panel that contains a number of buttons.
The number of buttons and the text in the buttons are supposed to change during the program execution.
I know how to create the buttons on the fly using NewCtrl, but have problems erasing/modifying excisting buttons.
Is there a way to get access to the list of Ctrl objects in a panel, investigate the Ctrl objects and erase or modify the Ctrl?
At the moment I am using DiscardCtrl, but this requires me to keep track of the Ctrl objects.
Mistakes in mainting this information are hard to debug. It would be far simpler if I could access the information that the application maintains.
Solved! Go to Solution.
03-12-2010 05:19 PM
A magic rule in CVI is that everything you can do in the UIR editor can be done programmatically ar runtime: you only have to know the right way to do it! So:
Deleting a control: DiscardCtrl () (you already discovered it)
Editing control aspect: almost all operations are done with SetCtrlAttribute with the appropriate attribute.
Obtaining the list of controls can be done this way:
GetCtrlAttribute (panelHandle, ATTR_FIRST_CTRL, &ctrlID);
while (ctrlID) {
// operate on the control
....
// Get next control: 0 if the last control in the panel is found
GetCtrlAttribute (panelHandle, ctrlID, ATTR_NEXT_CTRL, &ctrlID)
}
While scanning the controls in a panel you can retrieve details on the control by using
GetCtrlAttribute (panelHandle, ctrlID, ATTR_CTRL_STYLE, &style);
The list of control styles (buttons, rings...) can be found in userint.h
As an example, attached is a function I developed that:
- scans all controls in a panel
- switches all operable controls between indicator or hot
- skipping controls in a variable-list of arguments
To call this function to set all control as hot:
SetParamPanel (panelHandle, 1, VAL_HOT, 0);
To set all controls as indicator except quit button:
SetParamPanel (panelHandle, 0, VAL_HOT, PANEL_QUIT, 0)
Hope this helps.
03-12-2010 06:00 PM
Thanks,
Getting the next controll was what I was looking for.