如何得到当前Active的网页URL

snowbirdfly 2009-08-04 04:46:23
通过COM组件,可以得到所有当前打开的IE中所有网页的URL,具体代码参考如下:

SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass();
string filename = "";
foreach ( SHDocVw.InternetExplorer ie in shellWindows )
{
filename = Path.GetFileNameWithoutExtension( ie.FullName ).ToLower();
if ( filename.Equals( "iexplore" ) )
Console.WriteLine( " Web Site : {0}", ie.LocationURL );
}

不过,如何得到当前活动的IE窗口的URL???
不是用ASP.NET,用API来实现.
参考过http://www.cnblogs.com/gleamy_ming/articles/1393287.html,C#通过Win32 API操作IE浏览器--获得IE的URL,不过通过这种方法无法得到数据,因此想请教高手~~~
...全文
289 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
snowbirdfly 2009-08-05
  • 打赏
  • 举报
回复
ZAI DING~~~
snowbirdfly 2009-08-04
  • 打赏
  • 举报
回复
ding~~~
snowbirdfly 2009-08-04
  • 打赏
  • 举报
回复
HttpContext.Current.Request.Url.ToString() 获取到的数据为:
A first chance exception of type 'System.NullReferenceException' occurred in weburl.exe
这个方法测试过,不行的~~~

IntPtr hwndIE =FindWindow("IEFrame",null);
IntPtr hwndWorker = FindWindowEx(new HandleRef(this,hwndIE),new HandleRef(this,IntPtr.Zero), "WorkerW",null);
IntPtr hwndToolbar = FindWindowEx(new HandleRef(this,hwndWorker),new HandleRef(this,IntPtr.Zero), "ReBarWindow32",null);
IntPtr hwndComboboxex = FindWindowEx(new HandleRef(this,hwndToolbar), new HandleRef(this,IntPtr.Zero), "ComboBoxEx32",null);

StringBuilder sb = new StringBuilder(1024);
const int WM_GETTEXT=0x000D;
SendMessage(hwndComboboxex,WM_GETTEXT,sb.Capacity,sb);

这个方法和我给的链接是同个方法啊~~~
jsoner 2009-08-04
  • 打赏
  • 举报
回复
IntPtr hwndIE =FindWindow("IEFrame",null);
IntPtr hwndWorker = FindWindowEx(new HandleRef(this,hwndIE),new HandleRef(this,IntPtr.Zero), "WorkerW",null);
IntPtr hwndToolbar = FindWindowEx(new HandleRef(this,hwndWorker),new HandleRef(this,IntPtr.Zero), "ReBarWindow32",null);
IntPtr hwndComboboxex = FindWindowEx(new HandleRef(this,hwndToolbar), new HandleRef(this,IntPtr.Zero), "ComboBoxEx32",null);

StringBuilder sb = new StringBuilder(1024);
const int WM_GETTEXT=0x000D;
SendMessage(hwndComboboxex,WM_GETTEXT,sb.Capacity,sb);
li365941471 2009-08-04
  • 打赏
  • 举报
回复
BD!
jsoner 2009-08-04
  • 打赏
  • 举报
回复
HttpContext.Current.Request.Url.ToString()
这个是获取当前URL的
snowbirdfly 2009-08-04
  • 打赏
  • 举报
回复
对了,具体的问题和下面的帖子是一样的,
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/e66482c0-6254-47b0-848b-fc1942339bf2

111,096

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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