Programming with Text Message Controls
This topic describes how to complete the following tasks programmatically.
ATTR_STRING_TEXT_LENGTH attribute to determine the size of the- Creating a text message control
- Setting and obtaining text
- Setting text style
- Getting the number of bytes of text
Creating a Text Message Control
Call NewCtrl to create a text message control. Text message controls do not have labels. The controlLabel parameter for the NewCtrl function specifies the text that appears as the text message.
textMsg = NewCtrl (panelHandle, CTRL_TEXT_MSG, "Hello, I am a text message control", 20, 20);
Setting and Obtaining Text
Call SetCtrlVal to specify the text for the text message.
SetCtrlVal (panelHandle, textMsg, "Setting a new value");
GetCtrlVal obtains the value of the text message. GetCtrlVal appends a NUL byte to the end of the text string, so you must make the buffer 1 byte larger than the value returned by GetCtrlAttribute.
int textLength;
char *text = 0;
GetCtrlAttribute (panelHandle, textMsg, ATTR_STRING_TEXT_LENGTH, &textLength);
text = malloc ((textLength + 1) * sizeof (char));
GetCtrlVal (panelHandle, textMsg, text);
Setting Text Style
SetCtrlAttribute (panelHandle, textMsg, ATTR_TEXT_POINT_SIZE, 35);
SetCtrlAttribute (panelHandle, textMsg, ATTR_TEXT_FONT, "Times New Roman");
SetCtrlAttribute (panelHandle, textMsg, ATTR_TEXT_ANGLE, 450);
SetCtrlAttribute (panelHandle, textMsg, ATTR_TEXT_BGCOLOR, VAL_DK_MAGENTA);
SetCtrlAttribute (panelHandle, textMsg, ATTR_TEXT_COLOR, VAL_WHITE);
Getting the Number of Bytes of Text
int textLength;
GetCtrlAttribute (panelHandle, textMsg, ATTR_STRING_TEXT_LENGTH, &textLength);
SetCtrlVal (panelHandle, PANEL_NUMERIC, textLength);