如何使用c#从浏览器中检索URL

时间:2009-06-13 09:40:10

标签: c#

我正在使用c#处理Windows应用程序。我想从浏览器中检索URL。但我无法做到这一点。

private void WebListLoad()
{
    ListViewItem lvi;
    Process[] prs = Process.GetProcessesByName("firefox");
    try
    {

    //int handle = int.Parse(Console.ReadLine(), NumberStyles.HexNumber);
    //int txtLength = SendMessage(handle, WM_GETTEXTLENGTH, 0, 0);
    //StringBuilder sb = new StringBuilder(txtLength + 1);
    //SendMessage(handle, WM_GETTEXT, sb.Capacity, sb);


        foreach (Process proces in prs)
        {
            if (proces.MainWindowTitle.Length > 0)
            {
                lvi = listView2.Items.Add(System.Environment.UserName);
                lvi.SubItems.Add("");
                lvi.SubItems.Add(proces.MainWindowTitle.ToString());
                lvi.SubItems.Add(proces.StartTime.ToString());
            }
        }
    }
    catch
    {
    }
}

2 个答案:

答案 0 :(得分:1)

Firefox是一个多标签浏览器,因此获取每个标签的地址并不容易。

您可能需要制作一个与C#应用程序通信的Firefox插件,并为其提供选项卡的地址。

或者,请参阅此网址:http://social.msdn.microsoft.com/forums/en/csharpgeneral/thread/c60b1699-9fd7-408d-a395-110c1cd4f297

答案 1 :(得分:0)

string WebText = "";
foreach (InternetExplorer ie in new ShellWindowsClass())
{
    filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
    if (filename == "iexplore")
    Url = ie.LocationURL.ToString();
}
相关问题