如何使用webbrowser的execwb方法,奉献200分,急!急!(200分)

  • 主题发起人 主题发起人 宋海涛
  • 开始时间 开始时间

宋海涛

Unregistered / Unconfirmed
GUEST, unregistred user!
本人的程序中使用了webbrowser控件,并其调用execwb方法来实现打印、
拷贝、粘贴等功能,例如:
webbrowser1.ExecWB(OLECMDID_CUT, OLECMDEXECOPT_DODEFAULT);
可是程序总是引发异常并提示‘试图撤消一个未注册的拖放目标’,换成
其它参数也一样,这是怎么回事,请哪位高手赐教。
 
用_Copy试一下,_cut要删除原内容在web中可能不行。
 
webbrowser的bug很多(本论坛有很多贴子),最好不要用,换一个吧。
 
>>宋海涛
这是我以前做的,用的很好的,没有出错,你试试吧。
procedure Tmainfrm.saveicoClick(Sender: TObject);
var //保存当前页面到...;
pvaIn,pvaOut: OLeVariant;
begin
timer1.Enabled :=false;
try
pvaIn := NULL;
pvaOut := NULL;
WebBrowser1.ExecWB(OLECMDID_SAVEAS,OLECMDEXECOPT_PROMPTUSER,pvaIn,pvaOut);
except
on EOleException do DoNothing;//ShowMessage('请安装IE 5.0!');
end;
end;

procedure TMainFrm.mPrintSetupClick(Sender: TObject);
var //打印页面设置;
pvaIn,pvaOut: OLeVariant;
begin
timer1.Enabled :=false;
try
pvaIn := NULL;
pvaOut := NULL;
WebBrowser1.ExecWB(OLECMDID_PAGESETUP,OLECMDEXECOPT_PROMPTUSER,pvaIn,pvaOut);
except
on EOleException do DoNothing;//ShowMessage('请安装打印机!');
end;
end;
 
在“End.”之前加入下面两句
initialization
OleInitialize(nil);

finalization
OleUninitialize;
 
来自:hubdog 时间:00-4-9 12:08:19 ID:216196
var
Form1: TForm1;
FOleInPlaceActiveObject: IOleInPlaceActiveObject;
SaveMessageHandler: TMessageEvent;

...

implementation

...

procedure TForm1.FormActivate(Sender: TObject);
begin
SaveMessageHandler := Application.OnMessage;
Application.OnMessage := MyMessageHandler;
end;

procedure TForm1.FormDeactivate(Sender: TObject);
begin
Application.OnMessage := SaveMessageHandler;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Application.OnMessage := SaveMessageHandler;
FOleInPlaceActiveObject := nil;
end;

procedure TForm1.MyMessageHandler(var Msg: TMsg; var Handled: Boolean);
var
iOIPAO: IOleInPlaceActiveObject;
Dispatch: IDispatch;
begin
{ exit if we don't get back a webbrowser object }
if WebBrowser = nil then
begin
Handled := False;
Exit;
end;

Handled:=(IsDialogMessage(WebBrowser.Handle, Msg) = True);

if (Handled) and (not WebBrowser.Busy) then
begin
if FOleInPlaceActiveObject = nil then
begin
Dispatch := WebBrowser.Application;
if Dispatch <> nil then
begin
Dispatch.QueryInterface(IOleInPlaceActiveObject, iOIPAO);
if iOIPAO <> nil then
FOleInPlaceActiveObject := iOIPAO;
end;
end;

if FOleInPlaceActiveObject <> nil then
if ((Msg.message = WM_KEYDOWN) or (Msg.message = WM_KEYUP)) and
((Msg.wParam = VK_BACK) or (Msg.wParam = VK_LEFT) or (Msg.wParam = VK_RIGHT)) then
//nothing - do not pass on Backspace, Left or Right arrows
else
FOleInPlaceActiveObject.TranslateAccelerator(Msg);
end;
end;

--------------------------------------------------------------------------------
来自:hubdog 时间:00-4-9 12:09:45 ID:216197
You have to add the following line to the bottom of your unit:

initialization
OleInitialize(nil);

finalization
OleUninitialize;

 
多人接受答案了。
 
怎样保存到程序指定的路径,不弹出保存对话框呀,我试着把OLECMDID_saveas改成OLECMDID_save
执行时没有报错,可实际上根本就没有保存。
 
OLECMDID_save是在你修改了当前浏览的网页后保存用的。
 
后退
顶部