00001 #region License
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #endregion
00027
00028 using System;
00029 using System.Collections.Generic;
00030 using System.Text;
00031 using System.Diagnostics;
00032 using System.Runtime.InteropServices;
00033
00034 namespace OpenTK.Platform.Windows
00035 {
00038 sealed class WinWindowInfo : IWindowInfo
00039 {
00040 IntPtr handle, dc;
00041 WinWindowInfo parent;
00042 bool disposed;
00043
00044 #region --- Constructors ---
00045
00049 public WinWindowInfo()
00050 {
00051 }
00052
00058 public WinWindowInfo(IntPtr handle, WinWindowInfo parent)
00059 {
00060 this.handle = handle;
00061 this.parent = parent;
00062 }
00063
00064 #endregion
00065
00066 #region --- Public Methods ---
00067
00071 public IntPtr WindowHandle { get { return handle; } set { handle = value; } }
00072
00076 public WinWindowInfo Parent { get { return parent; } set { parent = value; } }
00077
00081 public IntPtr DeviceContext
00082 {
00083 get
00084 {
00085 if (dc == IntPtr.Zero)
00086 dc = Functions.GetDC(this.WindowHandle);
00087
00088 return dc;
00089 }
00090 }
00091
00092 #region public override string ToString()
00093
00096 public override string ToString()
00097 {
00098 return String.Format("Windows.WindowInfo: Handle {0}, Parent ({1})",
00099 this.WindowHandle, this.Parent != null ? this.Parent.ToString() : "null");
00100 }
00101
00105 public override bool Equals(object obj)
00106 {
00107 if (obj == null) return false;
00108 if (this.GetType() != obj.GetType()) return false;
00109 WinWindowInfo info = (WinWindowInfo)obj;
00110
00111 if (info == null) return false;
00112
00113 return handle.Equals(info.handle);
00114 }
00115
00118 public override int GetHashCode()
00119 {
00120 return handle.GetHashCode();
00121 }
00122
00123 #endregion
00124
00125 #endregion
00126
00127 #region --- IDisposable ---
00128
00129 #region public void Dispose()
00130
00132 public void Dispose()
00133 {
00134 this.Dispose(true);
00135 GC.SuppressFinalize(this);
00136 }
00137
00138 #endregion
00139
00140 #region void Dispose(bool manual)
00141
00142 void Dispose(bool manual)
00143 {
00144 if (!disposed)
00145 {
00146 if (this.dc != IntPtr.Zero)
00147 if (!Functions.ReleaseDC(this.handle, this.dc))
00148 Debug.Print("[Warning] Failed to release device context {0}. Windows error: {1}.", this.dc, Marshal.GetLastWin32Error());
00149
00150 if (manual)
00151 {
00152 if (parent != null)
00153 parent.Dispose();
00154 }
00155
00156 disposed = true;
00157 }
00158 }
00159
00160 #endregion
00161
00162 #region ~WinWindowInfo()
00163
00164 ~WinWindowInfo()
00165 {
00166 this.Dispose(false);
00167 }
00168
00169 #endregion
00170
00171 #endregion
00172 }
00173 }