实时监控当前活动的浏览器的url?

nodirection 2011-11-19 01:40:29
最近要做一个监控网页的软件,我是想得到当前桌面最顶层或者活动的是浏览器,且浏览器的url是我要我监控的网址,比如www.baidu.com。如果是我要的网址就输出。。我要用vc来做。。各位高手请教教我吧。。

网上找了些代码比如:
HWND hWorker,hRebar,hComEx,hcom,hEdit;
HWND hwndParent=(HWND)FindWindow("IEFrame",0);//找到IE窗口
TCHAR szError[260];
hWorker=(HWND)FindWindowEx(hwndParent,0,"WorkerW",0);//找到工作区窗口(不是internet explorer server窗口)
hRebar=(HWND)FindWindowEx(hWorker,0,"ReBarWindow32",0);//找到Rebar窗口
hComEx=(HWND)FindWindowEx(hRebar,0,"Address Band Root",0);//找到Comboboxex
//hcom=(HWND)FindWindowEx(hComEx,0,"ComboBox",NULL);//找到combobox
hEdit=(HWND)FindWindowEx(hComEx,0,"Edit",NULL);//找到ComBoBox的edit控件句柄
::SendMessage(hEdit,WM_GETTEXT,260,(LPARAM)szError);
TCHAR bb[200];
//获取标题
::SendMessage(hIE,WM_GETTEXT,200,(LPARAM)bb);

AfxMessageBox(szError);

却得的是空值,谁帮帮我啊。。。。
...全文
384 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
shen_wei 2011-11-21
  • 打赏
  • 举报
回复
你可以用spy++看看你IE的流程顺序。。。
这个是我IE8的流程
WCHAR wIEText[255] = {0},wIEURL[255] = {0};	
CWnd *IEhwnd =FindWindow(_T( "IEFrame"),NULL);
HWND hwnd = IEhwnd->GetSafeHwnd();
if(hwnd)
{
::SendMessage(hwnd,WM_GETTEXT,255,(LPARAM)wIEText);
HWND hwnd2=::FindWindowEx(hwnd,NULL,_T("WorkerW"),NULL);
HWND hwnd3=::FindWindowEx(hwnd2,NULL,_T("ReBarWindow32"),NULL);
HWND hwnd4=::FindWindowEx(hwnd3,NULL,_T("ComboBoxEx32"),NULL);
//HWND hwnd5=::FindWindowEx(hwnd4,NULL,_T("ComboBox"),NULL);
//HWND hwnd6=::FindWindowEx(hwnd5,NULL,_T("Edit"),NULL);
HWND hwnd5=::FindWindowEx(hwnd3,NULL,_T("Address Band Root"),NULL);
HWND hwnd6=::FindWindowEx(hwnd5,NULL,_T("Edit"),NULL);

::SendMessage(hwnd6,WM_GETTEXT,255,(LPARAM)wIEURL);
// AfxMessageBox(sz);
}
nodirection 2011-11-21
  • 打赏
  • 举报
回复
shen_wei大哥,真的可以哦。哈哈,太感谢你了。。之前我是用多字节字符集,刚才用unicode字符集。就可以了。。。小弟还有一个问题,如何检测我电脑桌面最顶层是ie浏览器,我是想检测谁现在是用着ie浏览器。。问题解决,我给你高分。。。。小弟再次感谢大哥了。。。
nodirection 2011-11-21
  • 打赏
  • 举报
回复
我试试看,谢谢shen_wei大哥。。
nodirection 2011-11-19
  • 打赏
  • 举报
回复
// getURL.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "getURL.h"

//#import <shdocvw.dll>
#include <mshtml.h>
#include <oleacc.h>
#include <atlbase.h>



#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// The one and only application object

CWinApp theApp;

using namespace std;


int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;

// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
long ies;
::CoInitialize(NULL);
CComPtr< IShellWindows > spShellWin;
HRESULT hr = spShellWin.CoCreateInstance( CLSID_ShellWindows );
if(SUCCEEDED(hr))
{
spShellWin->get_Count(&ies); //获取当前IE数目
// if(!ies) return bret;

for(int i=1; i<ies; i++)
{
CComPtr< IDispatch > pDispIE;
HRESULT hr=spShellWin->Item( CComVariant( (long)i ), &pDispIE );
if ( FAILED ( hr ) ) continue;

CComQIPtr< IWebBrowser2 > pBrowser = pDispIE;
if ( !pBrowser ) continue;

CComPtr < IDispatch > pDispDoc;
hr = pBrowser->get_Document( &pDispDoc );
if ( FAILED ( hr ) ) continue;

CComQIPtr< IHTMLDocument2 > pDocument2 = pDispDoc;
if ( !pDocument2 ) continue;

CComBSTR bstrURL=NULL;
CString str1,str2;
pDocument2->get_URL( &bstrURL );//获得url
str1=bstrURL;
pDocument2->get_title(&bstrURL);
str2=bstrURL;
AfxMessageBox(str1+str2);
//HWND hWnd = ::GetForegroundWindow();
//HWND hChildWnd = ::GetTopWindow(hWnd);


}
}


}
::CoUninitialize();

return nRetCode;
}
这个代码是可以得到网址,但是怎么知道最顶层的是IE浏览器,并且是我要求的网址呢?
nodirection 2011-11-19
  • 打赏
  • 举报
回复
我不想这样做,谢谢你
oyljerry 2011-11-19
  • 打赏
  • 举报
回复
还是做成IE的BHO插件吧

18,363

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