using LYFZ.OtherExpansion.Win32;
using LYFZ.OtherExpansion.Win32.Const;
using LYFZ.OtherExpansion.Win32.Struct;
using System;
using System.Drawing;
using System.Windows.Forms;
namespace LYFZ.OtherExpansion.SkinControl
{
	internal abstract class MaskControlBase : NativeWindow, IDisposable
	{
		private CreateParams _createParams;
		private bool _disposed;
		protected bool IsHandleCreated
		{
			get
			{
				return base.Handle != IntPtr.Zero;
			}
		}
		protected virtual CreateParams CreateParams
		{
			get
			{
				return this._createParams;
			}
		}
		protected MaskControlBase(IntPtr hWnd)
		{
			this.CreateParamsInternal(hWnd);
		}
		protected MaskControlBase(IntPtr hWnd, Rectangle rect)
		{
			this.CreateParamsInternal(hWnd, rect);
		}
		~MaskControlBase()
		{
			this.Dispose(false);
		}
		protected internal void OnCreateHandle()
		{
			base.CreateHandle(this.CreateParams);
			this.SetZorder();
		}
		protected virtual void OnPaint(IntPtr hWnd)
		{
		}
		protected override void WndProc(ref Message m)
		{
			base.WndProc(ref m);
			try
			{
				int msg = m.Msg;
				if (msg == 15 || msg == 133)
				{
					this.OnPaint(m.HWnd);
				}
			}
			catch
			{
			}
		}
		internal void CreateParamsInternal(IntPtr hWnd)
		{
			IntPtr hParent = NativeMethods.GetParent(hWnd);
			RECT rect = default(RECT);
			NativeMethods.Point point = default(NativeMethods.Point);
			NativeMethods.GetWindowRect(hWnd, ref rect);
			point.x = rect.Left;
			point.y = rect.Top;
			NativeMethods.ScreenToClient(hParent, ref point);
			int dwStyle = 1409286157;
			int dwExStyle = 136;
			this._createParams = new CreateParams();
			this._createParams.Parent = hParent;
			this._createParams.ClassName = "STATIC";
			this._createParams.Caption = null;
			this._createParams.Style = dwStyle;
			this._createParams.ExStyle = dwExStyle;
			this._createParams.X = point.x;
			this._createParams.Y = point.y;
			this._createParams.Width = rect.Right - rect.Left;
			this._createParams.Height = rect.Bottom - rect.Top;
		}
		internal void CreateParamsInternal(IntPtr hWnd, Rectangle rect)
		{
			IntPtr hParent = NativeMethods.GetParent(hWnd);
			int dwStyle = 1409286157;
			int dwExStyle = 136;
			this._createParams = new CreateParams();
			this._createParams.Parent = hParent;
			this._createParams.ClassName = "STATIC";
			this._createParams.Caption = null;
			this._createParams.Style = dwStyle;
			this._createParams.ExStyle = dwExStyle;
			this._createParams.X = rect.X;
			this._createParams.Y = rect.Y;
			this._createParams.Width = rect.Width;
			this._createParams.Height = rect.Height;
		}
		internal void DestroyHandleInternal()
		{
			if (this.IsHandleCreated)
			{
				base.DestroyHandle();
			}
		}
		internal void CheckBounds(IntPtr hWnd)
		{
			RECT controlRect = default(RECT);
			RECT maskRect = default(RECT);
			NativeMethods.GetWindowRect(base.Handle, ref maskRect);
			NativeMethods.GetWindowRect(hWnd, ref controlRect);
			uint uFlag = 532u;
			if (!NativeMethods.EqualRect(ref controlRect, ref maskRect))
			{
				NativeMethods.Point point = new NativeMethods.Point(controlRect.Left, controlRect.Top);
				IntPtr hParent = NativeMethods.GetParent(base.Handle);
				NativeMethods.ScreenToClient(hParent, ref point);
				NativeMethods.SetWindowPos(base.Handle, IntPtr.Zero, point.x, point.y, controlRect.Right - controlRect.Left, controlRect.Bottom - controlRect.Top, uFlag);
			}
		}
		internal void SetVisibale(IntPtr hWnd)
		{
			bool bVisible = (NativeMethods.GetWindowLong(hWnd, -16) & 268435456) == 268435456;
			this.SetVisibale(bVisible);
		}
		internal void SetVisibale(bool visibale)
		{
			if (visibale)
			{
				NativeMethods.ShowWindow(base.Handle, 1);
				return;
			}
			NativeMethods.ShowWindow(base.Handle, 0);
		}
		private void SetZorder()
		{
			uint uFlags = 531u;
			NativeMethods.SetWindowPos(base.Handle, HWND.HWND_TOP, 0, 0, 0, 0, uFlags);
		}
		public void Dispose()
		{
			this.Dispose(true);
			GC.SuppressFinalize(this);
		}
		protected virtual void Dispose(bool disposing)
		{
			if (!this._disposed)
			{
				if (disposing)
				{
					this._createParams = null;
				}
				this.DestroyHandleInternal();
			}
			this._disposed = true;
		}
	}
}