Guest User

Untitled

a guest
Jul 5th, 2015
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace MinimizeCapture
  6. {
  7.     class WindowSnapCollection:List<WindowSnap>
  8.     {
  9.         private readonly bool asReadonly = false;
  10.  
  11.         const string READONLYEXCEPTIONTEXT="The Collection is marked as Read-Only and it cannot be modified";
  12.         private void ThrowAReadonlyException()
  13.         {
  14.             throw new Exception(READONLYEXCEPTIONTEXT);
  15.         }
  16.  
  17.         public new void Add(WindowSnap item)
  18.         {
  19.             if (this.asReadonly)this.ThrowAReadonlyException();
  20.             base.Add(item);
  21.         }
  22.  
  23.         public new void AddRange(IEnumerable<WindowSnap> collection)
  24.         {
  25.             if (this.asReadonly) this.ThrowAReadonlyException();
  26.             base.AddRange(collection);
  27.         }
  28.  
  29.         public new void Clear()
  30.         {
  31.             if (this.asReadonly) this.ThrowAReadonlyException();
  32.             base.Clear();
  33.         }
  34.  
  35.         public new void Insert(int index,WindowSnap item)
  36.         {
  37.                         if (this.asReadonly) this.ThrowAReadonlyException();
  38.             base.Insert(index,item);
  39.         }
  40.  
  41.         public new void InsertRange(int index, IEnumerable<WindowSnap> collection)
  42.         {
  43.             if (this.asReadonly) this.ThrowAReadonlyException();
  44.             base.InsertRange(index, collection);
  45.         }
  46.  
  47.         public new void Remove(WindowSnap item)
  48.         {
  49.             if (this.asReadonly) this.ThrowAReadonlyException();
  50.             base.Remove(item);
  51.         }
  52.  
  53.         public new void RemoveAll(Predicate<WindowSnap> match)
  54.         {
  55.             if (this.asReadonly) this.ThrowAReadonlyException();
  56.             base.RemoveAll(match);
  57.         }
  58.  
  59.         public new void RemoveAt(int index)
  60.         {
  61.                         if (this.asReadonly) this.ThrowAReadonlyException();
  62.             base.RemoveAt(index);
  63.         }
  64.  
  65.         public new void RemoveRange(int index,int count)
  66.         {
  67.                         if (this.asReadonly) this.ThrowAReadonlyException();
  68.             base.RemoveRange(index,count);
  69.         }
  70.  
  71.         public new void Reverse(int index, int count)
  72.         {
  73.             if (this.asReadonly) this.ThrowAReadonlyException();
  74.             base.Reverse(index, count);
  75.         }
  76.  
  77.         public new void Reverse()
  78.         {
  79.             if (this.asReadonly) this.ThrowAReadonlyException();
  80.             base.Reverse();
  81.         }
  82.  
  83.         public new void Sort()
  84.         {
  85.             if (this.asReadonly) this.ThrowAReadonlyException();
  86.             base.Sort();
  87.         }
  88.  
  89.         public new void Sort(Comparison<WindowSnap> comparison)
  90.         {
  91.             if (this.asReadonly) this.ThrowAReadonlyException();
  92.             base.Sort(comparison);
  93.         }
  94.  
  95.         public new void Sort(IComparer<WindowSnap> compare)
  96.         {
  97.             if (this.asReadonly) this.ThrowAReadonlyException();
  98.             base.Sort(compare);
  99.         }
  100.  
  101.         public new void Sort(int index,int count,IComparer<WindowSnap> compare)
  102.         {
  103.             if (this.asReadonly) this.ThrowAReadonlyException();
  104.             base.Sort(index,count,compare);
  105.         }
  106.  
  107.  
  108.         public bool Contains(IntPtr hWnd)
  109.         {
  110.             if (GetWindowSnap(hWnd) != null) return true;
  111.             return false;
  112.            
  113.         }
  114.  
  115.         public WindowSnap GetWindowSnap(IntPtr hWnd)
  116.         {
  117.             checkHWnd = hWnd;
  118.             return base.Find(IshWndPredict);          
  119.         }
  120.  
  121.         public void Update(WindowSnap item)
  122.         {
  123.             lock (this)
  124.             {
  125.                 WindowSnap oldSnap = this.GetWindowSnap(item.Handle);
  126.                 this.Remove(oldSnap);
  127.                 this.Add(item);
  128.             }
  129.         }
  130.  
  131.         public WindowSnapCollection GetAllMinimized()
  132.         {
  133.             WindowSnapCollection wsCol= (WindowSnapCollection) base.FindAll(IsMinimizedPredict);
  134.             return wsCol;
  135.         }
  136.  
  137.         private static bool IsMinimizedPredict(WindowSnap ws)
  138.         {
  139.             if (ws.IsMinimized) return true;
  140.             return false;
  141.         }
  142.  
  143.         [ThreadStatic]private static IntPtr checkHWnd;
  144.         private static bool IshWndPredict(WindowSnap ws)
  145.         {
  146.             if (ws.Handle == checkHWnd)
  147.                 return true;
  148.             return false;
  149.         }
  150.  
  151.         public bool ReadOnly
  152.         {
  153.             get{return this.asReadonly;}
  154.         }
  155.  
  156.         public WindowSnapCollection(WindowSnap[] items, bool asReadOnly)
  157.         {
  158.             base.AddRange(items);
  159.             base.TrimExcess();
  160.             this.asReadonly = asReadOnly;
  161.         }
  162.  
  163.         public WindowSnapCollection()
  164.         {
  165.             this.asReadonly = false;
  166.         }
  167.     }
  168. }
Add Comment
Please, Sign In to add comment