【问题标题】:get url from web browser [closed]从网络浏览器获取 url [关闭]
【发布时间】:2010-10-23 20:25:58
【问题描述】:

如何从当前在机器上运行的 Web 浏览器检索列表框的 URL。使用c#

【问题讨论】:

    标签: c#


    【解决方案1】:

    看到这个question,它适用于 c++,但它可能会有所帮助

    【讨论】:

      【解决方案2】:
          [DllImport("user32.dll", SetLastError = true)]
          static extern IntPtr FindWindowEx(IntPtr parentHandle,
          IntPtr childAfter, string className, IntPtr windowTitle);
      
          [DllImport("user32.dll", CharSet = CharSet.Auto)]
          public static extern int SendMessage(IntPtr hWnd,
              int msg, int wParam, StringBuilder ClassName);
      
          private static string GetURL(IntPtr intPtr, string programName, out string url)
          {
              string temp=null;
              if (programName.Equals("chrome"))
              {
                  var hAddressBox = FindWindowEx(intPtr, IntPtr.Zero, "Chrome_OmniboxView", IntPtr.Zero);
                  var sb = new StringBuilder(256);
                  SendMessage(hAddressBox, 0x000D, (IntPtr)256, sb);
                  temp = sb.ToString();
              } 
              if (programName.Equals("iexplore"))
              {
                  foreach (InternetExplorer ie in new ShellWindows())
                  {
                      var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(ie.FullName);
                      if (fileNameWithoutExtension != null)
                      {
                          var filename = fileNameWithoutExtension.ToLower();
                          if (filename.Equals("iexplore"))
                          {
                              temp+=ie.LocationURL + " ";
                          }
                      }
                  }
              }
              if (programName.Equals("firefox"))
             {
                  DdeClient dde = new DdeClient("Firefox", "WWW_GetWindowInfo");
                  dde.Connect();
                  string url1 = dde.Request("URL", int.MaxValue);
                  dde.Disconnect();
                  temp = url1.Replace("\"","").Replace("\0","");
              }
              url = temp;
              return temp;
          }
      

      请执行以下操作以运行此代码 在您的项目中添加来自 VS.NET 的 Reference > Com > Microsoft.Internet.Controls

      http://ndde.codeplex.com/ 下载 DdeClient 类的 bin 并将其添加到您的项目中

      【讨论】:

        猜你喜欢
        • 2014-04-16
        • 2012-10-30
        • 2015-01-07
        • 2011-05-22
        • 2011-02-04
        • 1970-01-01
        • 1970-01-01
        • 2014-12-18
        相关资源
        最近更新 更多