MessageBox和MessageDlg(33分)

  • 主题发起人 主题发起人 千中元
  • 开始时间 开始时间

千中元

Unregistered / Unconfirmed
GUEST, unregistred user!
Messagebox,api<br>&nbsp; &nbsp;试验: &nbsp; <br>&nbsp; &nbsp;begin<br>&nbsp;messagebox(handle,'no thread',nil,MB_OKCANCEL);<br>&nbsp; &nbsp;end;<br>问题1:运行后弹出的小信息窗体的caption总是"错误...",能不能"警告","消息"....等<br>&nbsp; &nbsp; &nbsp; 通过改变哪个参数改变?<br>问题2:能否实现类似MessageDlg的功能,比如,如果选择OK,则执行A动作,<br>&nbsp; &nbsp; &nbsp; 选择cancel则执行B动作?<br>&nbsp;
 
1. var x:integer<br>&nbsp; begin<br>&nbsp; x:=Application.MessageBox('试试看','消息框',MB_OK+MB_ICONSTOP);<br>&nbsp; end;<br>2. 上例返回 x=IDOK(就是1),表示用户选中了“确定”
 
IDABORT;IDCANCEL ;IDIGNORE ; IDNO ;IDOK ;IDRETRY ;IDYES <br>if IDOK就是1,那么IDABORT,IDIGNORE....是多少?<br>这次是真的没找到!
 
算了算了,也不贴出帮助了,你自己看看吧
 
贴出来吧,看的我晕
 
function MessageBox(Text, Caption: PChar; Flags: Longint): Integer;<br><br>Description<br><br>Use MessageBox to displays a generic dialog box a message and one or <br>more buttons. Caption is the caption of the dialog box and is optional.<br><br>MessageBox is an encapsulation of the Windows API MessageBox <br>function. TApplication抯 encapsulation of MessageBox automatically <br>supplies the missing window handle parameter needed for the Windows <br>API function.<br><br>The value of the Text parameter is the message, which can be longer<br>&nbsp;than 255 characters if necessary. Long messages are automatically wrapped in the message box. The value of the Caption property is the <br>caption that appears in the title bar of the dialog box. Captions can <br>be longer than 255 characters, but they don't wrap. A long caption <br>results in a wide message box.<br><br>To see the possible values of the Flags parameter, see the MessageBox<br>&nbsp;function in the Windows API Help file. The corresponding parameter <br>on that Help screen is called TextType. The values determine the <br>buttons that appear in the message box and the behavior of the message box. The values can be combined to obtain the desired effect.<br><br><br>The return value of the MessageBox method is 0, if there wasn't <br>enough memory to create the message box, or one of these values:<br><br>Value Numeric value Meaning<br><br>IDABORT 3 The user chose the Abort button.<br>IDCANCEL 2 The user chose the Cancel button.<br>IDIGNORE 5 The user chose the Ignore button.<br>IDNO 7 The user chose the No button.<br>IDOK 1 The user chose the OK button.<br>IDRETRY 4 The user chose the Retry button.<br>IDYES 6 The user chose the Yes button.<br><br>注意最后7行<br><br>
 
