栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

从C#Windows Forms应用程序检索当前URL

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

从C#Windows Forms应用程序检索当前URL

到目前为止,这就是我所拥有的(尽管Chrome浏览器上没有找到任何有用的文章,除了使用FindWindowEx之外(我个人并不特别喜欢这种方法)。

public class BrowserLocation{    /// <summary>    /// Structure to hold the details regarding a browed location    /// </summary>    public struct URLDetails    {        /// <summary>        /// URL (location)        /// </summary>        public String URL;        /// <summary>        /// document title        /// </summary>        public String Title;    }    #region Internet Explorer    // requires the following DLL added as a reference:    // C:WindowsSystem32shdocvw.dll    /// <summary>    /// Retrieve the current open URLs in Internet Explorer    /// </summary>    /// <returns></returns>    public static URLDetails[] InternetExplorer()    {        System.Collections.Generic.List<URLDetails> URLs = new System.Collections.Generic.List<URLDetails>();        var shellWindows = new SHDocVw.ShellWindows();        foreach (SHDocVw.InternetExplorer ie in shellWindows) URLs.Add(new URLDetails() { URL = ie.LocationURL, Title = ie.LocationName });        return URLs.ToArray();    }    #endregion    #region Firefox    // This requires NDde    // http://ndde.preplex.com/    public static URLDetails[] Firefox()    {        NDde.Client.DdeClient dde = new NDde.Client.DdeClient("Firefox", "WWW_GetWindowInfo");        try        { dde.Connect(); String url = dde.Request("URL", Int32.MaxValue); dde.Disconnect(); Int32 stop = url.IndexOf('"', 1); return new URLDetails[]{     new URLDetails()     {         URL = url.Substring(1, stop - 1),         Title = url.Substring(stop + 3, url.Length - stop - 8)     } };        }        catch (Exception)        { return null;        }    }    #endregion}class Program{    static void Main(string[] args)    {        Console.WriteLine("Internet Explorer: ");        (new List<BrowserLocation.URLDetails>(BrowserLocation.InternetExplorer())).ForEach(u =>        { Console.WriteLine("[{0}]rn{1}rn", u.Title, u.URL);        });        Console.WriteLine();        Console.WriteLine("Firefox:");        (new List<BrowserLocation.URLDetails>(BrowserLocation.Firefox())).ForEach(u =>        { Console.WriteLine("[{0}]rn{1}rn", u.Title, u.URL);        });        Console.WriteLine();    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/465327.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号