C# 从 Firefox 获取 URL 但不使用 DDE [英] C# get URL from firefox but don't use DDE

查看:26
本文介绍了C# 从 Firefox 获取 URL 但不使用 DDE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了在 firefox 中检测 URL,我使用 DDE

For detect URL in firefox I use DDE

 DdeClient dde = new DdeClient("Firefox", "WWW_GetWindowInfo");
 dde.Connect();
 string url1 = dde.Request("URL", int.MaxValue);
 dde.Disconnect();
 temp = url1.Replace("\"", "").Replace("\0", "");
 dde = null;

这段代码完美运行!,但是对于connect(dde.Connect();)来说太慢了7/8秒!还有另一种方法可以从firefox获取url吗?(例如使用SendMessage"等 API 窗口)

This code works perfectly!, but it is too slow for connect (dde.Connect();) is too slow 7/8 second! Is there another way to get url from firefox? (example use API windows like "SendMessage")

推荐答案

这对我很有效:

                AutomationElement element = AutomationElement.FromHandle(intPtr);  // intPtr is the MainWindowHandle for FireFox browser
                element = element.FindFirst(TreeScope.Subtree,
                      new AndCondition(
                          new PropertyCondition(AutomationElement.NameProperty, "Search or enter address"),
                          new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit)));
                string url = ((ValuePattern)element.GetCurrentPattern(ValuePattern.Pattern)).Current.Value as string;

这篇关于C# 从 Firefox 获取 URL 但不使用 DDE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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