请教:delphi中application.messagebox和messagebox有什么区别?
我刚学delphi,很多不懂,请教老师们请教:delphi中application.messagebox和messagebox有什么区别?为什么messagebox(’测...
我刚学delphi,很多不懂,请教老师们 请教:delphi中application.messagebox和messagebox有什么区别? 为什么messagebox(’测试’,’测试’,mb_ok);编译不能通过? 而application.messagebox(’测试’,’测试’,mb_ok)可以, messagebox(0,’测试’,’测试’,mb_ok)也可以?
展开
2个回答
展开全部
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中的源码 会学到不少东西
展开全部
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中的源码 会学到不少东西 查看原帖>>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询