惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
博客园 - Franky
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
L
LangChain Blog
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
AI
AI
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Security @ Cisco Blogs
Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs

博客园 - 伯乐共勉

WIN7下调试IE 记录一些事情 ActiveX Scripting[转] 改进的 CHoverButton 支持focus,四种状态,修复BUG C++学习推荐书目 比较中肯的读书经验[转] ntlm 的 delphi for smtp 深圳公交能有多挤 乱码大全 给老板娘的一封信 一年前的工作日记 预测中国主要赛事夺金亮点 按日程 实战 Firefox 扩展开发 了解数字证书 了解公钥加密 了解 S/MIME - 伯乐共勉 Windows内存与进程管理器底层分析 探索 Windows 2000 的内存管理机制 C++内存管理 windows进程中的内存结构
模拟IE开发工具条一
伯乐共勉 · 2010-04-19 · via 博客园 - 伯乐共勉

用过IE开发工具条的朋友对IE这个工具进行枚举的方式都会有些好奇,它是如何将一个网页中所有的元素都枚举出来的,在网页上,可能大家都学过通过JAVASCRIPT访问DOM对象来取得数据,其实在BHO中是相似的,只是要注意一些事项。

首先,我们肯定是已经定义了一个

CComQIPtr<IWebBrowser2, &IID_IWebBrowser2> m_spWebBrowser2;

而且通过SetSite方法已经将其与IE进行挂接,如果你不清楚这一点,可以在网上查找一篇文章《VC++开发BHO插件——定制你的浏览器

其次,我们新建一个Dialog,并在其上放置一个 TreeViewCtrl,其IDIDC_TREE1

接下来我们就可以通过 m_spWebBrowser2这个成员变量来获取数据了。

 代码

 代码

通过上面的代码,我们就可以将整个HTML的内容生成一个DOM结构放在一个树里面,并且每个节点中都存放了一个IHTMLElement的指针,通过它我们可以做更多的事。

 比如我们可以取得某一个节点的Source

 代码

代码

//我们还可以像IE开发工具条一样,点击某一个节点,在IE上面高亮显示
bool HTMLElementRect(IHTMLElement *pElement, RECT &rect)
{
    memset(
&rect,0sizeof(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(00255)));
    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);
}