把以下代码放在有WebBrowser控件的窗口最后一个End前面:
initialization
oleinitialize(nil);
finalization
oleuninitialize;
转载于:http://blog.sina.com.cn/s/blog_62dcdf1a0100qu7d.html
4、webbrowser控件显示网页遇到页面内有关闭窗口脚本问题
问题讨论网址: http://bbs.csdn.net/topics/390229795
解决办法网址:http://www.cnblogs.com/dlwang2002/archive/2007/04/14/713499.html
代码:
//webbrowser控件显示网页遇到页面内有关闭窗口脚本问题。运行完后执行Window Close的提示
var
vDefInetExplorerServerProc: Pointer;
function InetExplorerServerWndProc(
hwnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
begin
Result := CallWindowProc(vDefInetExplorerServerProc,
hwnd, Msg, wParam, lParam);
case Msg of
WM_DESTROY:
begin
SetWindowLong(hwnd, GWL_WNDPROC, Integer(vDefInetExplorerServerProc));
ShowMessage('Window Close'); //执行语句
end;
end;
end;
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
var
vShellDocObjViewHandle: THandle;
vInetExplorerServerHandle: THandle;
begin
vShellDocObjViewHandle := GetWindow(TWebBrowser(Sender).Handle, GW_CHILD);
vInetExplorerServerHandle := GetWindow(vShellDocObjViewHandle, GW_CHILD);
if Integer(@InetExplorerServerWndProc) <>
GetWindowLong(vInetExplorerServerHandle, GWL_WNDPROC) then
begin
Integer(vDefInetExplorerServerProc) :=
GetWindowLong(vInetExplorerServerHandle, GWL_WNDPROC);
SetWindowLong(vInetExplorerServerHandle, GWL_WNDPROC,
Integer(@InetExplorerServerWndProc));
end;
end;
//分割线
下面为从网页转载的web控件bug和解决办法参考
请发表评论