5,392
社区成员
发帖
与我相关
我的任务
分享
//仅仅适合32位程序
procedure TForm1.FormCreate(Sender: TObject);
var
P : Pointer;
Buf : array [0..7] of Byte;
n : SIZE_T; //低版本的Delphi 定义为 LongWord
begin
P := GetProcAddress(GetModuleHandle('user32.dll'), 'SoftModalMessageBox');
Buf[0] := $B8;
Pinteger(@Buf[1])^ := ID_YES; //设置所有MessageBox的返回值,也可以是ID_NO,ID_OK等,
Buf[5] := $C2;
Buf[6] := $04;
Buf[7] := $00;
WriteProcessMemory(GetCurrentProcess(), P , @Buf, Length(Buf), n);
Application.MessageBox('不会弹出提示框了','AAA', MB_YESNO or MB_ICONWARNING);
end;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, ActiveX;
type
IDocHostShowUI = interface(IUnknown)
['{c4d244b0-d43e-11cf-893b-00aa00bdce1a}']
function ShowMessage(hwnd: THandle; lpstrText: POLESTR; lpstrCaption: POLESTR;dwType: longint; lpstrHelpfile: POLESTR; dwHelpContext: longint;var plResult: LRESULT): HRESULT; stdcall;
function ShowHelp(hwnd: THandle; pszHelpfile: POLESTR; uCommand: integer;dwData: longint; ptMouse: TPoint; var pDispatchObjectHit: IDispatch): HRESULT; stdcall;
end;
TWebBrowser = class(SHDocVw.TWebBrowser,IDocHostShowUI)
protected
function ShowMessage(hwnd: THandle; lpstrText: POLESTR; lpstrCaption: POLESTR;dwType: longint; lpstrHelpfile: POLESTR; dwHelpContext: longint;var plResult: LRESULT): HRESULT; stdcall;
function ShowHelp(hwnd: THandle; pszHelpfile: POLESTR; uCommand: integer;dwData: longint; ptMouse: TPoint; var pDispatchObjectHit: IDispatch): HRESULT; stdcall;
end;
type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TWebBrowser }
function TWebBrowser.ShowHelp(hwnd: THandle; pszHelpfile: POLESTR; uCommand,
dwData: Integer; ptMouse: TPoint; var pDispatchObjectHit: IDispatch): HRESULT;
begin
Result := S_FALSE;
end;
function TWebBrowser.ShowMessage(hwnd: THandle; lpstrText,
lpstrCaption: POLESTR; dwType: Integer; lpstrHelpfile: POLESTR;
dwHelpContext: Integer; var plResult: LRESULT): HRESULT;
begin
plResult := MessageBoxW(hwnd,PWChar(lpstrText),'Title',64);
Result := S_OK;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
WebBrowser1.Navigate('E:/alert.htm');
end;
end.