الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

من معرفة موقع صفحة ويب ما عندما يتم فتحها

بدأه ayash في 1 مايو 2011 · 11 رد · 646 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

بسم الله الرحمن الرحيم

السلام عليكم ورحمه الله وركاته

اخواني في المنتدى

كيف اقدر من معرفة عنوان صفحة ويب ما عندما يتم فتحها

اي عندما يفتح المستخدم صفحة ويب ما يتم معرفة موقعها

مثال اذا كنت فتحت منتدى الفريق العربي

ياتي لي في textbox

موقع الفريق العربي

>><<

واي صفحة افتحها ياتي لي في textbox موقعها

وبارك الله فيكم

291964_260506123967115_206850989332629_1001538_45132_n.jpg

اللهم إني أعوذ بك من علم لا ينفع ، ومن قلب لا يخشع ، ومن نفس لا تشبع ، ومن دعوة لا يستجاب لها

#2

السلام عليكم ورحمه الله وبركاته

طيب اخي بس المتصفح ؟؟ يعني يمكن افتح متصفحين .. فممكن توضح سؤالك بالتفصيل؟!!

.:: Wish to become better and better ::.

#3

اولا مشكور على المرور اخي

==========================

الي انا بدي ياه بالضبط انو اي موقع يفتحه المستخدم بدي يضعه في listbox يضع الرابط للموقع

بغض النظر عن عدد المتصفحات

هلل ممكن ذلك

وشكرا

291964_260506123967115_206850989332629_1001538_45132_n.jpg

اللهم إني أعوذ بك من علم لا ينفع ، ومن قلب لا يخشع ، ومن نفس لا تشبع ، ومن دعوة لا يستجاب لها

#5

يسلمو إن شاء الله راح اجرب الرابط وإن شاء الله ينجح

291964_260506123967115_206850989332629_1001538_45132_n.jpg

اللهم إني أعوذ بك من علم لا ينفع ، ومن قلب لا يخشع ، ومن نفس لا تشبع ، ومن دعوة لا يستجاب لها

#6

السلام عليكم

اخي جربت الكود بس ما بعطيني اسم الموقع الي بفتحه

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            Control.CheckForIllegalCrossThreadCalls = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Thread th = new Thread(new ThreadStart(get));
            th.IsBackground = true;
            th.Start();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
        public void get()
        {


                foreach (var entry in Library.Net.InternetCache.FindUrlCacheEntries("Visited:"))
                {

                    listBox1.Items.Add(entry.lpszSourceUrlName);

                }
            }
        }
    }


namespace Library.Net.DataStructs
{
    [StructLayout(LayoutKind.Sequential)]
    public struct INTERNET_CACHE_ENTRY_INFO
    {
        public UInt32 dwStructSize;
        public string lpszSourceUrlName;
        public string lpszLocalFileName;
        public UInt32 CacheEntryType;
        public UInt32 dwUseCount;
        public UInt32 dwHitRate;
        public UInt32 dwSizeLow;
        public UInt32 dwSizeHigh;
        public FILETIME LastModifiedTime;
        public FILETIME ExpireTime;
        public FILETIME LastAccessTime;
        public FILETIME LastSyncTime;
        public IntPtr lpHeaderInfo;
        public UInt32 dwHeaderInfoSize;
        public string lpszFileExtension;
        public UInt32 dwExemptDelta;
    } ;
}


