如何找出浏览器当前所在的URL [英] How to find out in which URL the browser is currently

查看:116
本文介绍了如何找出浏览器当前所在的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!我的程序用于捕获浏览器(opera,IE,firefox,chrome)上的鼠标行为.所以我坐了一个全局鼠标钩,现在我知道鼠标指针在哪里,即鼠标指针下方的窗口是否是浏览器.因此,当点击在浏览器中被捕获时,我知道以下内容:
1.浏览器窗口句柄
2.浏览器窗口进程ID

问题是如何检索浏览器所在的URL?"

请不要告诉我使用SPY ++"之类的东西,因为我已经尝试过这样做,但是失败了:(
我也试图将javascript命名为"location.href",并且...无用(我对javascript不了解.也许做错了什么)
并最终尝试使用IWebBrowser2 ...,但是get_LocationURL返回一个空字符串.这是用于IE的代码:

Hi all! My program is for the capturing mouse behavior on the browsers(opera, IE, firefox, chrome). So I sat a global mouse hook, and now I know where the mouse pointer is , i.e. is the window under the mouse pointer a browser or not. So, when the click is caught on a browser I know the following:
1. browser window handle
2. the browser window process ID

the question is "how can I retrieve the URL in which the browser is?"

please, don''t tell me "use SPY++" or something like that, because I''ve already tried to do that, but failed :(
Also I tried to call javascript "location.href", and... nothing usable (I know nothing in javascript.. maybe do something wrong)
and finally tried to use IWebBrowser2... but get_LocationURL returns an empty string. here is the code (for IE):

<br />
	IWebBrowser2 *pIwb;<br />
	OleInitialize( 0 );<br />
	CoCreateInstance( CLSID_InternetExplorer, NULL, CLSCTX_ALL,IID_IWebBrowser2, (void**)&pIwb );<br />
	if( pIwb )<br />
	{<br />
		VARIANT vEmpty;<br />
		VARIANT_BOOL bBusy = VARIANT_TRUE;<br />
		VariantInit( &vEmpty );<br />
<br />
		HINSTANCE hIEInstance = LoadLibrary( "atl.dll" );<br />
<br />
		AttachCtrl AtlAxAttachControl = (AttachCtrl)GetProcAddress( hIEInstance, "AtlAxAttachControl" );<br />
<br />
		HWND hWnd = ::GetForegroundWindow();<br />
		HRESULT hResult = AtlAxAttachControl( pIwb, hWnd , 0 );<br />
<br />
		CComBSTR bufferScript;<br />
		hResult = pIwb->get_LocationURL( &bufferScript );<br />
                /*hResult gets value 1 here*/<br />
<br />
		SysFreeString( bufferScript );<br />
<br />
		pIwb->Quit();<br />
		pIwb->Release();<br />
<br />
		FreeLibrary( hIEInstance );<br />
	}<br />



我希望有人能为我提供一段代码,以完成这项工作.



I hope somebody will provide me a piece of code, which will do this job

推荐答案

更多建议,但是有了浏览器窗口的句柄,您能否浏览一下子窗口,直到您进入其中包含URL的控件?识别这可能需要一些努力,但是使用该句柄,一个简单的GetWindowText应该会获得您想要的URL.
More of a suggestion, but with the browser window handle, could you walk through the child windows till you come to the control that contains the URL in it? Identifying this may take some effort, but with that handle, a simple GetWindowText should get the URL you are after.


这篇关于如何找出浏览器当前所在的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