Programming with Command Button Controls
This topic describes how to complete the following tasks programmatically.
- Creating a command button control
- Determining the size of the buffer needed to get the button label
- Resizing the command button
- Setting and getting the string displayed on the button
Creating a Command Button Control
Use NewCtrl to create a command button control.
command = NewCtrl (panelHandle, CTRL_SQUARE_COMMAND_BUTTON, "My Command Button", 30, 30);
Setting and Getting the String Displayed on the Button
SetCtrlAttribute (panelHandle, PANEL_COMMANDBUTTON, ATTR_LABEL_TEXT, "My Command Button");
char textLabel[100];
GetCtrlAttribute (panelHandle, PANEL_COMMANDBUTTON, ATTR_LABEL_TEXT, textLabel);
Determining the Size of the Buffer Needed to Get the Button Label
Use GetCtrlAttribute with the ATTR_LABEL_TEXT_LENGTH attribute to determine the size of the buffer needed to get the button label. Keep in mind that GetCtrlAttribute appends a NULL byte to the end of the text string, so you must make the buffer 1 byte larger than the value obtained using ATTR_LABEL_TEXT_LENGTH.
GetCtrlAttribute (panelHandle, PANEL_COMMANDBUTTON, ATTR_LABEL_TEXT_LENGTH, &labelTextLen);
labelText = malloc ((labelTextLen + 1) * sizeof (char));
Resizing the Command Button
Use SetCtrlAttribute with the ATTR_AUTO_SIZING attribute to resize the command button.
SetCtrlAttribute (panelHandle, PANEL_COMMANDBUTTON, ATTR_AUTO_SIZING, VAL_ALWAYS_AUTO_SIZE);
SetCtrlAttribute (panelHandle, PANEL_COMMANDBUTTON, ATTR_AUTO_SIZING, VAL_GROW_ONLY);
SetCtrlAttribute (panelHandle, PANEL_COMMANDBUTTON, ATTR_AUTO_SIZING, VAL_SHRINK_ONLY);
SetCtrlAttribute (panelHandle, PANEL_COMMANDBUTTON, ATTR_AUTO_SIZING, VAL_NEVER_AUTO_SIZE);