delphi中WebBrowser的parent改變時變成空白問題的解決(覆蓋CreateWnd和DestroyWnd)
阿新 • • 發佈:2017-07-24
classes panel replace orm cat art topic alt 解決
這段時間在做一個delphi界面打開網頁的功能,且此網頁所在窗口可完整顯示,可縮小到另一個窗口的panel上顯示
可是在改變網頁所在窗口時,WebBrowser控件變成了空白
上網google了半天,終於在csdn上查到了解決方案:
原帖地址:http://bbs.csdn.NET/topics/200046109
[Delphi] view plain copy
- uses
- SHDocVw, Windows, Controls, Forms, Classes;
- type
- TMyWebBrowser = class(TWebBrowser)
- private
- protected
- ActualHandle: HWND;
- procedure CreateWnd; override;
- procedure DestroyWnd; override;
- public
- end;
- { TMyWebBrowser }
- procedure TMyWebBrowser.CreateWnd;
- begin
- if (ActualHandle <> 0) and IsWindow(ActualHandle) then
- begin
- WindowHandle := ActualHandle;
- ActualHandle := 0;
- Windows.SetParent(WindowHandle, TWinControl(Self).Parent.Handle);
- //Force a resize on the client window
- MoveWindow(WindowHandle, 0, 0, TWinControl(Self).Parent.Width,
- TWinControl(Self).Parent.Height, true);
- end
- else
- inherited;
- end;
- procedure TMyWebBrowser.DestroyWnd;
- begin
- if (csDestroying in ComponentState) then
- inherited
- else
- begin
- //Parent to the Application window which is 0x0 in size
- Windows.SetParent(WindowHandle, Forms.Application.Handle);
- //save the WindowHandle
- ActualHandle := WindowHandle;
- //set it to 0 so Createwnd will be called again...
- WindowHandle := 0;
- end;
- end;
http://blog.csdn.net/youthon/article/details/8450610
delphi中WebBrowser的parent改變時變成空白問題的解決(覆蓋CreateWnd和DestroyWnd)