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

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

问题描述

在firefox中检测URL我使用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;

这段代码完美无缺!但是连接速度太慢(dde.Connect();)太慢了7/8秒!
是否有另一种方法从firefox获取url?(例如使用像SendMessage这样的API窗口)

解决方案

对于我来说:
$ b $ pre $ AutomationElement元素= AutomationElement.FromHandle(intPtr); // intPtr是FireFox浏览器的MainWindowHandle
元素=元素.FindFirst(TreeScope.Subtree,
新AndCondition(
新PropertyCondition(AutomationElement.NameProperty,搜索或输入地址),
新PropertyCondition(AutomationElement.ControlTypeProperty,ControlType.Edit )));
string url =((ValuePattern)element.GetCurrentPattern(ValuePattern.Pattern))。Current.Va lue as string;


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;

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")

解决方案

This works well for me:

                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天全站免登陆