全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1870
推到 Plurk!
推到 Facebook!

得到了IWebBrowser2,有辦法知道Toolbar的高度嗎?

缺席
djunny
一般會員


發表:1
回覆:1
積分:0
註冊:2007-11-26

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-12-11 22:07:53 IP:220.169.xxx.xxx 訂閱
因為要用鼠標定位IE里得到IE的Iwebbrowser2接口,用IHTMLDocument2 的elementFromPoint(X,y)得到當前坐標裏邊的HTML元素,
所以,初步思路是將獲得
當前鼠標.Y坐標-IE.TOP-IE.工具欄高度得到X
當前鼠標.X坐標-IE.Left

這樣可能還不太准確,如果各位大有其它好辦法,還望指點迷津,謝謝!

===============

我找到这个方法:
Windows.ScreenToClient(IE.hwnd, p);
但好像定位还是不对?

我测试的源码:


[code delphi]
function GetIEFromHWND(WHandle: HWND; var IE: IWebBrowser2;var pDoc: IHTMLDocument2): HRESULT;
var
hInst: HWND;
lRes: Cardinal;
MSG: Integer;
ServiceProvider : IServiceProvider;
begin
try
MSG := RegisterWindowMessage('WM_HTML_GETOBJECT');
SendMessageTimeOut(WHandle, MSG, 0, 0, SMTO_ABORTIFHUNG, 1000, lRes);
Result := ObjectFromLresult(lRes, IHTMLDocument2, 0, pDoc);
if Result = S_OK then
begin
(pDoc.parentWindow as IServiceprovider).QueryService(IWebBrowserapp, IWebbrowser2, IE);
end;
finally
FreeLibrary(hInst);
end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
p:tpoint;
i :hwnd;
buffer: array[0..255] of char;
IE: IWebBrowser2;
Doc2 : IHTMLDocument2;
PELE:IHTMLELEMENT;
ShWin:IShellWindows;
j : integer;
Wb:IWebBrowser2;
function GetWBHTMLCode(ACode: Tstrings): Boolean;
var
ps: IPersistStreamInit;
ss: TStringStream;
sa: IStream;
s: string;
begin
ps := Doc2 as IPersistStreamInit;
s := '';
ss := TStringStream.Create(s);
try
sa := TStreamAdapter.Create(ss, soReference) as IStream;
Result := Succeeded(ps.Save(sa, True));
if Result then
if LowerCase(doc2.charset) ='utf-8' then
ACode.Add(UTF8Decode(ss.Datastring))
else
ACode.Add(ss.Datastring);//UTF8Decode
finally
ss.Free;
end;
end;
begin
GetCursorPos(p);
i:=WindowFromPoint(p);
if i <> 0 then
begin
memo1.Lines.Clear;
memo2.Lines.Clear;
memo3.Lines.Clear;
//ChildHwnd := ChildWindowFromPoint(I, P);
//memo2.Lines.Add(IntToStr(ChildHwnd));
GetClassName(i, buffer, 255);
Label1.Caption:='类名:' string(buffer) ' '
'txt:' GetText(i) ' '
'句柄:' inttostr(i);
caption:='handle is:' inttostr(i);
//EnumChildWindows(i,@EnumChildWindowsProc, 0);
GetIEFromHWND(i, IE, Doc2);
//EnumChildWindows(ie.hwnd,@EnumChildWindowsProc, 0);
if Assigned(IE) then
begin
Windows.ScreenToClient(IE.hwnd, p);
Label3.Caption:='IEHeight:' IntToStr(IE.Height) ';IEWidth:' IntToStr(IE.Width) #13#10
'NowposX:' IntToStr(p.X) ',NowposY:' IntToStr(p.y-90) ',';
ELE := Doc2.elementFromPoint(p.x, p.y);
PELE:= ELE.parentElement;
while assigned(PELE) do
begin
memo2.Lines.Add(PELE.tagName);
PELE:= PELE.parentElement;
end;
if Assigned(ELE) then
begin
if ELE.tagName='IFRAME' then
begin
ELE.QueryInterface(IWebBrowser2, IE);
IE.Document.QueryInterface(IHTMLDOCUMENT2, Doc2);
memo1.Lines.Add(Doc2.body.innerText);
memo3.clear;
GetWBHTMLCode(Memo3.lines);
end
else begin
memo1.Lines.Add(ELE.innerText);
end;
end else begin
memo1.Lines.Add(Doc2.body.innerText);
end;
if Assigned(ELE) then
Label2.Caption:= ELE.tagName;
end;
end;
end;
[/code]
編輯記錄
djunny 重新編輯於 2008-12-11 22:26:25, 註解 無‧
djunny
一般會員


發表:1
回覆:1
積分:0
註冊:2007-11-26

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-12-16 14:07:06 IP:220.169.xxx.xxx 訂閱
解决了,
Windows.ScreenToClient(IE.hwnd, p);
改成:
Windows.ScreenToClient(I, p);
呵,就可以了!
系統時間:2024-04-20 4:40:28
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!