MessageBox 和 messagedlg用法
消息框是个很常用的控件,属性比较多,本文列出了它的一些常用方法,及指出了它的一些应用场合。
1.最简单用法,不带图形
MessageBox(0,'不同意','提示',MB_OK);
MessageBox(0,'不同意','提示',MB_OKCANCEL );
2.警告对话框:
MessageBox(0,'密码不能为空,请务必输入密码','警告',MB_ICONEXCLAMATION);
3.提示信息对话框:
MessageBox(0,'密码不能为空,请务必输入密码','提示',MB_ICONASTERISK and MB_ICONINFORMATION);
4.复杂用法:
MessageBox(Handle, PChar('进程' + Listview1.Selected.caption +'不能被结束!'), PChar('提示'), MB_ICONEXCLAMATION);
附常用属性
系统默认图标,可在消息框上显示
X错误 MB_ICONHAND, MB_ICONSTOP, and MB_ICONERROR
?询问 MB_ICONQUESTION
!警告 MB_ICONEXCLAMATION and MB_ICONWARNING
i信息 MB_ICONASTERISK and MB_ICONINFORMATION
按钮的形式
MB_OK?? 默认
MB_OKCANCEL 确定取消
MB_YESNO 是否
MB_YESNOCANCEL 是否取消
返回值
IDCANCEL 取消被选
IDNO 否被选
IDOK 确定被选
IDYES 是被选
补充:
以上消息框的用法是在Delphi中的应用,如果不是,则要MessageBox(NULL,"ddd","ddd",MB_OK);?? 或MessageBox(hWnd,"ddd","ddd",MB_OK); hWnd为某窗口的句柄,或者直接用AfxMessageBox。
?
===================================MEssageDLG=============
procedure TForm1.Button1Click(Sender: TObject);
var
S:string;
begin
if MessageDlg('提示框',mtInformation,[mbok,mbyes],0)=mryes then
????? messagebeep(MB_ICONEXCLAMATION);
end;
TMsgDlgType = (mtWarning, mtError, mtInformation, mtConfirmation, mtCustom);
TMsgDlgBtn = (mbYes, mbNo, mbOK, mbCancel, mbAbort, mbRetry, mbIgnore,
??? mbAll, mbNoToAll, mbYesToAll, mbHelp);
const
mrNone???? = 0;
mrOk?????? = idOk;
mrCancel?? = idCancel;
mrAbort??? = idAbort;
mrRetry??? = idRetry;
mrIgnore?? = idIgnore;
mrYes????? = idYes;
mrNo?????? = idNo;
mrAll????? = mrNo + 1;
mrNoToAll = mrAll + 1;
mrYesToAll = mrNoToAll + 1;