//
我们还可以像IE开发工具条一样,点击某一个节点,在IE上面高亮显示
bool
HTMLElementRect(IHTMLElement
*
pElement, RECT
&
rect)
{
memset(
&
rect,
0
,
sizeof
(rect));
if
( pElement
==
NULL )
return
false
;
pElement
->
get_offsetWidth(
&
rect.right);
pElement
->
get_offsetHeight(
&
rect.bottom);
IHTMLElement
*
pParentElement
=
NULL,
*
pTemp;
pParentElement
=
pElement;
pParentElement
->
AddRef();
long
lx
=
0
, ly
=
0
;
do
{
pParentElement
->
get_offsetTop(
&
ly);
pParentElement
->
get_offsetLeft(
&
lx);
rect.left
+=
lx;
rect.top
+=
ly;
CComQIPtr
<
IHTMLElement2
>
pElement2
=
pParentElement;
pElement2
->
get_scrollLeft(
&
lx);
pElement2
->
get_scrollTop(
&
ly);
rect.left
-=
lx;
rect.top
-=
ly;
pParentElement
->
get_parentElement(
&
pTemp);
pParentElement
->
Release();
pParentElement
=
pTemp;
}
while
(pParentElement);
return
true
;
}
void
CHTMLCodeDlg::FocusElement()
{
//
TODO : Add Code for control notification handler.
WTL::CTreeViewCtrlEx ctrl
=
GetDlgItem(IDC_TREE1);
CTreeItem item
=
ctrl.GetSelectedItem();
IHTMLElement
*
pItem
=
(IHTMLElement
*
)item.GetData();
RECT rect;
HTMLElementRect(pItem, rect);
long
nBrowser
=
0
;
m_pParent
->
m_spWebBrowser2
->
get_HWND(
&
nBrowser);
HWND hWndParent
=
(HWND)nBrowser;
hWndParent
=
FindWindowEx(hWndParent, NULL,
"
Shell DocObject View
"
, NULL);
if
(hWndParent)
{
hWndParent
=
FindWindowEx(hWndParent, NULL,
"
Internet Explorer_Server
"
, NULL);
}
//
得到IE的节点。仅针对IE6
HDC hdc
=
::GetDC(hWndParent);
HBRUSH hBrush;
hBrush
=
CreateSolidBrush(RGB(
255
,
0
,
0
));
CBrush pBrush((HBRUSH)GetStockObject(NULL_BRUSH));
SelectObject(hdc, CreatePen(PS_DASHDOTDOT,
1
, RGB(
0
,
0
,
255
)));
SelectObject(hdc,GetStockObject(NULL_BRUSH));
{
::Rectangle(hdc, rect.left, rect.top, rect.left
+
rect.right, rect.top
+
rect.bottom);
Sleep(
400
);
SetROP2(hdc,R2_NOTXORPEN);
::Rectangle(hdc, rect.left, rect.top, rect.left
+
rect.right, rect.top
+
rect.bottom);
SetROP2(hdc,R2_NOTXORPEN);
}
::DeleteObject(hBrush);
::ReleaseDC(hWndParent, hdc);
}