نمایش نتایج 1 تا 3 از 3

نام تاپیک: ایجاد شئی از کلاس

  1. #1

    ایجاد شئی از کلاس

    سلام دوستان
    من کد زیر رو از این سایت پیدا کردم.
    کارش پاک کردن کش webbrowser هست.
    ولی بلد نیستم ازش تو برنامه استفاده کنم. ممنون میشم راهنماییم کنید.
     /**
    * Modified from code originally found here: http://support.microsoft.com/kb/326201
    **/
    public class WebBrowserHelper
    {
    #region Definitions/DLL Imports
    /// <summary>
    /// For PInvoke: Contains information about an entry in the Internet cache
    /// </summary>
    [StructLayout(LayoutKind.Explicit)]
    public struct ExemptDeltaOrReserverd
    {
    [FieldOffset(0)]
    public UInt32 dwReserved;
    [FieldOffset(0)]
    public UInt32 dwExemptDelta;
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct INTERNET_CACHE_ENTRY_INFOA
    {
    public UInt32 dwStructSize;
    public IntPtr lpszSourceUrlName;
    public IntPtr 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 IntPtr lpszFileExtension;
    public ExemptDeltaOrReserverd dwExemptDeltaOrReserved;
    }

    // For PInvoke: Initiates the enumeration of the cache groups in the Internet cache
    [DllImport(@"wininet",
    SetLastError = true,
    CharSet = CharSet.Auto,
    EntryPoint = "FindFirstUrlCacheGroup",
    CallingConvention = CallingConvention.StdCall)]
    public static extern IntPtr FindFirstUrlCacheGroup(
    int dwFlags,
    int dwFilter,
    IntPtr lpSearchCondition,
    int dwSearchCondition,
    ref long lpGroupId,
    IntPtr lpReserved);

    // For PInvoke: Retrieves the next cache group in a cache group enumeration
    [DllImport(@"wininet",
    SetLastError = true,
    CharSet = CharSet.Auto,
    EntryPoint = "FindNextUrlCacheGroup",
    CallingConvention = CallingConvention.StdCall)]
    public static extern bool FindNextUrlCacheGroup(
    IntPtr hFind,
    ref long lpGroupId,
    IntPtr lpReserved);

    // For PInvoke: Releases the specified GROUPID and any associated state in the cache index file
    [DllImport(@"wininet",
    SetLastError = true,
    CharSet = CharSet.Auto,
    EntryPoint = "DeleteUrlCacheGroup",
    CallingConvention = CallingConvention.StdCall)]
    public static extern bool DeleteUrlCacheGroup(
    long GroupId,
    int dwFlags,
    IntPtr lpReserved);

    // For PInvoke: Begins the enumeration of the Internet cache
    [DllImport(@"wininet",
    SetLastError = true,
    CharSet = CharSet.Auto,
    EntryPoint = "FindFirstUrlCacheEntryA",
    CallingConvention = CallingConvention.StdCall)]
    public static extern IntPtr FindFirstUrlCacheEntry(
    [MarshalAs(UnmanagedType.LPTStr)] string lpszUrlSearchPattern,
    IntPtr lpFirstCacheEntryInfo,
    ref int lpdwFirstCacheEntryInfoBufferSize);

    // For PInvoke: Retrieves the next entry in the Internet cache
    [DllImport(@"wininet",
    SetLastError = true,
    CharSet = CharSet.Auto,
    EntryPoint = "FindNextUrlCacheEntryA",
    CallingConvention = CallingConvention.StdCall)]
    public static extern bool FindNextUrlCacheEntry(
    IntPtr hFind,
    IntPtr lpNextCacheEntryInfo,
    ref int lpdwNextCacheEntryInfoBufferSize);

    // For PInvoke: Removes the file that is associated with the source name from the cache, if the file exists
    [DllImport(@"wininet",
    SetLastError = true,
    CharSet = CharSet.Auto,
    EntryPoint = "DeleteUrlCacheEntryA",
    CallingConvention = CallingConvention.StdCall)]
    public static extern bool DeleteUrlCacheEntry(
    IntPtr lpszUrlName);
    #endregion

    /// <summary>
    /// Clears the cache of the web browser
    /// </summary>
    public static void ClearCache()
    {
    // Indicates that all of the cache groups in the user's system should be enumerated
    const int CACHEGROUP_SEARCH_ALL = 0x0;
    // Indicates that all the cache entries that are associated with the cache group
    // should be deleted, unless the entry belongs to another cache group.
    const int CACHEGROUP_FLAG_FLUSHURL_ONDELETE = 0x2;
    const int ERROR_INSUFFICIENT_BUFFER = 0x7A;

    // Delete the groups first.
    // Groups may not always exist on the system.
    // For more information, visit the following Microsoft Web site:
    // http://msdn.microsoft.com/library/?u...view/cache.asp
    // By default, a URL does not belong to any group. Therefore, that cache may become
    // empty even when the CacheGroup APIs are not used because the existing URL does not belong to any group.
    long groupId = 0;
    IntPtr enumHandle = FindFirstUrlCacheGroup(0, CACHEGROUP_SEARCH_ALL, IntPtr.Zero, 0, ref groupId, IntPtr.Zero);
    if (enumHandle != IntPtr.Zero) {
    bool more;
    do {
    // Delete a particular Cache Group.
    DeleteUrlCacheGroup(groupId, CACHEGROUP_FLAG_FLUSHURL_ONDELETE, IntPtr.Zero);
    more = FindNextUrlCacheGroup(enumHandle, ref groupId, IntPtr.Zero);
    } while (more);
    }

    // Start to delete URLs that do not belong to any group.
    int cacheEntryInfoBufferSizeInitial = 0;
    FindFirstUrlCacheEntry(null, IntPtr.Zero, ref cacheEntryInfoBufferSizeInitial); // should always fail because buffer is too small
    if (Marshal.GetLastWin32Error() == ERROR_INSUFFICIENT_BUFFER) {
    int cacheEntryInfoBufferSize = cacheEntryInfoBufferSizeInitial;
    IntPtr cacheEntryInfoBuffer = Marshal.AllocHGlobal(cacheEntryInfoBufferSize);
    enumHandle = FindFirstUrlCacheEntry(null, cacheEntryInfoBuffer, ref cacheEntryInfoBufferSizeInitial);
    if (enumHandle != IntPtr.Zero) {
    bool more;
    do {
    INTERNET_CACHE_ENTRY_INFOA internetCacheEntry = (INTERNET_CACHE_ENTRY_INFOA)Marshal.PtrToStructure (cacheEntryInfoBuffer, typeof(INTERNET_CACHE_ENTRY_INFOA));
    cacheEntryInfoBufferSizeInitial = cacheEntryInfoBufferSize;
    DeleteUrlCacheEntry(internetCacheEntry.lpszSourceU rlName);
    more = FindNextUrlCacheEntry(enumHandle, cacheEntryInfoBuffer, ref cacheEntryInfoBufferSizeInitial);
    if (!more && Marshal.GetLastWin32Error() == ERROR_INSUFFICIENT_BUFFER) {
    cacheEntryInfoBufferSize = cacheEntryInfoBufferSizeInitial;
    cacheEntryInfoBuffer = Marshal.ReAllocHGlobal(cacheEntryInfoBuffer, (IntPtr)cacheEntryInfoBufferSize);
    more = FindNextUrlCacheEntry(enumHandle, cacheEntryInfoBuffer, ref cacheEntryInfoBufferSizeInitial);
    }
    } while (more);
    }
    Marshal.FreeHGlobal(cacheEntryInfoBuffer);
    }
    }
    }

  2. #2
    مدیر بخش آواتار danialafshari
    تاریخ عضویت
    تیر 1387
    محل زندگی
    هر کجا هستم باشم آسمان مال من است
    پست
    2,909

    نقل قول: ایجاد شئی از کلاس

    با سلام
    کد بالا کار نکرد
    فایل dll ضمیمه شده رو به references اضافه کنید و کد زیر رو بنویسید

    UrlHistoryLibrary.UrlHistoryWrapperClass urlHistory = new UrlHistoryLibrary.UrlHistoryWrapperClass();
    urlHistory.ClearHistory();

    موفق باشید
    فایل های ضمیمه فایل های ضمیمه
    لطفاً از پرسیدن سوال در خصوصی خودداری کنید.
    قبل از ایجاد تاپیک، حتماً قوانین سایت را مطالعه فرمایید.
    قوانین پرسش های دانشجویی
    برای درست وارد شدن کد در قالب C#‎‎‎ سایت، ابتدا کد رو درون Notepad.exe کپی سپس از اونجا به سایت در قالب C#‎‎‎ منتفل کنید
    نرم افزار code manager دستیار برنامه نویسان جهت نگهداری کد ها

  3. #3

    نقل قول: ایجاد شئی از کلاس

    این کش رو پاک میکنه یا History؟

تاپیک های مشابه

  1. پاسخ: 0
    آخرین پست: جمعه 06 بهمن 1391, 16:01 عصر
  2. استفاده از کلاس برای ایجاد در بانک
    نوشته شده توسط toopak در بخش VB.NET
    پاسخ: 0
    آخرین پست: جمعه 23 اردیبهشت 1390, 08:55 صبح
  3. سوال: ایجاد رویداد کلیک برای شیی از کلاس Graphic?? فوری ؟؟؟
    نوشته شده توسط Tintirio در بخش C#‎‎
    پاسخ: 2
    آخرین پست: دوشنبه 29 فروردین 1390, 22:47 عصر
  4. ایجاد آرایه ای از کلاس
    نوشته شده توسط z_barnamenevis در بخش C#‎‎
    پاسخ: 3
    آخرین پست: پنج شنبه 14 خرداد 1388, 23:10 عصر
  5. پاسخ: 7
    آخرین پست: یک شنبه 02 تیر 1387, 19:24 عصر

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •