2013-03-16 3 views
2

를 사용하기 위해 나는이 코드는 완벽하게 작동 C#을 파이어 폭스에서 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

사용하는 파이어 폭스에서 URL을 검색 할 수없는!하지만 (dde.Connect();) 연결에 대한 너무 느립니다 7/8 초 너무 느립니다! Firefox에서 URL을 가져 오는 다른 방법이 있습니까? 이것은 나를 위해 잘 작동

+0

sendMessage 첨부는 너무 깨지기 쉬운 것입니다. UI의 컨트롤 이름이 모두 동일하게 유지된다는 보장은 없습니다. 사실, 파이어 폭스가 완전히 새롭게 디자인 된만큼, 나는 이미 여러 번 바뀌었을 것이다. –

+0

http://stackoverflow.com/questions/5317642/retrieve-current-url-from-c-sharp-windows-form을 살펴 보셨습니까? –

답변

1

(예는 "sendMessage 첨부"와 같은 API 창을 사용) :

   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; 
2
  Process[] process = Process.GetProcessesByName("firefox"); 

      foreach (Process firefox in process) 
      { 
       // the chrome process must have a window 
       if (firefox.MainWindowHandle == IntPtr.Zero) 
       { 
        return null; 
       } 

       AutomationElement element = AutomationElement.FromHandle(firefox.MainWindowHandle); 
       if (element == null) 
        return null; 

       //search for first custom element 
       AutomationElement custom1 = element.FindFirst(TreeScope.Descendants, 
       new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Custom)); 

       //search all custom element children 
       AutomationElementCollection custom2 = custom1.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Custom)); 

       //for each custom child 
       foreach (AutomationElement item in custom2) 
       { 
        //search for first custom element 
        AutomationElement custom3 = item.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Custom)); 
        //search for first document element 
        AutomationElement doc3 = custom3.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document)); 



        if (!doc3.Current.IsOffscreen) 
        { 
         url = ((ValuePattern)doc3.GetCurrentPattern(ValuePattern.Pattern)).Current.Value as string; 
         return url; 
        }      
       } 
      }    
      return url; 
    } 
관련 문제