namespace Library.Net
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.InteropServices;
    using System.Text.RegularExpressions;
    using DataStructs;

    public sealed class InternetCache
    {
        private const int ERROR_INVALID_PARAMETER = 87;
        private const int ERROR_INSUFFICIENT_BUFFER = 122;
        private const int ERROR_NO_MORE_ITEMS = 259;
        private const int ERROR_NO_TOKEN = 1008;

        /// <summary>
        /// UrlCache functionality is taken from:
        /// Scott McMaster (EMAIL REMOVED)
        /// CodeProject article
        /// 
        /// There were some issues with preparing URLs
        /// for RegExp to work properly. This is
        /// demonstrated in AllForms.SetupCookieCachePattern method
        /// 
        /// urlPattern:
        /// . Dump the entire contents of the cache.
        /// Cookie: Lists all cookies on the system.
        /// Visited: Lists all of the history items.
        /// Cookie:.*\.example\.com Lists cookies from the example.com domain.
        /// http://www.example.com/example.html$: Lists the specific named file if present
        /// \.example\.com: Lists any and all entries from *.example.com.
        /// \.example\.com.*\.gif$: Lists the .gif files from *.example.com.
        /// \.js$: Lists the .js files in the cache.
        /// </summary>
        /// <param name="urlPattern"></param>
        /// <returns></returns>
        public static IEnumerable<INTERNET_CACHE_ENTRY_INFO> FindUrlCacheEntries(string urlPattern)
        {
            var results = new List<INTERNET_CACHE_ENTRY_INFO>();

            var buffer = IntPtr.Zero;
            UInt32 structSize;

            //This call will fail but returns the size required in structSize
            //to allocate necessary buffer
            var hEnum = FindFirstUrlCacheEntry(null, buffer, out structSize);
            try
            {
                if (hEnum == IntPtr.Zero)
                {
                    var lastError = Marshal.GetLastWin32Error();
                    switch (lastError)
                    {
                        case ERROR_INSUFFICIENT_BUFFER:
                            buffer = Marshal.AllocHGlobal((int)structSize);
                            hEnum = FindFirstUrlCacheEntry(urlPattern, buffer, out structSize);
                            break;
                        case ERROR_NO_TOKEN:
                        case ERROR_NO_MORE_ITEMS:
                            return results.AsEnumerable();
                    }
                }

                var result = (INTERNET_CACHE_ENTRY_INFO)Marshal.PtrToStructure(buffer, typeof(INTERNET_CACHE_ENTRY_INFO));
                try
                {
                    if (Regex.IsMatch(result.lpszSourceUrlName, urlPattern, RegexOptions.IgnoreCase))
                        results.Add(result);
                }
                catch (ArgumentException ae)
                {
                    throw new ApplicationException("Invalid regular expression, details=" + ae.Message);
                }

                if (buffer != IntPtr.Zero)
                {
                    try
                    {
                        Marshal.FreeHGlobal(buffer);
                    }
                    catch
                    {
                    }
                    buffer = IntPtr.Zero;
                }

                while (true)
                {
                    var nextResult = FindNextUrlCacheEntry(hEnum, buffer, out structSize);
                    structSize *= 4;
                    if (nextResult != 1) //TRUE
                    {
                        var lastError = Marshal.GetLastWin32Error();
                        switch (lastError)
                        {
                            case ERROR_INSUFFICIENT_BUFFER:
                                buffer = Marshal.AllocHGlobal((int)structSize);
                                FindNextUrlCacheEntry(hEnum, buffer, out structSize);
                                break;
                            case ERROR_NO_MORE_ITEMS:
                            case ERROR_INVALID_PARAMETER:
                                return results.AsEnumerable();
                        }
                    }

                    if (buffer != IntPtr.Zero)
                    {
                        result = (INTERNET_CACHE_ENTRY_INFO)Marshal.PtrToStructure(buffer, typeof(INTERNET_CACHE_ENTRY_INFO));
                        if (Regex.IsMatch(result.lpszSourceUrlName, urlPattern, RegexOptions.IgnoreCase))
                            results.Add(result);


                        try
                        {
                            Marshal.FreeHGlobal(buffer);
                        }
                        catch
                        {
                        }
                        buffer = IntPtr.Zero;
                    }
                }
            }
            finally
            {
                if (hEnum != IntPtr.Zero)
                    FindCloseUrlCache(hEnum);
                if (buffer != IntPtr.Zero)
                    try
                    {
                        Marshal.FreeHGlobal(buffer);
                    }
                    catch
                    {
                    }
            }
        }

        [DllImport("wininet.dll", SetLastError = true)]
        private static extern IntPtr FindFirstUrlCacheEntry(string lpszUrlSearchPattern,
                                                           IntPtr lpFirstCacheEntryInfo,
                                                           out UInt32 lpdwFirstCacheEntryInfoBufferSize);
        [DllImport("wininet.dll", SetLastError = true)]
        private static extern long FindNextUrlCacheEntry(IntPtr hEnumHandle,
                                                        IntPtr lpNextCacheEntryInfo,
                                                        out UInt32 lpdwNextCacheEntryInfoBufferSize);

        [DllImport("wininet.dll", SetLastError = true)]
        private static extern long FindCloseUrlCache(IntPtr hEnumHandle);

    }
}

291964_260506123967115_206850989332629_1001538_45132_n.jpg

اللهم إني أعوذ بك من علم لا ينفع ، ومن قلب لا يخشع ، ومن نفس لا تشبع ، ومن دعوة لا يستجاب لها

#7

السلام عليكم ورحمه الله وبركاته

اخي اكيد هالرابط بيساعدك http://stackoverflow.com/questions/430614/get-firefox-url

.:: Wish to become better and better ::.

#8

السلام عليكم

مشكور اخي على المتابعه معي في الموضوع

---------------------------------------

في الرابط التالي وجت ما ابحث عنه

http://stackoverflow.com/questions/5317642/retrieve-current-url-from-c-windows-form

والاكواد المطلوبة هي

public static string GetChromeUrl(Process process)
{
    if (process == null)
        throw new ArgumentNullException("process");

    if (process.MainWindowHandle == IntPtr.Zero)
        return null;

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

    AutomationElement edit = element.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit));
    return ((ValuePattern)edit.GetCurrentPattern(ValuePattern.Pattern)).Current.Value as string;
}

public static string GetInternetExplorerUrl(Process process)
{
    if (process == null)
        throw new ArgumentNullException("process");

    if (process.MainWindowHandle == IntPtr.Zero)
        return null;

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

    AutomationElement rebar = element.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "ReBarWindow32"));
    if (rebar == null)
        return null;

    AutomationElement edit = rebar.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit));

    return ((ValuePattern)edit.GetCurrentPattern(ValuePattern.Pattern)).Current.Value as string;
}

