关于messagebox

今天上午上数据库课,说到一些vfp里面的函数,其中一个是书上没有讲的,老师补充了下那就是messagebox这个函数了,
messagebox
题外话,这360~~捕获
想到了以前自己学习win32asm中的api函数messagebox,其实很多地方都有messagebox,都是这个api的封装,其实老师讲的也很不详细,google了下vfp中这个函数的用法

messagebox( ) 函数

显示一个用户自定义对话框。

语法

MESSAGEBOX(cMessageText [, nDialogBoxType [, cTitleBarText]])

参数
cMessageText

指定在对话框中显示的文本。在 cMessageText 中包含回车符 (CHR(13)) 可以使信息移到下一行显示。对话框的高度和宽度根据 cMessageText 适当增大,以包含全部信息。

nDialogBoxType

指定对话框中的按钮和图标、显示对话框时的默认按钮以及对话框的行为。
在下面的表中,对话框按钮值从 0 到 5 指定了对话框中显示的按钮。图标值 16、32、64 指定了对话框中的图标。默认值 0、256、512 指定对话框中哪个按钮为默认按钮。当显示对话框时选中此默认按钮。
当省略 nDialagBoxType 时,等同于指定 nDialagBoxType 值为0。

数值  对话框按钮
0 仅有“确定”按钮
1 “确定”和“取消”按钮
2 “放弃”、“重试”和“忽略”按钮
3 “是”、“否”和“取消”按钮
4 “是”、“否”按钮
5 “重试”和“取消”按钮

数值  图标
16 “停止”图标
32 问号
48 惊叹号
64 信息 (i) 图标

数值  默认按钮
0 第一个按钮
256 第二个按钮
512 第三个按钮

nDialogBoxType 可以是三个值的和从上面每个表中选一个值。例如,若 nDialogBoxType 为 290(2+32+256),则指定的对话框含有如下特征:

“放弃”、“重试”或“忽略”按钮。
消息框显示问号图标。
第二个按钮,“重试”为默认按钮。
cTitleBarText

指定对话框标题栏中的文本。若省略 cTitleBarText,标题栏中将显示“Microsoft Visual FoxPro”

返回值类型

数值型

说明

MESSAGEBOX( ) 的返回值标明选取了对话框中的哪个按钮。在含有取消按钮的对话框中,如果按下 ESC 键退出对话框,则与选取“取消”按钮一样,返回值 (2)。
注意本函数的最短缩写为 MESSAGEB( )。
下表列出了 MESSAGEBOX( ) 对应每个按钮的返回值。

返回值  按钮
1 确定
2 取消
3 放弃
4 重试
5 忽略
6 是
7 否

下面的示例中显示了一个用户自定义对话框。标题“record not found.would you like to search again?”显示在用户自定义对话框中,标题栏中显示“my application”。用户自定义对话框含有“是”和“否”按钮以及问号图标。第二个按钮 (no) 为默认按钮。当选取一个按钮时,显示所选的内容。

cmessagetitle = 'my application'
cmessagetext = 'record not found. would you like to search again?'
ndialogtype = 4 + 32 + 256
* 4 = yes and no buttons
* 32 = question mark icon
* 256 = second button is default

nanswer = messagebox(cmessagetext, ndialogtype, cmessagetitle)

do case
case nanswer = 6
wait window 'you chose yes'
case nanswer = 7
wait window 'you chose no'
endcase
那么现在跟windows的api函数对比下(摘自msdn)

MessageBox Function

Displays a modal dialog box that contains a system icon, a set of buttons, and a brief application-specific message, such as status or error information. The message box returns an integer value that indicates which button the user clicked.

Syntax

int WINAPI MessageBox(
  __in_opt  HWND hWnd,
  __in_opt  LPCTSTR lpText,
  __in_opt  LPCTSTR lpCaption,
  __in      UINT uType
);

Parameters

hWnd [in, optional]
HWND
A handle to the owner window of the message box to be created. If this parameter is NULL, the message box has no owner window.

lpText [in, optional]
LPCTSTR
The message to be displayed. If the string consists of more than one line, you can separate the lines using a carriage return and/or linefeed character between each line.

lpCaption [in, optional]
LPCTSTR
The dialog box title. If this parameter is NULL, the default title is Error.

uType [in]
UINT
The contents and behavior of the dialog box. This parameter can be a combination of flags from the following groups of flags.

格式里面就这四个参数啦,比较有内容的参数呢就是uint了,其中可以包含button和icon

这个是button

Value Meaning
MB_ABORTRETRYIGNORE
0x00000002L
The message box contains three push buttons: AbortRetry, and Ignore.
MB_CANCELTRYCONTINUE
0x00000006L
The message box contains three push buttons: CancelTry AgainContinue. Use this message box type instead of MB_ABORTRETRYIGNORE.
MB_HELP
0x00004000L
Adds a Help button to the message box. When the user clicks the Help button or presses F1, the system sends a WM_HELP message to the owner.
MB_OK
0x00000000L
The message box contains one push button: OK. This is the default.
MB_OKCANCEL
0x00000001L
The message box contains two push buttons: OK and Cancel.
MB_RETRYCANCEL
0x00000005L
The message box contains two push buttons: Retry and Cancel.
MB_YESNO
0x00000004L
The message box contains two push buttons: Yes and No.
MB_YESNOCANCEL
0x00000003L
The message box contains three push buttons: YesNo, and Cancel.

这个是icon

Value Meaning
MB_ICONEXCLAMATION
0x00000030L
An exclamation-point icon appears in the message box.
MB_ICONWARNING
0x00000030L
An exclamation-point icon appears in the message box.
MB_ICONINFORMATION
0x00000040L
An icon consisting of a lowercase letter i in a circle appears in the message box.
MB_ICONASTERISK
0x00000040L
An icon consisting of a lowercase letter i in a circle appears in the message box.
MB_ICONQUESTION
0x00000020L
A question-mark icon appears in the message box. The question-mark message icon is no longer recommended because it does not clearly represent a specific type of message and because the phrasing of a message as a question could apply to any message type. In addition, users can confuse the message symbol question mark with Help information. Therefore, do not use this question mark message symbol in your message boxes. The system continues to support its inclusion only for backward compatibility.
MB_ICONSTOP
0x00000010L
A stop-sign icon appears in the message box.
MB_ICONERROR
0x00000010L
A stop-sign icon appears in the message box.
MB_ICONHAND
0x00000010L
A stop-sign icon appears in the message box.

 

可以对比一下和vfp中那些数值代表的意义,和api中的这些“数值”,其实它们是表示的在内存中的位置

api的返回值是int型

Return code/value Description
IDABORT
3
The Abort button was selected.
IDCANCEL
2
The Cancel button was selected.
IDCONTINUE
11
The Continue button was selected.
IDIGNORE
5
The Ignore button was selected.
IDNO
7
The No button was selected.
IDOK
1
The OK button was selected.
IDRETRY
4
The Retry button was selected.
IDTRYAGAIN
10
The Try Again button was selected.
IDYES
6
The Yes button was selected.

好吧,还有更多详细解释请看msdn,在这里只是抛个砖,顺带思考一下api和一些高级语言中的封装的对比,当然菜菜我也分析不出啥,权当mark