Programming with Controls

This topic describes how to use the User Interface Library functions to control the elements of user interface controls.

Control Functions for All Controls

When you use LoadPanel to load a panel from a .uir file into memory, it also loads the controls on that panel. To refer to a particular control in a call to a User Interface Library function, use the defined constant you assigned to the control in the User Interface Editor. The defined constant evaluates to the resource ID for the control. You use the following functions to manage general aspects of all controls:

NewCtrl creates a new control during program execution. NewCtrl returns an ID you use to reference the control in subsequent operations. Use the first parameter of NewCtrl to specify the panel on which the control is to appear. The second parameter of NewCtrl specifies the control style. You also specify the name and position of the control through parameters to NewCtrl.

DuplicateCtrl creates a new control that is a duplicate of a control that you loaded with LoadPanel or created with NewCtrl. DuplicateCtrl returns an ID that you use to reference the control in subsequent operations. You specify the destination panel, name, and position of the control through parameters to DuplicateCtrl.

SetCtrlVal sets a control to a particular value. This function is not valid for all control types.

GetCtrlVal obtains the current value of a control. This function is not valid for all control types.

GetActiveCtrl obtains the control that receives keyboard events when its panel is the active panel.

SetActiveCtrl establishes the control that receives keyboard events when its panel is the active panel. The label of the active control is inset when its panel is the active panel.

DefaultCtrl restores a control to its default value. If the control is visible, the program updates it to reflect its default value. You assign default values to controls in the User Interface Editor or through SetCtrlAttribute. This function is not valid for all control types.

GetCtrlBoundingRect obtains the top, left, height, and width of the rectangle bounding the control and its label.

GetCtrlAttribute obtains a particular attribute of a control.

SetCtrlAttribute sets a particular attribute of a control. When changing control attributes that affect the font of a control, set the ATTR_TEXT_FONT attribute first.

DiscardCtrl removes a control from memory. If its panel is visible, the control is removed from the screen. LabWindows/CVI does not allow you to call DiscardCtrl from the callback function for the control, except in response to a commit event. A call to DiscardCtrl from any other type of event might cause unpredictable behavior.