这可是embeddedwb自带的demo中的代码,试试看有没有可能吧
unit intercept;
(* 检测用户是否保存了页面,如果不保存则不能编辑
Last Modified : 1-8-2000
Author : Michael Cessna <mcessna@saleslogix.com>
Purpose : This unit is used to subclass the Internet Explorer 5.x Save
Web Page dialog, so that it can be determined if the user
selected Save or Cancel. If the user selected Save, the
entire path+filename is calculated and the file is opened for
editing (the code for opening the file is in the
EditWebBrowserDoc() procedure of the main unit).
*)
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, CommDlg;
type
TFormIntercept = class(TForm)
Timer: TTimer;
procedure TimerTimer(Sender: TObject);
private
{ Private declarations }
OldWndProc: Pointer;
NewWndProc: Pointer;
DialogHWnd: HWND;
public
{ Public declarations }
protected
{ Protected }
procedure NewWndMethod(var Msg: TMessage);
end;
var
FormIntercept: TFormIntercept;
SavedFileName: string;
WasSaved: Boolean;
implementation
{$R *.DFM}
procedure TFormIntercept.NewWndMethod(var Msg: TMessage);
function ParseExtension(const S: string): string;
var
P: Integer;
begin
Result := '';
P := Pos('.TXT', UpperCase(S));
if P > 0 then
begin
Result := '.txt';
Exit;
end;
P := Pos('.HTM', UpperCase(S));
if P > 0 then
begin
Result := '.htm';
Exit;
end;
P := Pos('.MHT', UpperCase(S));
if P > 0 then
begin
Result := '.mht';
end;
end;
var
Path: array[0..MAX_PATH] of WideChar;
ExtBuff: array[0..34] of char;
Extension: string;
RetVal: Integer;
begin
Msg.Result := 0;
case Msg.Msg of
WM_COMMAND:
begin
case Msg.wParam of
1: { The Save button was clicked }
begin
WasSaved := True;
RetVal := SendMessage(DialogHWnd,
CDM_GETFILEPATH,
SizeOf(Path),
Integer(@Path)
);
if RetVal >= 0 then
begin
if Win32Platform = VER_PLATFORM_WIN32_NT then
begin
{ Handle the UNICODE string on NT }
SavedFileName := PWideChar(Pointer(@Path));
end
else
begin
SavedFileName := PChar(Pointer(@Path));
end;
if ExtractFileExt(SavedFileName) = '' then
begin
GetDlgItemText(DialogHWnd, 1136, ExtBuff, SizeOf(ExtBuff));
Extension := ParseExtension(StrPas(@ExtBuff));
SavedFileName := SavedFileName + Extension;
end;
end;
end;
2: { Dialog was canceled (via either 'Cancel', 'X', or ALT+F4) }
begin
WasSaved := False;
end;
end;
end;
WM_DESTROY:
begin
if Assigned(NewWndProc) then
begin
FreeObjectInstance(NewWndProc);
SetWindowLong(DialogHWnd,
GWL_WNDPROC,
Longint(OldWndProc)
);
end;
end;
end;
Msg.Result := CallWindowProc(OldWndProc,
DialogHWnd,
Msg.Msg,
Msg.WParam,
Msg.LParam
);
end;
procedure TFormIntercept.TimerTimer(Sender: TObject);
begin
DialogHWnd := FindWindow('#32770', '保存 Web 页');
if DialogHWnd > 0 then
begin
if (GetParent(DialogHWnd) = Application.MainForm.Handle) and IsWindow(DialogHWnd) then
begin
Timer.Enabled := False;
SavedFileName := '';
WasSaved := False;
NewWndProc := MakeObjectInstance(NewWndMethod);
OldWndProc := Pointer(SetWindowLong(DialogHWnd,
GWL_WNDPROC,
Longint(NewWndProc))
);
end;
end;
end;
end.