public static string GetFirefoxUrl(Process process)
{
    if (process == null)
        throw new ArgumentNullException("process");

    if (process.MainWindowHandle == IntPtr.Zero)
        return null;

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

    AutomationElement doc = element.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document));
    if (doc == null)
        return null;

    return ((ValuePattern)doc.GetCurrentPattern(ValuePattern.Pattern)).Current.Value as string;
}
You can use the UI Spy tool to understand the visual hierarchy for all 3 browsers. You may need to adapt things to make sure it really work in your specific cases, but you should get the general idea with these samples.

And an example that dumps all urls for all the 3 types of process (IE, FF, CH) currently running in the system:

static void Main(string[] args)
{
    foreach (Process process in Process.GetProcessesByName("firefox"))
    {
        string url = GetFirefoxUrl(process);
        if (url == null)
            continue;

        Console.WriteLine("FF Url for '" + process.MainWindowTitle + "' is " + url);
    }

    foreach (Process process in Process.GetProcessesByName("iexplore"))
    {
        string url = GetInternetExplorerUrl(process);
        if (url == null)
            continue;

        Console.WriteLine("IE Url for '" + process.MainWindowTitle + "' is " + url);
    }

    foreach (Process process in Process.GetProcessesByName("chrome"))
    {
        string url = GetChromeUrl(process);
        if (url == null)
            continue;

        Console.WriteLine("CH Url for '" + process.MainWindowTitle + "' is " + url);
    }
}

وايضا

static void Main(string[] args)
{
    foreach (Process process in Process.GetProcessesByName("firefox"))
    {
        string url = GetFirefoxUrl(process);
        if (url == null)
            continue;

        Console.WriteLine("FF Url for '" + process.MainWindowTitle + "' is " + url);
    }

    foreach (Process process in Process.GetProcessesByName("iexplore"))
    {
        string url = GetInternetExplorerUrl(process);
        if (url == null)
            continue;

        Console.WriteLine("IE Url for '" + process.MainWindowTitle + "' is " + url);
    }

    foreach (Process process in Process.GetProcessesByName("chrome"))
    {
        string url = GetChromeUrl(process);
        if (url == null)
            continue;

        Console.WriteLine("CH Url for '" + process.MainWindowTitle + "' is " + url);
    }
}

لكن المشكلة بعد ما حملت الملف UIAutomationClient.dll

واستدعيته في البرنامج

حدث مشكلة انه لم يتعرف على TreeScope.Subtree

و ControlType.Edit والباقي تعرف عليه بشكل سليم

هل لان الملف VIRSION قديمة

اذا كان كذلك ياريت تعطوني الVIRSON المناسبة ذلك

إن شاء الله المشكلة يتم حلها

وبارك الله فيكم جميعا

تم تعديل هذه المشاركة بواسطة ayash في 1 مايو 2011 في 16:39

291964_260506123967115_206850989332629_1001538_45132_n.jpg

اللهم إني أعوذ بك من علم لا ينفع ، ومن قلب لا يخشع ، ومن نفس لا تشبع ، ومن دعوة لا يستجاب لها

#9

السلام عليكم ورحمه الله وبركاته

اخي عياش قبل ما ارسل لك الرابط الاخير سويت مثال يشبه الي كتبته بس اقل بكثير بس حبيت اقول انه ال MainWindowTitle هو النص المكتوب اعلى الصفحه مو الرابط؟!!

.:: Wish to become better and better ::.

#10

مشكور بس اسم الصفحة

ما بلزم اخي لاي اريد معرفه الكود الذي تحتويه الصفحة والعنوان لا يلزم

مشكور

هل تقصد مثل هذا الكود ولا لا

 foreach (Process p in Process.GetProcesses())
            {
                try
                {
                    listBox1.Items.Add(p.MainWindowTitle); 
                }
                catch (Exception ex) { }

  }

وشكرا مرة اخرى

تم تعديل هذه المشاركة بواسطة ayash في 1 مايو 2011 في 17:28

291964_260506123967115_206850989332629_1001538_45132_n.jpg

اللهم إني أعوذ بك من علم لا ينفع ، ومن قلب لا يخشع ، ومن نفس لا تشبع ، ومن دعوة لا يستجاب لها

#11

السلام عليكم ورحمه الله وبركاته

اخي قصدي عالكود الي كتبته في ردك السابق ...

.:: Wish to become better and better ::.

#12

اها انا اسف فهمت غلط

انا في الانتظار اخي

وبارك الله فيك

تم تعديل هذه المشاركة بواسطة ayash في 1 مايو 2011 في 18:30

291964_260506123967115_206850989332629_1001538_45132_n.jpg

اللهم إني أعوذ بك من علم لا ينفع ، ومن قلب لا يخشع ، ومن نفس لا تشبع ، ومن دعوة لا يستجاب لها

مواضيع مشابهة