Programming Guide |
Displays a message in a dialog box
int sm_message_box(char *text, char *title, unsigned int options, char *icon);
text
- The text of the message. The text can contain format options shown in "Description." For Motif, the text has a maximum size of 75 characters.
title
- The title of the dialog box. A null pointer or empty string specifies no title.
options
- A bit mask that specifies message box display and behavior. Arguments that set different bits can be OR'd together. Table 5-13shows the flags that you can set on this mask.
icon
- Specifies the icon to use in the dialog box. The icon specified here overrides any icon set through
options
. This argument is ignored in character-mode.
- An integer that indicates which button was pushed:
sm_message_box
creates a dialog box that displays a message and requests the user to select a button. Panther prevents further interaction with the application until the function returns with the user's selection.The message text is a single string that wraps within the window. The text can contain these
%
format options:
%K
keyname
- Displays the specified key, where
keyname
is a logical key constant. When Panther displays the message, it replaceskeyname
with the key label string defined for that key in the key translation file. If there is no label, the%K
is stripped out and the constant remains. Key constants are defined insmkeys.h
%B
- Beeps the terminal with sm_bel before the message displays. This escape character must precede the message text.
%N
- Creates a new line.
You control message box display and behavior by setting one or more flags in Table 5-13. You can set one flag from each group. Flag settings from different groups can be OR'd together.
The following sections describe these settings in more detail.
User options are controlled through the message box buttons. Table 5-13 shows the permissible combinations and the constants that set them.
Your message file defines the labels of message box buttons. You can edit this file and modify the label text. For more information on button label text, refer to "Customizing Push Button Labels for Message Boxes" in Application Development Guide.
You can use the
options
parameter to set a flag for the system icon you want to display in the message window, if any. The actual icon that appears is platform-specific. In character mode, Panther searches in the message file for the tag that corresponds to the specified icon and its associated text; this text appears in front of the title text. For information on modifying message file tags, refer to "Using Message Files" in Application Development Guide.
The
options
parameter can set the default button. The default button is specified by position—for example, you can set the third button as the default. You cannot set the Help button as the default button.
Panther requires the user to respond to the message before continuing interaction with the application. You can extend this restriction to the entire system, and thereby prevent interaction with other applications, by setting
SM_MB_SYSTEMMODAL
on theoptions
parameter. The default modality setting isSM_MB_APPLMODAL
, which constrains user interaction only within the Panther application.
proc clean_exit()
{
vars btnPush
btnPush = sm_message_box("Save changes before exiting?",\
"", SM_MB_YESNOCANCEL | SM_MB_ICONQUESTION,"")
if (btnPush == SM_IDCANCEL)
{
return
}
if (btnPush == SM_IDYES)
{
call save_changes()
}
if (btnPush == SM_IDNO)
{
call sm_jclose()
}
}