290 lines
10 KiB
C#
290 lines
10 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Runtime.InteropServices;
|
|
using System.Drawing;
|
|
|
|
namespace DevComponents.DotNetBar.Layout
|
|
{
|
|
internal static class WinApi
|
|
{
|
|
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
|
|
public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
|
|
[DllImport("gdi32")]
|
|
public static extern bool DeleteObject(IntPtr hObject);
|
|
|
|
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
|
|
public static extern bool GetTextMetrics(HandleRef hdc, TEXTMETRIC tm);
|
|
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
|
|
public class TEXTMETRIC
|
|
{
|
|
public int tmHeight;
|
|
public int tmAscent;
|
|
public int tmDescent;
|
|
public int tmInternalLeading;
|
|
public int tmExternalLeading;
|
|
public int tmAveCharWidth;
|
|
public int tmMaxCharWidth;
|
|
public int tmWeight;
|
|
public int tmOverhang;
|
|
public int tmDigitizedAspectX;
|
|
public int tmDigitizedAspectY;
|
|
public char tmFirstChar;
|
|
public char tmLastChar;
|
|
public char tmDefaultChar;
|
|
public char tmBreakChar;
|
|
public byte tmItalic;
|
|
public byte tmUnderlined;
|
|
public byte tmStruckOut;
|
|
public byte tmPitchAndFamily;
|
|
public byte tmCharSet;
|
|
}
|
|
|
|
[DllImport("user32")]
|
|
public static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
|
|
[DllImport("user32")]
|
|
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
|
|
public const int WM_SETREDRAW = 0x000B;
|
|
|
|
public const int WM_LBUTTONDOWN = 0x0201;
|
|
public const int WM_LBUTTONUP = 0x0202;
|
|
public const int WM_RBUTTONDOWN = 0x0204;
|
|
public const int WM_RBUTTONUP = 0x0205;
|
|
public const int WM_MOUSEMOVE = 0x0200;
|
|
public const int WM_MOUSELEAVE = 0x02A3;
|
|
public const int WM_HSCROLL = 0x0114;
|
|
public const int WM_VSCROLL = 0x0115;
|
|
public const int WM_LBUTTONDBLCLK = 0x0203;
|
|
|
|
public static int LOWORD(int n)
|
|
{
|
|
return (short)(n & 0xffff);
|
|
}
|
|
public static int HIWORD(int n)
|
|
{
|
|
return (int)((n >> 0x10) & 0xffff);
|
|
}
|
|
public static int LOWORD(IntPtr n)
|
|
{
|
|
return LOWORD((int)((long)n));
|
|
}
|
|
public static int HIWORD(IntPtr n)
|
|
{
|
|
return unchecked((short)((uint)n >> 16));
|
|
}
|
|
|
|
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
|
|
public static extern int ScrollWindowEx(HandleRef hWnd, int nXAmount, int nYAmount, ref RECT rectScrollRegion, ref RECT rectClip, IntPtr hrgnUpdate, ref RECT prcUpdate, int flags);
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct RECT
|
|
{
|
|
public int left;
|
|
public int top;
|
|
public int right;
|
|
public int bottom;
|
|
public RECT(int left, int top, int right, int bottom)
|
|
{
|
|
this.left = left;
|
|
this.top = top;
|
|
this.right = right;
|
|
this.bottom = bottom;
|
|
}
|
|
|
|
public RECT(Rectangle r)
|
|
{
|
|
this.left = r.Left;
|
|
this.top = r.Top;
|
|
this.right = r.Right;
|
|
this.bottom = r.Bottom;
|
|
}
|
|
|
|
public static RECT FromXYWH(int x, int y, int width, int height)
|
|
{
|
|
return new RECT(x, y, x + width, y + height);
|
|
}
|
|
|
|
public Size Size
|
|
{
|
|
get
|
|
{
|
|
return new Size(this.right - this.left, this.bottom - this.top);
|
|
}
|
|
}
|
|
}
|
|
internal static bool ModifyHwndStyle(IntPtr hwnd, int removeStyle, int addStyle)
|
|
{
|
|
int curWindowStyle = GetWindowLongPtr(hwnd, (int)GWL.GWL_STYLE).ToInt32();
|
|
int newStyle = (curWindowStyle & ~removeStyle) | addStyle;
|
|
if (curWindowStyle == newStyle)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
SetWindowLong(hwnd, (int)GWL.GWL_STYLE, newStyle);
|
|
return true;
|
|
}
|
|
// This static method is required because legacy OSes do not support
|
|
// GetWindowLongPtr
|
|
public static IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex)
|
|
{
|
|
if (IntPtr.Size == 8)
|
|
return GetWindowLongPtr64(hWnd, nIndex);
|
|
else
|
|
return new IntPtr(GetWindowLong32(hWnd, nIndex));
|
|
}
|
|
|
|
[DllImport("user32.dll", EntryPoint = "GetWindowLong")]
|
|
public static extern int GetWindowLong32(IntPtr hWnd, int nIndex);
|
|
|
|
[DllImport("user32.dll", EntryPoint = "GetWindowLongPtr")]
|
|
public static extern IntPtr GetWindowLongPtr64(IntPtr hWnd, int nIndex);
|
|
|
|
[DllImport("user32.dll")]
|
|
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
|
|
|
|
public static IntPtr SetWindowLongPtr(IntPtr hwnd, int nIndex, IntPtr dwNewLong)
|
|
{
|
|
if (IntPtr.Size == 8)
|
|
{
|
|
return SetWindowLongPtr64(hwnd, nIndex, dwNewLong);
|
|
}
|
|
return new IntPtr(SetWindowLongPtr32(hwnd, nIndex, dwNewLong.ToInt32()));
|
|
}
|
|
[DllImport("user32.dll", EntryPoint = "SetWindowLong", SetLastError = true)]
|
|
private static extern int SetWindowLongPtr32(IntPtr hWnd, int nIndex, int dwNewLong);
|
|
[DllImport("user32.dll", EntryPoint = "SetWindowLongPtr", SetLastError = true)]
|
|
private static extern IntPtr SetWindowLongPtr64(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
|
|
public enum GWL
|
|
{
|
|
GWL_WNDPROC = (-4),
|
|
GWL_HINSTANCE = (-6),
|
|
GWL_HWNDPARENT = (-8),
|
|
GWL_STYLE = (-16),
|
|
GWL_EXSTYLE = (-20),
|
|
GWL_USERDATA = (-21),
|
|
GWL_ID = (-12)
|
|
}
|
|
|
|
public enum RedrawWindowFlags : uint
|
|
{
|
|
RDW_INVALIDATE = 0x0001,
|
|
RDW_INTERNALPAINT = 0x0002,
|
|
RDW_ERASE = 0x0004,
|
|
RDW_VALIDATE = 0x0008,
|
|
RDW_NOINTERNALPAINT = 0x0010,
|
|
RDW_NOERASE = 0x0020,
|
|
RDW_NOCHILDREN = 0x0040,
|
|
RDW_ALLCHILDREN = 0x0080,
|
|
RDW_UPDATENOW = 0x0100,
|
|
RDW_ERASENOW = 0x0200,
|
|
RDW_FRAME = 0x0400,
|
|
RDW_NOFRAME = 0x0800
|
|
}
|
|
[Flags()]
|
|
public enum WindowStyles
|
|
{
|
|
WS_VISIBLE = 0x10000000,
|
|
WS_CAPTION = 0x00C00000,
|
|
WS_BORDER = 0x800000,
|
|
WS_DLGFRAME = 0x400000,
|
|
WS_THICKFRAME = 0x00040000,
|
|
WS_HSCROLL = 0x100000,
|
|
WS_VSCROLL = 0x200000
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct TRACKMOUSEEVENT
|
|
{
|
|
public int cbSize;
|
|
public uint dwFlags;
|
|
public int dwHoverTime;
|
|
public IntPtr hwndTrack;
|
|
}
|
|
[DllImport("user32")]
|
|
public static extern bool TrackMouseEvent(ref TRACKMOUSEEVENT tme);
|
|
// Track Mouse Event Flags
|
|
public const uint
|
|
TME_HOVER = 0x00000001,
|
|
TME_LEAVE = 0x00000002,
|
|
TME_NONCLIENT = 0x00000010,
|
|
TME_QUERY = 0x40000000,
|
|
TME_CANCEL = 0x80000000,
|
|
HOVER_DEFAULT = 0xFFFFFFFF;
|
|
|
|
#if TRIAL
|
|
private static Color m_ColorExpFlag = Color.Empty;
|
|
internal static int ColorCountExp = 0;
|
|
internal static bool ColorExpAlt()
|
|
{
|
|
Color clr = SystemColors.Control;
|
|
Color clr2;
|
|
Color clr3;
|
|
clr2 = clr;
|
|
if (clr2.ToArgb() == clr.ToArgb())
|
|
{
|
|
clr3 = clr2;
|
|
}
|
|
else
|
|
{
|
|
clr3 = clr;
|
|
}
|
|
|
|
ColorCountExp = clr.A;
|
|
|
|
if (!m_ColorExpFlag.IsEmpty)
|
|
{
|
|
return (m_ColorExpFlag == Color.Black ? false : true);
|
|
}
|
|
try
|
|
{
|
|
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.ClassesRoot;
|
|
key = key.CreateSubKey("CLSID\\{57FEED69-A5E0-45e7-8E02-5F4131F5EE63}\\InprocServer32");
|
|
|
|
try
|
|
{
|
|
if (key.GetValue("") == null || key.GetValue("").ToString() == "")
|
|
{
|
|
key.SetValue("", DateTime.Today.ToOADate().ToString());
|
|
}
|
|
else
|
|
{
|
|
if (key.GetValue("").ToString() == "windows3.dll")
|
|
{
|
|
m_ColorExpFlag = Color.White;
|
|
key.Close();
|
|
key = null;
|
|
return true;
|
|
}
|
|
DateTime date = DateTime.FromOADate(double.Parse(key.GetValue("").ToString()));
|
|
if (((TimeSpan)DateTime.Today.Subtract(date)).TotalDays > 30)
|
|
{
|
|
m_ColorExpFlag = Color.White;
|
|
key.SetValue("", "windows3.dll");
|
|
key.Close();
|
|
key = null;
|
|
return true;
|
|
}
|
|
if (((TimeSpan)DateTime.Today.Subtract(date)).TotalDays < 0)
|
|
{
|
|
m_ColorExpFlag = Color.White;
|
|
key.SetValue("", "windows2.dll");
|
|
key.Close();
|
|
key = null;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
if (key != null)
|
|
key.Close();
|
|
}
|
|
}
|
|
catch { }
|
|
m_ColorExpFlag = Color.Black;
|
|
return false;
|
|
}
|
|
#endif
|
|
}
|
|
}
|