faint,你自己下在的帮助,在Oicq上让我看什么最后7行:(
 
帮助发给你,继续写文稿。
 
MessageBox这个我最常用问我就对了。<br>TApplication类中封装的MessageBox是直接调用Windows API的,两者的差别就是Tapplication省去了一个从String转到PChar的过程。这给调用者带来了一定的方便。<br>以下是WINDOWS API HELP中MessageBox的解释。<br>如果追求是一些个性化的东西还可以使用<br>MessageBox在WINDOWS API中的函数原型如下:<br>int MessageBox(<br><br>&nbsp; &nbsp; HWND hWnd, // handle of owner window<br>&nbsp; &nbsp; LPCTSTR lpText, // address of text in message box<br>&nbsp; &nbsp; LPCTSTR lpCaption, // address of title of message box &nbsp;<br>&nbsp; &nbsp; UINT uType // style of message box<br>&nbsp; &nbsp;);<br>Handle参数是显示时基于的窗口句柄,如果为0则自己新开一个窗口。一般如果无法确定当前窗口<br>的句则需要调用GetForegroundWindow函数返回。<br>其uTupe参数一般有如下几个。<br>MB_ABORTRETRYIGNORE<br>MB_OK<br>MB_OKCANCEL<br>MB_RETRYCANCEL<br>MB_YESNO<br>MB_YESNOCANCEL<br>另外在MessageBox中还可以显示特定的图标。<br>MB_ICONEXCLAMATION, <br>MB_ICONWARNING<br>MB_ICONINFORMATION<br>MB_ICONASTERISK<br>MB_ICONQUESTION<br>MB_ICONSTOP, <br>MB_ICONERROR, <br>MB_ICONHAND<br>至于返回结果,只不过是把uTupe参数中的“MB”改成了“ID”,以下是一段演示代码。<br>function TForm1.Demo(Sender:TObject):String;<br>begin<br>&nbsp;case MessageBox(Handle,'您是程序员吗?','提示信息',MB_YESNOCANCEL+MB_ICONQUESTION<br>) of <br>&nbsp; case ID_YES:Result:='是';<br>&nbsp; case ID_NO:Result:='不是';<br>&nbsp; case ID_CANCEL:Result:='程序员是什么工作?';<br>&nbsp;end;<br>end;<br>&nbsp; <br>&nbsp;最近我从中计报的TIPS里看到了一个如何实现显示自己图标的MessageBox也一同贴出来。<br>function MessageBoxLg(Handle:integer;Text,Caption:String;flag:integer):integer;<br>var<br>&nbsp; Msg:TMsgBoxParams;<br>begin<br>&nbsp;Msg.cbSize:=Sizeof(Msg);<br>&nbsp;Msg.hwndOwner:=Handle;<br>&nbsp;Msg.hInstance:=hinstance;<br>&nbsp;Msg.lpszText:=PChar(Text);<br>&nbsp;Msg.lpszCaption:=PChar(Caption);<br>&nbsp;Msg.dwStyle:=flag+MB_USERICON;<br>&nbsp;Msg.lpszIcon:='MAINICON';<br>&nbsp;Msg.dwContextHelpId:=1;<br>&nbsp;Msg.lpfnMsgBoxCallback:=nil;<br>&nbsp;Msg.dwLanguageId:=LANG_NEUTRAL;<br>&nbsp;Result:=integer(MessageBoxIndirect(Msg));<br>end;<br>我要分!!!
 
结束时给请我一分 :)
 
kang,本来都是给你2分呢,应你的强烈要求,改成1分吧
 
死脑筋,不灵活
 
我经常用的是showmessage或者messagedlg, messagebox只是2者的折中产物.<br><br>ShowMessage简单, 真简单, 只有一个string参数, 缺省的是OK按钮.<br><br>MessageDlg好, 真好, 整个Message框都可以自己控制.<br>而且MessageDlg只不过比MessageBox多一点点的参数, 但控制起来简单多了.
 
messagebox('xxxxx','hint',1);<br>messagebox('xxxxx','hint',2);<br>messagebox('xxxxx','hint',3);<br>messagebox('xxxxx','hint',4);<br>messagebox('xxxxx','hint',5);<br>messagebox('xxxxx','hint',6);<br>.....<br><br>if messagebox('xxxxx','hint',1)=1 then<br>...<br>if messagebox('xxxxx','hint',1)=2 then<br>..<br>试一下就知道了<br><br><br>
 
错了,上面是TApplication.MessageBox('xxx','hint',1);<br><br>Messagebox是windows API<br>TApplication.MessageBox是VCL接口<br>&nbsp; 用什么实质性差别吗?<br>showmessage 好象不可以控制caption,我很少用 &nbsp;<br><br>
 
来晚了,能说的都让你们给说了,<br><br>我常用的是。<br><br>Application.MessageBox('你是否继续下一步?','系统提示',292);
 
Application.MessageBox('你是否继续下一步?','系统提示',289);<br>&nbsp; Cancel button is setfocus;<br>Application.MessageBox('你是否继续下一步?','系统提示',1);<br>&nbsp; Ok Button is setfocus;<br><br>&nbsp; Continue... <br><br>&nbsp; &nbsp;<br><br>
 
我也说说:<br>messagebox中第一个参数类型为string,表示你要显示的信息、<br>第二个参数类型为pchar,表示信息框的标题,如果在程序中想用变量来随时<br>改变注意类型转换,比如用pchar(string1)的方式将字串转换为pchar、<br>第三个参数为按钮类型liguang的贴子中已有说明,各常量相加就是你所需要的<br>按钮样式,最好不要用数字常量,不好懂!<br>messagedlg中第一个参数与messagebox相同、<br>第二个参数表示对话框的类型,主要决定对话框中的图标类型、<br>第三个参数表示对话框的按钮,其类型为集合,表述方式[bt1,bt2...]<br>第四个参数表示帮助的指针,如果没有帮助取0。<br>至于showmessage,必须使用application.showmessage('欲显示的信息')<br>其参数类型为string,也只有一个OK按钮。<br><br>
 
后退
顶部