小米4a开发者选项在哪:请教:delphi中application.messagebox和messagebox有什么区别?

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/28 04:02:24
我刚学delphi,很多不懂,请教老师们
请教:delphi中application.messagebox和messagebox有什么区别?
为什么messagebox(’测试’,’测试’,mb_ok);编译不能通过?
而application.messagebox(’测试’,’测试’,mb_ok)可以,
messagebox(0,’测试’,’测试’,mb_ok)也可以?

Application是Form单元的一个全局对象
具体实现是
----------------------
function TApplication.MessageBox(const Text, Caption: PChar; Flags: Longint): Integer;
var
ActiveWindow: HWnd;
WindowList: Pointer;
MBMonitor, AppMonitor: HMonitor;
MonInfo: TMonitorInfo;
Rect: TRect;
FocusState: TFocusState;
begin
ActiveWindow := GetActiveWindow;
MBMonitor := MonitorFromWindow(ActiveWindow, MONITOR_DEFAULTTONEAREST);
AppMonitor := MonitorFromWindow(Handle, MONITOR_DEFAULTTONEAREST);
if MBMonitor <> AppMonitor then
begin
MonInfo.cbSize := Sizeof(TMonitorInfo);
GetMonitorInfo(MBMonitor, @MonInfo);
GetWindowRect(Handle, Rect);
SetWindowPos(Handle, 0,
MonInfo.rcMonitor.Left + ((MonInfo.rcMonitor.Right - MonInfo.rcMonitor.Left) div 2),
MonInfo.rcMonitor.Top + ((MonInfo.rcMonitor.Bottom - MonInfo.rcMonitor.Top) div 2),
0, 0, SWP_NOACTIVATE or SWP_NOREDRAW or SWP_NOSIZE or SWP_NOZORDER);
end;
WindowList := DisableTaskWindows(0);
FocusState := SaveFocusState;
if UseRightToLeftReading then Flags := Flags or MB_RTLREADING;
try
Result := Windows.MessageBox(Handle, Text, Caption, Flags);
finally
if MBMonitor <> AppMonitor then
SetWindowPos(Handle, 0,
Rect.Left + ((Rect.Right - Rect.Left) div 2),
Rect.Top + ((Rect.Bottom - Rect.Top) div 2),
0, 0, SWP_NOACTIVATE or SWP_NOREDRAW or SWP_NOSIZE or SWP_NOZORDER);
EnableTaskWindows(WindowList);
SetActiveWindow(ActiveWindow);
RestoreFocusState(FocusState);
end;
end;
---------------------------------

MessageBox是Windows单元的函数
可以看到Application.MessageBox调用了Windows.MessageBox

编译时要包含相应的单元
比如用到Application.Messagebox就包含Form
用到MessageBox要包含WIndows

有什么问题可以研究一下
borland\delphi\source\vcl中的源码
会学到不少东西