using System.IO;
using System.Runtime.InteropServices;
using System.Text;
+using System.Threading;
/// Win32 Version
internal static Rectangle grab_area;
internal static WndProc wnd_proc;
internal static IntPtr prev_mouse_hwnd;
- internal static IntPtr override_cursor;
internal static bool caret_visible;
internal static bool themes_enabled;
private static IntPtr clip_magic = new IntPtr(27051977);
private static int scroll_width;
private static int scroll_height;
+ private static Hashtable wm_nc_registered;
+ private static RECT clipped_cursor_rect;
+ private Hashtable registered_classes;
+ private Hwnd HwndCreating; // the Hwnd we are currently creating (see CreateWindow)
- private static Win32DnD DnD;
#endregion // Local Variables
#region Private Structs
internal int top;
internal int right;
internal int bottom;
- public override string ToString() {
+
+ public RECT (int left, int top, int right, int bottom)
+ {
+ this.left = left;
+ this.top = top;
+ this.right = right;
+ this.bottom = bottom;
+ }
+
+ #region Instance Properties
+ public int Height { get { return bottom - top; } }
+ public int Width { get { return right - left; } }
+ public Size Size { get { return new Size (Width, Height); } }
+ public Point Location { get { return new Point (left, top); } }
+ #endregion
+
+ #region Instance Methods
+ public Rectangle ToRectangle ()
+ {
+ return Rectangle.FromLTRB (left, top, right, bottom);
+ }
+
+ public static RECT FromRectangle (Rectangle rectangle)
+ {
+ return new RECT (rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom);
+ }
+
+ public override int GetHashCode ()
+ {
+ return left ^ ((top << 13) | (top >> 0x13))
+ ^ ((Width << 0x1a) | (Width >> 6))
+ ^ ((Height << 7) | (Height >> 0x19));
+ }
+
+ public override string ToString ()
+ {
return String.Format("RECT left={0}, top={1}, right={2}, bottom={3}, width={4}, height={5}", left, top, right, bottom, right-left, bottom-top);
}
+ #endregion
- }
+ #region Operator overloads
+ public static implicit operator Rectangle (RECT rect)
+ {
+ return Rectangle.FromLTRB (rect.left, rect.top, rect.right, rect.bottom);
+ }
- [StructLayout(LayoutKind.Sequential)]
- internal struct POINT {
- internal int x;
- internal int y;
+ public static implicit operator RECT (Rectangle rect)
+ {
+ return new RECT (rect.Left, rect.Top, rect.Right, rect.Bottom);
+ }
+ #endregion
}
internal enum SPIAction {
- SPI_GETWORKAREA = 0x0030,
+ SPI_GETACTIVEWINDOWTRACKING = 0x1000,
+ SPI_GETACTIVEWNDTRKTIMEOUT = 0x2002,
+ SPI_GETANIMATION = 0x0048,
+ SPI_GETCARETWIDTH = 0x2006,
+ SPI_GETCOMBOBOXANIMATION = 0x1004,
+ SPI_GETDRAGFULLWINDOWS = 0x0026,
+ SPI_GETDROPSHADOW = 0x1024,
+ SPI_GETFONTSMOOTHING = 0x004A,
+ SPI_GETFONTSMOOTHINGCONTRAST = 0x200C,
+ SPI_GETFONTSMOOTHINGTYPE = 0x200A,
+ SPI_GETGRADIENTCAPTIONS = 0x1008,
+ SPI_GETHOTTRACKING = 0x100E,
+ SPI_GETICONTITLEWRAP = 0x0019,
+ SPI_GETKEYBOARDSPEED = 0x000A,
+ SPI_GETKEYBOARDDELAY = 0x0016,
+ SPI_GETKEYBOARDCUES = 0x100A,
+ SPI_GETKEYBOARDPREF = 0x0044,
+ SPI_GETLISTBOXSMOOTHSCROLLING = 0x1006,
+ SPI_GETMENUANIMATION = 0x1002,
+ SPI_GETMENUDROPALIGNMENT = 0x001B,
+ SPI_GETMENUFADE = 0x1012,
+ SPI_GETMENUSHOWDELAY = 0x006A,
+ SPI_GETMOUSESPEED = 0x0070,
+ SPI_GETSELECTIONFADE = 0x1014,
+ SPI_GETSNAPTODEFBUTTON = 0x005F,
+ SPI_GETTOOLTIPANIMATION = 0x1016,
+ SPI_GETWORKAREA = 0x0030,
SPI_GETMOUSEHOVERWIDTH = 0x0062,
SPI_GETMOUSEHOVERHEIGHT = 0x0064,
SPI_GETMOUSEHOVERTIME = 0x0066,
+ SPI_GETUIEFFECTS = 0x103E,
+ SPI_GETWHEELSCROLLLINES = 0x0068
}
internal enum WindowPlacementFlags {
private enum TMEFlags {
TME_HOVER = 0x00000001,
TME_LEAVE = 0x00000002,
+ TME_NONCLIENT = 0x00000010,
TME_QUERY = unchecked((int)0x40000000),
TME_CANCEL = unchecked((int)0x80000000)
}
internal int Reserved8;
}
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct KEYBDINPUT {
+ internal short wVk;
+ internal short wScan;
+ internal Int32 dwFlags;
+ internal Int32 time;
+ internal UIntPtr dwExtraInfo;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct MOUSEINPUT {
+ internal Int32 dx;
+ internal Int32 dy;
+ internal Int32 mouseData;
+ internal Int32 dwFlags;
+ internal Int32 time;
+ internal UIntPtr dwExtraInfo;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct HARDWAREINPUT {
+ internal Int32 uMsg;
+ internal short wParamL;
+ internal short wParamH;
+ }
+
+ [StructLayout (LayoutKind.Sequential)]
+ internal struct ICONINFO {
+ internal bool fIcon;
+ internal Int32 xHotspot;
+ internal Int32 yHotspot;
+ internal IntPtr hbmMask;
+ internal IntPtr hbmColor;
+ }
+
+ [StructLayout(LayoutKind.Explicit)]
+ internal struct INPUT {
+ [FieldOffset(0)]
+ internal Int32 type;
+
+ [FieldOffset(4)]
+ internal MOUSEINPUT mi;
+
+ [FieldOffset(4)]
+ internal KEYBDINPUT ki;
+
+ [FieldOffset(4)]
+ internal HARDWAREINPUT hi;
+ }
+
+ [StructLayout (LayoutKind.Sequential)]
+ public struct ANIMATIONINFO {
+ internal uint cbSize;
+ internal int iMinAnimate;
+ }
+
+ internal enum InputFlags {
+ KEYEVENTF_EXTENDEDKEY = 0x0001,
+ KEYEVENTF_KEYUP = 0x0002,
+ KEYEVENTF_SCANCODE = 0x0003,
+ KEYEVENTF_UNICODE = 0x0004,
+ }
+
internal enum ClassStyle {
CS_VREDRAW = 0x00000001,
CS_HREDRAW = 0x00000002,
CS_BYTEALIGNCLIENT = 0x00001000,
CS_BYTEALIGNWINDOW = 0x00002000,
CS_GLOBALCLASS = 0x00004000,
- CS_IME = 0x00010000
+ CS_IME = 0x00010000,
+ // Windows XP+
+ CS_DROPSHADOW = 0x00020000
}
internal enum SetWindowPosZOrder {
Last = 32651
}
+ private enum AncestorType {
+ GA_PARENT = 1,
+ GA_ROOT = 2,
+ GA_ROOTOWNER = 3
+ }
+
[Flags]
private enum WindowLong {
GWL_WNDPROC = -4,
internal byte tmStruckOut;
internal byte tmPitchAndFamily;
internal byte tmCharSet;
- }
+ }
+
+ public enum TernaryRasterOperations : uint
+ {
+ SRCCOPY = 0x00CC0020,
+ SRCPAINT = 0x00EE0086,
+ SRCAND = 0x008800C6,
+ SRCINVERT = 0x00660046,
+ SRCERASE = 0x00440328,
+ NOTSRCCOPY = 0x00330008,
+ NOTSRCERASE = 0x001100A6,
+ MERGECOPY = 0x00C000CA,
+ MERGEPAINT = 0x00BB0226,
+ PATCOPY = 0x00F00021,
+ PATPAINT = 0x00FB0A09,
+ PATINVERT = 0x005A0049,
+ DSTINVERT = 0x00550009,
+ BLACKNESS = 0x00000042,
+ WHITENESS = 0x00FF0062
+ }
[Flags]
private enum ScrollWindowExFlags {
NIF_MESSAGE = 0x00000001,
NIF_ICON = 0x00000002,
NIF_TIP = 0x00000004,
+ NIF_STATE = 0x00000008,
+ NIF_INFO = 0x00000010
}
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
internal struct NOTIFYICONDATA {
- internal uint cbSize;
- internal IntPtr hWnd;
- internal uint uID;
+ internal uint cbSize;
+ internal IntPtr hWnd;
+ internal uint uID;
internal NotifyIconFlags uFlags;
- internal uint uCallbackMessage;
- internal IntPtr hIcon;
+ internal uint uCallbackMessage;
+ internal IntPtr hIcon;
+ [MarshalAs(UnmanagedType.ByValTStr, SizeConst=128)]
+ internal string szTip;
+ internal int dwState;
+ internal int dwStateMask;
+ [MarshalAs(UnmanagedType.ByValTStr, SizeConst=256)]
+ internal string szInfo;
+ internal int uTimeoutOrVersion;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=64)]
- internal string szTip;
+ internal string szInfoTitle;
+ internal ToolTipIcon dwInfoFlags;
}
[Flags]
PS_ALTERNATE = 8
}
+ internal enum PatBltRop : int {
+ PATCOPY = 0xf00021,
+ PATINVERT = 0x5a0049,
+ DSTINVERT = 0x550009,
+ BLACKNESS = 0x000042,
+ WHITENESS = 0xff0062,
+ }
+
internal enum StockObject : int {
WHITE_BRUSH = 0,
LTGRAY_BRUSH = 1,
LWA_ALPHA = 0x2,
}
-
+ public enum ACLineStatus : byte {
+ Offline = 0,
+ Online = 1,
+ Unknown = 255
+ }
+
+ public enum BatteryFlag : byte {
+ High = 1,
+ Low = 2,
+ Critical = 4,
+ Charging = 8,
+ NoSystemBattery = 128,
+ Unknown = 255
+ }
+
+ [StructLayout (LayoutKind.Sequential)]
+ public class SYSTEMPOWERSTATUS {
+ public ACLineStatus _ACLineStatus;
+ public BatteryFlag _BatteryFlag;
+ public Byte _BatteryLifePercent;
+ public Byte _Reserved1;
+ public Int32 _BatteryLifeTime;
+ public Int32 _BatteryFullLifeTime;
+ }
#endregion
#region Constructor & Destructor
private XplatUIWin32() {
- WNDCLASS wndClass;
- bool result;
-
// Handle singleton stuff first
ref_count=0;
- DnD = new Win32DnD();
-
mouse_state = MouseButtons.None;
mouse_position = Point.Empty;
+ grab_confined = false;
+ grab_area = Rectangle.Empty;
+
message_queue = new Queue();
themes_enabled = false;
- // Prepare 'our' window class
- wnd_proc = new WndProc(NativeWindow.WndProc);
- wndClass.style = (int)(ClassStyle.CS_OWNDC | ClassStyle.CS_DBLCLKS);
- wndClass.lpfnWndProc = wnd_proc;
- wndClass.cbClsExtra = 0;
- wndClass.cbWndExtra = 0;
- wndClass.hbrBackground = IntPtr.Zero;
- wndClass.hCursor = Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW);
- wndClass.hIcon = IntPtr.Zero;
- wndClass.hInstance = IntPtr.Zero;
- wndClass.lpszClassName = XplatUI.DefaultClassName;
- wndClass.lpszMenuName = "";
-
- result=Win32RegisterClass(ref wndClass);
- if (result==false) {
- Win32MessageBox(IntPtr.Zero, "Could not register the "+XplatUI.DefaultClassName+" window class, win32 error " + Win32GetLastError().ToString(), "Oops", 0);
- }
+ wnd_proc = new WndProc(InternalWndProc);
- FosterParent=Win32CreateWindow((int)WindowExStyles.WS_EX_TOOLWINDOW, "static", "Foster Parent Window", (int)WindowStyles.WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
+ FosterParent=Win32CreateWindow(WindowExStyles.WS_EX_TOOLWINDOW, "static", "Foster Parent Window", WindowStyles.WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
if (FosterParent==IntPtr.Zero) {
Win32MessageBox(IntPtr.Zero, "Could not create foster window, win32 error " + Win32GetLastError().ToString(), "Oops", 0);
scroll_width = Win32GetSystemMetrics(SystemMetrics.SM_CXVSCROLL);
timer_list = new Hashtable ();
+ registered_classes = new Hashtable ();
}
#endregion // Constructor & Destructor
#region Private Support Methods
- private static IntPtr DefWndProc(IntPtr hWnd, Msg msg, IntPtr wParam, IntPtr lParam) {
- return Win32DefWindowProc(hWnd, msg, wParam, lParam);
- }
- private static bool MessageWaiting {
- get {
- if (message_queue.Count == 0) {
- return false;
- }
- return true;
+ private string RegisterWindowClass (int classStyle)
+ {
+ string class_name;
+
+ lock (registered_classes) {
+ class_name = (string)registered_classes[classStyle];
+
+ if (class_name != null)
+ return class_name;
+
+ class_name = string.Format ("Mono.WinForms.{0}.{1}", System.Threading.Thread.GetDomainID ().ToString (), classStyle);
+
+ WNDCLASS wndClass;
+
+ wndClass.style = classStyle;
+ wndClass.lpfnWndProc = wnd_proc;
+ wndClass.cbClsExtra = 0;
+ wndClass.cbWndExtra = 0;
+ wndClass.hbrBackground = (IntPtr)(GetSysColorIndex.COLOR_WINDOW + 1);
+ wndClass.hCursor = Win32LoadCursor (IntPtr.Zero, LoadCursorType.IDC_ARROW);
+ wndClass.hIcon = IntPtr.Zero;
+ wndClass.hInstance = IntPtr.Zero;
+ wndClass.lpszClassName = class_name;
+ wndClass.lpszMenuName = "";
+
+ bool result = Win32RegisterClass (ref wndClass);
+
+ if (result == false)
+ Win32MessageBox (IntPtr.Zero, "Could not register the window class, win32 error " + Win32GetLastError ().ToString (), "Oops", 0);
+
+ registered_classes[classStyle] = class_name;
}
+
+ return class_name;
}
private static bool RetrieveMessage(ref MSG msg) {
return dup;
}
+
+ private int GetSystemParametersInfoInt (SPIAction spi)
+ {
+ int value = 0;
+
+ Win32SystemParametersInfo (spi, 0, ref value, 0);
+
+ return value;
+ }
+
+ private bool GetSystemParametersInfoBool (SPIAction spi)
+ {
+ bool value = false;
+
+ Win32SystemParametersInfo (spi, 0, ref value, 0);
+
+ return value;
+ }
#endregion // Private Support Methods
#region Static Properties
+ internal override int ActiveWindowTrackingDelay {
+ get { return GetSystemParametersInfoInt (SPIAction.SPI_GETACTIVEWNDTRKTIMEOUT); }
+ }
+
+ internal override int CaretWidth {
+ get {
+ // Supported on 2k, XP, 2k3 +
+ if (Environment.OSVersion.Version.Major < 5)
+ throw new NotSupportedException ();
+
+ return GetSystemParametersInfoInt (SPIAction.SPI_GETCARETWIDTH);
+ }
+ }
+
+ internal override int FontSmoothingContrast {
+ get {
+ // Supported on XP, 2k3 +
+ if (Environment.OSVersion.Version.Major < 5 || (Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor == 0))
+ throw new NotSupportedException ();
+
+ return GetSystemParametersInfoInt (SPIAction.SPI_GETFONTSMOOTHINGCONTRAST);
+ }
+ }
+
+ internal override int FontSmoothingType {
+ get {
+ // Supported on XP, 2k3 +
+ if (Environment.OSVersion.Version.Major < 5 || (Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor == 0))
+ throw new NotSupportedException ();
+
+ return GetSystemParametersInfoInt (SPIAction.SPI_GETFONTSMOOTHINGTYPE);
+ }
+ }
+
+ internal override int HorizontalResizeBorderThickness {
+ get { return Win32GetSystemMetrics (SystemMetrics.SM_CXSIZEFRAME); }
+ }
+
+ internal override bool IsActiveWindowTrackingEnabled {
+ get { return GetSystemParametersInfoBool (SPIAction.SPI_GETACTIVEWINDOWTRACKING); }
+ }
+
+ internal override bool IsComboBoxAnimationEnabled {
+ get { return GetSystemParametersInfoBool (SPIAction.SPI_GETCOMBOBOXANIMATION); }
+ }
+
+ internal override bool IsDropShadowEnabled {
+ get {
+ // Supported on XP, 2k3 +
+ if (Environment.OSVersion.Version.Major < 5 || (Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor == 0))
+ throw new NotSupportedException ();
+
+ return GetSystemParametersInfoBool (SPIAction.SPI_GETDROPSHADOW);
+ }
+ }
+
+ internal override bool IsFontSmoothingEnabled {
+ get { return GetSystemParametersInfoBool (SPIAction.SPI_GETFONTSMOOTHING); }
+ }
+
+ internal override bool IsHotTrackingEnabled {
+ get { return GetSystemParametersInfoBool (SPIAction.SPI_GETHOTTRACKING); }
+ }
+
+ internal override bool IsIconTitleWrappingEnabled {
+ get { return GetSystemParametersInfoBool (SPIAction.SPI_GETICONTITLEWRAP); }
+ }
+
+ internal override bool IsKeyboardPreferred {
+ get { return GetSystemParametersInfoBool (SPIAction.SPI_GETKEYBOARDPREF); }
+ }
+
+ internal override bool IsListBoxSmoothScrollingEnabled {
+ get { return GetSystemParametersInfoBool (SPIAction.SPI_GETLISTBOXSMOOTHSCROLLING); }
+ }
+
+ internal override bool IsMenuAnimationEnabled {
+ get { return GetSystemParametersInfoBool (SPIAction.SPI_GETMENUANIMATION); }
+ }
+
+ internal override bool IsMenuFadeEnabled {
+ get { return GetSystemParametersInfoBool (SPIAction.SPI_GETMENUFADE); }
+ }
+
+ internal override bool IsMinimizeRestoreAnimationEnabled {
+ get {
+ ANIMATIONINFO ai = new ANIMATIONINFO ();
+ ai.cbSize = (uint)Marshal.SizeOf (ai);
+
+ Win32SystemParametersInfo (SPIAction.SPI_GETANIMATION, 0, ref ai, 0);
+ return ai.iMinAnimate == 0 ? false : true;
+ }
+ }
+
+ internal override bool IsSelectionFadeEnabled {
+ get { return GetSystemParametersInfoBool (SPIAction.SPI_GETSELECTIONFADE); }
+ }
+
+ internal override bool IsSnapToDefaultEnabled {
+ get { return GetSystemParametersInfoBool (SPIAction.SPI_GETSNAPTODEFBUTTON); }
+ }
+
+ internal override bool IsTitleBarGradientEnabled {
+ get { return GetSystemParametersInfoBool (SPIAction.SPI_GETGRADIENTCAPTIONS); }
+ }
+
+ internal override bool IsToolTipAnimationEnabled {
+ get { return GetSystemParametersInfoBool (SPIAction.SPI_GETTOOLTIPANIMATION); }
+ }
+
+ internal override Size MenuBarButtonSize {
+ get {
+ return new Size (Win32GetSystemMetrics (SystemMetrics.SM_CXMENUSIZE),
+ Win32GetSystemMetrics (SystemMetrics.SM_CYMENUSIZE));
+ }
+ }
+
+ public override Size MenuButtonSize {
+ get {
+ return new Size (
+ Win32GetSystemMetrics (SystemMetrics.SM_CXMENUSIZE),
+ Win32GetSystemMetrics (SystemMetrics.SM_CYMENUSIZE));
+ }
+ }
+
+ internal override int MenuShowDelay {
+ get { return GetSystemParametersInfoInt (SPIAction.SPI_GETMENUSHOWDELAY); }
+ }
+
+ internal override int MouseSpeed {
+ get { return GetSystemParametersInfoInt (SPIAction.SPI_GETMOUSESPEED); }
+ }
+
+ internal override LeftRightAlignment PopupMenuAlignment {
+ get { return GetSystemParametersInfoBool (SPIAction.SPI_GETMENUDROPALIGNMENT) == true ? LeftRightAlignment.Left : LeftRightAlignment.Right; }
+ }
+
+ internal override PowerStatus PowerStatus {
+ get {
+ SYSTEMPOWERSTATUS p = new SYSTEMPOWERSTATUS ();
+
+ Win32GetSystemPowerStatus (p);
+
+ PowerStatus ps = new PowerStatus ((BatteryChargeStatus)p._BatteryFlag, p._BatteryFullLifeTime, (float)p._BatteryLifePercent / 255f, p._BatteryLifeTime, (PowerLineStatus)p._ACLineStatus);
+
+ return ps;
+ }
+ }
+
+ internal override int SizingBorderWidth {
+ get { return Win32GetSystemMetrics (SystemMetrics.SM_CXSIZEFRAME); }
+ }
+
+ internal override Size SmallCaptionButtonSize {
+ get {
+ return new Size (Win32GetSystemMetrics (SystemMetrics.SM_CXSMSIZE),
+ Win32GetSystemMetrics (SystemMetrics.SM_CYSMSIZE));
+ }
+ }
+
+ internal override bool UIEffectsEnabled {
+ get { return GetSystemParametersInfoBool (SPIAction.SPI_GETUIEFFECTS); }
+ }
+
+ internal override int VerticalResizeBorderThickness {
+ get { return Win32GetSystemMetrics (SystemMetrics.SM_CYSIZEFRAME); }
+ }
+
+ internal override void RaiseIdle (EventArgs e)
+ {
+ if (Idle != null)
+ Idle (this, e);
+ }
+
internal override Keys ModifierKeys {
get {
short state;
}
}
+ internal override int MouseWheelScrollDelta {
+ get {
+ int delta = 120;
+ Win32SystemParametersInfo(SPIAction.SPI_GETWHEELSCROLLLINES, 0, ref delta, 0);
+ return delta;
+ }
+ }
+
internal override int HorizontalScrollBarHeight {
get {
return scroll_height;
}
}
+ internal override Size Border3DSize {
+ get {
+ return new Size (Win32GetSystemMetrics (SystemMetrics.SM_CXEDGE),
+ Win32GetSystemMetrics (SystemMetrics.SM_CYEDGE));
+ }
+ }
+
+ internal override Size BorderSize {
+ get {
+ return new Size (Win32GetSystemMetrics (SystemMetrics.SM_CXBORDER),
+ Win32GetSystemMetrics (SystemMetrics.SM_CYBORDER));
+ }
+ }
+
internal override bool DropTarget {
get {
return false;
}
}
- internal override int Caption {
+ internal override Size CaptionButtonSize {
+ get {
+ return new Size (Win32GetSystemMetrics (SystemMetrics.SM_CXSIZE),
+ Win32GetSystemMetrics (SystemMetrics.SM_CYSIZE));
+ }
+ }
+
+ internal override int CaptionHeight {
get {
return Win32GetSystemMetrics(SystemMetrics.SM_CYCAPTION);
}
internal override bool DragFullWindows {
get {
- return true;
+ int full = 0;
+ Win32SystemParametersInfo (SPIAction.SPI_GETDRAGFULLWINDOWS, 0, ref full, 0);
+ return (full != 0);
}
}
}
}
+ internal override Size DoubleClickSize {
+ get {
+ return new Size (Win32GetSystemMetrics (SystemMetrics.SM_CXDOUBLECLK),
+ Win32GetSystemMetrics (SystemMetrics.SM_CYDOUBLECLK));
+ }
+ }
+
+ internal override int DoubleClickTime {
+ get {
+ return Win32GetDoubleClickTime ();
+ }
+ }
+
+ internal override Size FixedFrameBorderSize {
+ get {
+ return new Size (Win32GetSystemMetrics (SystemMetrics.SM_CXFIXEDFRAME),
+ Win32GetSystemMetrics (SystemMetrics.SM_CYFIXEDFRAME));
+ }
+ }
+
internal override Size FrameBorderSize {
get {
return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXFRAME), Win32GetSystemMetrics(SystemMetrics.SM_CYFRAME));
}
}
+ internal override bool MenuAccessKeysUnderlined {
+ get {
+ int underlined = 0;
+ Win32SystemParametersInfo (SPIAction.SPI_GETKEYBOARDCUES, 0, ref underlined, 0);
+ return (underlined != 0);
+ }
+ }
+
internal override Size MinimizedWindowSize {
get {
return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXMINIMIZED), Win32GetSystemMetrics(SystemMetrics.SM_CYMINIMIZED));
return XplatUIWin32.themes_enabled;
}
}
-
+ internal override bool RequiresPositiveClientAreaSize {
+ get {
+ return false;
+ }
+ }
+
+ public override int ToolWindowCaptionHeight {
+ get {
+ return Win32GetSystemMetrics (SystemMetrics.SM_CYSMCAPTION);
+ }
+ }
+
+ public override Size ToolWindowCaptionButtonSize {
+ get {
+ return new Size (
+ Win32GetSystemMetrics (SystemMetrics.SM_CXSMSIZE),
+ Win32GetSystemMetrics (SystemMetrics.SM_CYSMSIZE));
+ }
+ }
#endregion // Static Properties
#region Singleton Specific Code
Console.WriteLine("Xplat version $revision: $");
}
- internal override void AudibleAlert() {
- Win32PlaySound("Default", IntPtr.Zero, SndFlags.SND_ALIAS | SndFlags.SND_ASYNC | SndFlags.SND_NOSTOP | SndFlags.SND_NOWAIT);
+ string GetSoundAlias (AlertType alert)
+ {
+ switch (alert) {
+ case AlertType.Error:
+ return "SystemHand";
+ case AlertType.Question:
+ return "SystemQuestion";
+ case AlertType.Warning:
+ return "SystemExclamation";
+ case AlertType.Information:
+ return "SystemAsterisk";
+ default:
+ return "SystemDefault";
+ }
+ }
+
+ internal override void AudibleAlert(AlertType alert) {
+ Win32PlaySound(GetSoundAlias (alert), IntPtr.Zero, SndFlags.SND_ALIAS_ID | SndFlags.SND_ASYNC | SndFlags.SND_NOSTOP | SndFlags.SND_NOWAIT);
+ }
+
+ internal override void BeginMoveResize (IntPtr handle) {
}
internal override void GetDisplaySize(out Size size) {
ParentHandle = FosterParent;
}
- // Since we fake MDI dont tell Windows that this is a real MDI window
- if ((cp.ExStyle & (int) WindowExStyles.WS_EX_MDICHILD) != 0) {
- SetMdiStyles (cp);
+ Point location;
+ if (cp.HasWindowManager) {
+ location = Hwnd.GetNextStackedFormLocation (cp, Hwnd.ObjectFromHandle (cp.Parent));
+ } else {
+ location = new Point (cp.X, cp.Y);
}
- WindowHandle = Win32CreateWindow((uint)cp.ExStyle, cp.ClassName, cp.Caption, (uint)cp.Style, cp.X, cp.Y, cp.Width, cp.Height, ParentHandle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
+ string class_name = RegisterWindowClass (cp.ClassStyle);
+ HwndCreating = hwnd;
+
+ // We cannot actually send the WS_EX_MDICHILD flag to Windows because we
+ // are faking MDI, not uses Windows' version.
+ if ((cp.WindowExStyle & WindowExStyles.WS_EX_MDICHILD) == WindowExStyles.WS_EX_MDICHILD)
+ cp.WindowExStyle ^= WindowExStyles.WS_EX_MDICHILD;
+
+ WindowHandle = Win32CreateWindow (cp.WindowExStyle, class_name, cp.Caption, cp.WindowStyle, location.X, location.Y, cp.Width, cp.Height, ParentHandle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
+
+ HwndCreating = null;
if (WindowHandle==IntPtr.Zero) {
- uint error = Win32GetLastError();
+ int error = Marshal.GetLastWin32Error ();
Win32MessageBox(IntPtr.Zero, "Error : " + error.ToString(), "Failed to create window, class '"+cp.ClassName+"'", 0);
}
hwnd.ClientWindow = WindowHandle;
-
+ hwnd.Mapped = true;
Win32SetWindowLong(WindowHandle, WindowLong.GWL_USERDATA, (uint)ThemeEngine.Current.DefaultControlBackColor.ToArgb());
return WindowHandle;
create_params.Width = Width;
create_params.Height = Height;
- create_params.ClassName=XplatUI.DefaultClassName;
+ create_params.ClassName=XplatUI.GetDefaultClassName (GetType ());
create_params.ClassStyle = 0;
create_params.ExStyle=0;
create_params.Parent=IntPtr.Zero;
internal override void SetWindowStyle(IntPtr handle, CreateParams cp) {
- if ((cp.ExStyle & (int) WindowExStyles.WS_EX_MDICHILD) != 0) {
- SetMdiStyles (cp);
- }
-
Win32SetWindowLong(handle, WindowLong.GWL_STYLE, (uint)cp.Style);
Win32SetWindowLong(handle, WindowLong.GWL_EXSTYLE, (uint)cp.ExStyle);
+
+ // From MSDN:
+ // Certain window data is cached, so changes you make using SetWindowLong
+ // will not take effect until you call the SetWindowPos function. Specifically,
+ // if you change any of the frame styles, you must call SetWindowPos with
+ // the SWP_FRAMECHANGED flag for the cache to be updated properly.
+ if (cp.control is Form)
+ XplatUI.RequestNCRecalc (handle);
+ }
+
+ internal override double GetWindowTransparency(IntPtr handle)
+ {
+ LayeredWindowAttributes lwa;
+ COLORREF clrRef;
+ byte alpha;
+
+ if (0 == Win32GetLayeredWindowAttributes (handle, out clrRef, out alpha, out lwa))
+ return 1.0;
+
+ return ((double)alpha) / 255.0;
}
-
internal override void SetWindowTransparency(IntPtr handle, double transparency, Color key) {
LayeredWindowAttributes lwa = LayeredWindowAttributes.LWA_ALPHA;
byte opacity = (byte)(transparency*255);
Win32SetLayeredWindowAttributes(handle, clrRef, opacity, lwa);
}
- internal override bool SupportsTransparency() {
- // We might check with the OS, but I think we're only >=W2k
- return true;
+ TransparencySupport support;
+ bool queried_transparency_support;
+ internal override TransparencySupport SupportsTransparency() {
+ if (queried_transparency_support)
+ return support;
+
+ bool flag;
+ support = TransparencySupport.None;
+
+ flag = true;
+ try {
+ Win32SetLayeredWindowAttributes (IntPtr.Zero, new COLORREF (), 255, LayeredWindowAttributes.LWA_ALPHA);
+ }
+ catch (EntryPointNotFoundException) { flag = false; }
+ catch { /* swallow everything else */ }
+
+ if (flag) support |= TransparencySupport.Set;
+
+ flag = true;
+ try {
+ LayeredWindowAttributes lwa;
+ COLORREF clrRef;
+ byte alpha;
+
+ Win32GetLayeredWindowAttributes (IntPtr.Zero, out clrRef, out alpha, out lwa);
+ }
+ catch (EntryPointNotFoundException) { flag = false; }
+ catch { /* swallow everything else */ }
+
+ if (flag) support |= TransparencySupport.Get;
+
+ queried_transparency_support = true;
+ return support;
}
internal override void UpdateWindow(IntPtr handle) {
Win32UpdateWindow(handle);
}
- internal override PaintEventArgs PaintEventStart(IntPtr handle, bool client) {
+ internal override PaintEventArgs PaintEventStart(ref Message msg, IntPtr handle, bool client) {
IntPtr hdc;
PAINTSTRUCT ps;
PaintEventArgs paint_event;
rect = new RECT();
ps = new PAINTSTRUCT();
- hwnd = Hwnd.ObjectFromHandle(handle);
-
+ hwnd = Hwnd.ObjectFromHandle(msg.HWnd);
+
if (client) {
- if (Win32GetUpdateRect(handle, ref rect, false)) {
- hdc = Win32BeginPaint(handle, ref ps);
-
- hwnd.user_data = (object)ps;
-
- clip_rect = new Rectangle(ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right-ps.rcPaint.left, ps.rcPaint.bottom-ps.rcPaint.top);
+ if (Win32GetUpdateRect(msg.HWnd, ref rect, false)) {
+ if (handle != msg.HWnd) {
+ // We need to validate the window where the paint message
+ // was generated, otherwise we'll never stop getting paint
+ // messages.
+ Win32GetClientRect (msg.HWnd, out rect);
+ Win32ValidateRect (msg.HWnd, ref rect);
+ hdc = Win32GetDC (handle);
+ } else {
+ hdc = Win32BeginPaint (handle, ref ps);
+ rect = ps.rcPaint;
+ }
} else {
hdc = Win32GetDC(handle);
- // FIXME: Add the DC to internal list
- clip_rect = new Rectangle(rect.top, rect.left, rect.right-rect.left, rect.bottom-rect.top);
}
+ clip_rect = rect.ToRectangle ();
} else {
hdc = Win32GetWindowDC (handle);
- hwnd.user_data = (object)hdc;
// HACK this in for now
Win32GetWindowRect (handle, out rect);
- clip_rect = new Rectangle(0, 0, rect.right-rect.left, rect.bottom-rect.top);
+ clip_rect = new Rectangle (0, 0, rect.Width, rect.Height);
}
- hwnd.client_dc = Graphics.FromHdc(hdc);
- paint_event = new PaintEventArgs(hwnd.client_dc, clip_rect);
+ // If we called BeginPaint, store the PAINTSTRUCT,
+ // otherwise store hdc, so that PaintEventEnd can know
+ // whether to call EndPaint or ReleaseDC.
+ if (ps.hdc != IntPtr.Zero) {
+ hwnd.drawing_stack.Push (ps);
+ } else {
+ hwnd.drawing_stack.Push (hdc);
+ }
+
+ Graphics dc = Graphics.FromHdc(hdc);
+ hwnd.drawing_stack.Push (dc);
+
+ paint_event = new PaintEventArgs(dc, clip_rect);
return paint_event;
}
- internal override void PaintEventEnd(IntPtr handle, bool client) {
+ internal override void PaintEventEnd(ref Message m, IntPtr handle, bool client) {
Hwnd hwnd;
- PAINTSTRUCT ps;
- hwnd = Hwnd.ObjectFromHandle(handle);
- hwnd.client_dc.Dispose();
+ hwnd = Hwnd.ObjectFromHandle(m.HWnd);
- if (client) {
- if (hwnd.user_data != null) {
- ps = (PAINTSTRUCT)hwnd.user_data;
- Win32EndPaint(handle, ref ps);
- hwnd.user_data = null;
- }
- } else {
- if (hwnd.user_data != null) {
- Win32ReleaseDC(handle, (IntPtr)hwnd.user_data);
- hwnd.user_data = null;
- }
+ Graphics dc = (Graphics)hwnd.drawing_stack.Pop();
+ dc.Dispose ();
+
+ object o = hwnd.drawing_stack.Pop();
+ if (o is IntPtr) {
+ IntPtr hdc = (IntPtr) o;
+ Win32ReleaseDC (handle, hdc);
+ } else if (o is PAINTSTRUCT) {
+ PAINTSTRUCT ps = (PAINTSTRUCT) o;
+ Win32EndPaint (handle, ref ps);
}
}
pt.x=rect.left;
pt.y=rect.top;
- parent = Win32GetParent(handle);
- Win32ScreenToClient(parent, ref pt);
+ parent = Win32GetAncestor (handle, AncestorType.GA_PARENT);
+ if (parent != IntPtr.Zero && parent != Win32GetDesktopWindow ())
+ Win32ScreenToClient(parent, ref pt);
x = pt.x;
y = pt.y;
internal override void Activate(IntPtr handle) {
Win32SetActiveWindow(handle);
+ // delayed timer enabled
+ lock (timer_list) {
+ foreach (Timer t in timer_list.Values) {
+ if (t.Enabled && t.window == IntPtr.Zero) {
+ t.window = handle;
+ int id = t.GetHashCode ();
+ Win32SetTimer(handle, id, (uint)t.Interval, IntPtr.Zero);
+ }
+ }
+ }
}
internal override void Invalidate(IntPtr handle, Rectangle rc, bool clear) {
Win32InvalidateRect(handle, ref rect, clear);
}
+
+ internal override void InvalidateNC (IntPtr handle)
+ {
+ // found this gem at
+ // http://www.dotnet247.com/247reference/msgs/58/292037.aspx
+ Win32SetWindowPos(handle, IntPtr.Zero,
+ 0, 0, 0, 0,
+ SetWindowPosFlags.SWP_NOMOVE |
+ SetWindowPosFlags.SWP_NOSIZE |
+ SetWindowPosFlags.SWP_NOZORDER |
+ SetWindowPosFlags.SWP_NOACTIVATE |
+ SetWindowPosFlags.SWP_DRAWFRAME);
+ }
+
+ private IntPtr InternalWndProc (IntPtr hWnd, Msg msg, IntPtr wParam, IntPtr lParam)
+ {
+ if (HwndCreating != null && HwndCreating.ClientWindow == IntPtr.Zero)
+ HwndCreating.ClientWindow = hWnd;
+ return NativeWindow.WndProc (hWnd, msg, wParam, lParam);
+ }
+
internal override IntPtr DefWndProc(ref Message msg) {
msg.Result=Win32DefWindowProc(msg.HWnd, (Msg)msg.Msg, msg.WParam, msg.LParam);
return msg.Result;
internal override void DoEvents() {
MSG msg = new MSG();
- if (override_cursor != IntPtr.Zero) {
- Cursor.Current = null;
- }
-
while (GetMessage(ref msg, IntPtr.Zero, 0, 0, false)) {
+ Message m = Message.Create (msg.hwnd, (int)msg.message, msg.wParam, msg.lParam);
+
+ if (Application.FilterMessage (ref m))
+ continue;
+
XplatUI.TranslateMessage(ref msg);
XplatUI.DispatchMessage(ref msg);
}
Win32PostQuitMessage(exitCode);
}
+ internal override void RequestAdditionalWM_NCMessages(IntPtr hwnd, bool hover, bool leave)
+ {
+ if (wm_nc_registered == null)
+ wm_nc_registered = new Hashtable ();
+
+ TMEFlags flags = TMEFlags.TME_NONCLIENT;
+ if (hover)
+ flags |= TMEFlags.TME_HOVER;
+ if (leave)
+ flags |= TMEFlags.TME_LEAVE;
+
+ if (flags == TMEFlags.TME_NONCLIENT) {
+ if (wm_nc_registered.Contains (hwnd)) {
+ wm_nc_registered.Remove (hwnd);
+ }
+ } else {
+ if (!wm_nc_registered.Contains (hwnd)) {
+ wm_nc_registered.Add (hwnd, flags);
+ } else {
+ wm_nc_registered [hwnd] = flags;
+ }
+ }
+ }
+
internal override void RequestNCRecalc(IntPtr handle) {
- Win32SetWindowPos(handle, IntPtr.Zero, 0, 0, 0, 0, SetWindowPosFlags.SWP_FRAMECHANGED | SetWindowPosFlags.SWP_NOOWNERZORDER | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOMOVE);
+ Win32SetWindowPos(handle, IntPtr.Zero, 0, 0, 0, 0, SetWindowPosFlags.SWP_FRAMECHANGED | SetWindowPosFlags.SWP_NOOWNERZORDER | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_NOACTIVATE);
}
internal override void ResetMouseHover(IntPtr handle) {
private bool GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, bool blocking) {
bool result;
+ msg.refobject = 0;
if (RetrieveMessage(ref msg)) {
return true;
}
}
}
- // We need to fake WM_MOUSE_ENTER/WM_MOUSE_LEAVE
+ // We need to fake WM_MOUSE_ENTER
switch (msg.message) {
case Msg.WM_LBUTTONDOWN: {
mouse_state |= MouseButtons.Left;
if (msg.hwnd != prev_mouse_hwnd) {
TRACKMOUSEEVENT tme;
+ mouse_state = Control.FromParamToMouseButtons ((int)msg.lParam.ToInt32());
+
// The current message will be sent out next time around
StoreMessage(ref msg);
break;
}
+ case Msg.WM_NCMOUSEMOVE: {
+ if (wm_nc_registered == null || !wm_nc_registered.Contains (msg.hwnd))
+ break;
+
+ mouse_state = Control.FromParamToMouseButtons ((int)msg.lParam.ToInt32 ());
+
+ TRACKMOUSEEVENT tme;
+
+ tme = new TRACKMOUSEEVENT ();
+ tme.size = Marshal.SizeOf(tme);
+ tme.hWnd = msg.hwnd;
+ tme.dwFlags = (TMEFlags)wm_nc_registered[msg.hwnd];
+ Win32TrackMouseEvent (ref tme);
+ return result;
+ }
+
case Msg.WM_DROPFILES: {
return Win32DnD.HandleWMDropFiles(ref msg);
}
case Msg.WM_MOUSELEAVE: {
prev_mouse_hwnd = IntPtr.Zero;
- msg.message=Msg.WM_MOUSE_LEAVE;
break;
}
return false;
}
- internal override bool SetTopmost(IntPtr hWnd, IntPtr hWndOwner, bool Enabled) {
+ internal override bool SetTopmost(IntPtr hWnd, bool Enabled) {
if (Enabled) {
- Win32SetWindowPos(hWnd, SetWindowPosZOrder.HWND_TOPMOST, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
+ Win32SetWindowPos(hWnd, SetWindowPosZOrder.HWND_TOPMOST, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOACTIVATE);
return true;
} else {
- Win32SetWindowPos(hWnd, SetWindowPosZOrder.HWND_NOTOPMOST, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
+ Win32SetWindowPos(hWnd, SetWindowPosZOrder.HWND_NOTOPMOST, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOACTIVATE);
return true;
}
}
+
+ internal override bool SetOwner(IntPtr hWnd, IntPtr hWndOwner) {
+ Win32SetWindowLong(hWnd, WindowLong.GWL_HWNDPARENT, (uint) hWndOwner);
+ return true;
+ }
internal override bool Text(IntPtr handle, string text) {
Win32SetWindowText(handle, text);
return true;
}
- internal override bool SetVisible(IntPtr handle, bool visible) {
+ internal override bool SetVisible (IntPtr handle, bool visible, bool activate)
+ {
if (visible) {
- if (Control.FromHandle(handle) is Form) {
+ Control c = Control.FromHandle (handle);
+ if (c is Form) {
Form f;
- f = (Form)Control.FromHandle(handle);
+ f = (Form)Control.FromHandle (handle);
+ WindowPlacementFlags flags = WindowPlacementFlags.SW_SHOWNORMAL;
switch (f.WindowState) {
- case FormWindowState.Normal: Win32ShowWindow(handle, WindowPlacementFlags.SW_SHOWNORMAL); break;
- case FormWindowState.Minimized: Win32ShowWindow(handle, WindowPlacementFlags.SW_MINIMIZE); break;
- case FormWindowState.Maximized: Win32ShowWindow(handle, WindowPlacementFlags.SW_MAXIMIZE); break;
+ case FormWindowState.Normal: flags = WindowPlacementFlags.SW_SHOWNORMAL; break;
+ case FormWindowState.Minimized: flags = WindowPlacementFlags.SW_MINIMIZE; break;
+ case FormWindowState.Maximized: flags = WindowPlacementFlags.SW_MAXIMIZE; break;
}
- } else {
- Win32ShowWindow(handle, WindowPlacementFlags.SW_SHOWNORMAL);
+
+ if (!f.ActivateOnShow)
+ flags = WindowPlacementFlags.SW_SHOWNOACTIVATE;
+
+ Win32ShowWindow (handle, flags);
+ }
+ else {
+ if (c.ActivateOnShow)
+ Win32ShowWindow (handle, WindowPlacementFlags.SW_SHOWNORMAL);
+ else
+ Win32ShowWindow (handle, WindowPlacementFlags.SW_SHOWNOACTIVATE);
}
- } else {
- Win32ShowWindow(handle, WindowPlacementFlags.SW_HIDE);
+ }
+ else {
+ Win32ShowWindow (handle, WindowPlacementFlags.SW_HIDE);
}
return true;
}
internal override bool IsEnabled(IntPtr handle) {
return IsWindowEnabled (handle);
}
+
+ internal override bool IsKeyLocked (VirtualKeys key)
+ {
+ return (Win32GetKeyState (key) & 1) == 1;
+ }
internal override bool IsVisible(IntPtr handle) {
return IsWindowVisible (handle);
}
internal override IntPtr SetParent(IntPtr handle, IntPtr parent) {
- return Win32SetParent(handle, parent);
+ Control c = Control.FromHandle (handle);
+ if (parent == IntPtr.Zero) {
+ if (!(c is Form)) {
+ Win32ShowWindow(handle, WindowPlacementFlags.SW_HIDE);
+ }
+ } else {
+ if (!(c is Form)) {
+ SetVisible (handle, c.is_visible, true);
+ }
+ }
+ // The Win32SetParent is lame, it can very well move the window
+ // ref: http://groups.google.com/group/microsoft.public.vb.winapi/browse_thread/thread/1b82ccc54231ecee/afa82835bfc0422a%23afa82835bfc0422a
+ // Here we save the position before changing the parent, and if it has changed afterwards restore it.
+ // Another possibility would be to intercept WM_WINDOWPOSCHANGING and restore the coords there, but this would require plumbing in weird places
+ // (either inside Control or add handling to InternalWndProc)
+ // We also need to remove WS_CHILD if making the window parent-less, and add it if we're parenting it.
+ RECT rect, rect2;
+ IntPtr result;
+ WindowStyles style, new_style;
+
+ Win32GetWindowRect (handle, out rect);
+ style = (WindowStyles) Win32GetWindowLong (handle, WindowLong.GWL_STYLE);
+
+ if (parent == IntPtr.Zero) {
+ new_style = style & ~WindowStyles.WS_CHILD;
+ result = Win32SetParent (handle, FosterParent);
+ } else {
+ new_style = style | WindowStyles.WS_CHILD;
+ result = Win32SetParent (handle, parent);
+ }
+ if (style != new_style && c is Form) {
+ Win32SetWindowLong (handle, WindowLong.GWL_STYLE, (uint) new_style);
+ }
+ Win32GetWindowRect (handle, out rect2);
+ if (rect.top != rect2.top && rect.left != rect2.left && c is Form) {
+ Win32SetWindowPos (handle, IntPtr.Zero, rect.top, rect.left, rect.Width, rect.Height, SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_NOREDRAW | SetWindowPosFlags.SWP_NOOWNERZORDER | SetWindowPosFlags.SWP_NOENDSCHANGING | SetWindowPosFlags.SWP_NOACTIVATE);
+ }
+ return result;
}
+ // If we ever start using this, we should probably replace FosterParent with IntPtr.Zero
internal override IntPtr GetParent(IntPtr handle) {
return Win32GetParent(handle);
}
+ // This is a nop on win32 and x11
+ internal override IntPtr GetPreviousWindow(IntPtr handle) {
+ return handle;
+ }
+
internal override void GrabWindow(IntPtr hWnd, IntPtr ConfineToHwnd) {
grab_hwnd = hWnd;
Win32SetCapture(hWnd);
+
+ if (ConfineToHwnd != IntPtr.Zero) {
+ RECT window_rect;
+ Win32GetWindowRect (ConfineToHwnd, out window_rect);
+ Win32GetClipCursor (out clipped_cursor_rect);
+ Win32ClipCursor (ref window_rect);
+ }
}
internal override void GrabInfo(out IntPtr hWnd, out bool GrabConfined, out Rectangle GrabArea) {
}
internal override void UngrabWindow(IntPtr hWnd) {
+ if (!(clipped_cursor_rect.top == 0 && clipped_cursor_rect.bottom == 0 && clipped_cursor_rect.left == 0 && clipped_cursor_rect.right == 0)) {
+ Win32ClipCursor (ref clipped_cursor_rect);
+ clipped_cursor_rect = new RECT ();
+ }
+
Win32ReleaseCapture();
grab_hwnd = IntPtr.Zero;
}
- internal override bool CalculateWindowRect(ref Rectangle ClientRect, int Style, int ExStyle, Menu menu, out Rectangle WindowRect) {
+ internal override bool CalculateWindowRect(ref Rectangle ClientRect, CreateParams cp, Menu menu, out Rectangle WindowRect) {
RECT rect;
rect.left=ClientRect.Left;
rect.right=ClientRect.Right;
rect.bottom=ClientRect.Bottom;
- if (!Win32AdjustWindowRectEx(ref rect, Style, menu != null, ExStyle)) {
+ if (!Win32AdjustWindowRectEx(ref rect, cp.Style, menu != null, cp.ExStyle)) {
WindowRect = new Rectangle(ClientRect.Left, ClientRect.Top, ClientRect.Width, ClientRect.Height);
return false;
}
return cursor;
}
+ internal override Bitmap DefineStdCursorBitmap (StdCursor id)
+ {
+ // We load the cursor, create a bitmap, draw the cursor onto the bitmap and return the bitmap.
+ IntPtr cursor = DefineStdCursor (id);
+ // Windows only have one possible cursor size!
+ int width = Win32GetSystemMetrics (SystemMetrics.SM_CXCURSOR);
+ int height = Win32GetSystemMetrics (SystemMetrics.SM_CYCURSOR);
+ Bitmap bmp = new Bitmap (width, height);
+ Graphics gc = Graphics.FromImage (bmp);
+ IntPtr hdc = gc.GetHdc ();
+ Win32DrawIcon (hdc, 0, 0, cursor);
+ gc.ReleaseHdc (hdc);
+ gc.Dispose ();
+ return bmp;
+ }
+
[MonoTODO("Define the missing cursors")]
internal override IntPtr DefineStdCursor(StdCursor id) {
switch(id) {
[MonoTODO]
internal override void GetCursorInfo(IntPtr cursor, out int width, out int height, out int hotspot_x, out int hotspot_y) {
+ ICONINFO ii = new ICONINFO ();
+
+ if (!Win32GetIconInfo (cursor, out ii))
+ throw new Win32Exception ();
+
width = 20;
height = 20;
- hotspot_x = 0;
- hotspot_y = 0;
+ hotspot_x = ii.xHotspot;
+ hotspot_y = ii.yHotspot;
}
internal override void SetCursorPos(IntPtr handle, int x, int y) {
}
internal override void SetClipRegion(IntPtr hwnd, Region region) {
- Win32SetWindowRgn(hwnd, region.GetHrgn(Graphics.FromHwnd(hwnd)), true);
+ if (region == null)
+ Win32SetWindowRgn (hwnd, IntPtr.Zero, true);
+ else
+ Win32SetWindowRgn(hwnd, region.GetHrgn(Graphics.FromHwnd(hwnd)), true);
}
internal override void EnableWindow(IntPtr handle, bool Enable) {
Win32GetWindowRect(handle, out rect);
x -= rect.left + SystemInformation.FrameBorderSize.Width;
- y -= rect.top + SystemInformation.FrameBorderSize.Height + ThemeEngine.Current.CaptionHeight;
- return;
+ y -= rect.top + SystemInformation.FrameBorderSize.Height;
+
+ WindowStyles style = (WindowStyles) Win32GetWindowLong (handle, WindowLong.GWL_STYLE);
+ if (CreateParams.IsSet (style, WindowStyles.WS_CAPTION)) {
+ y -= ThemeEngine.Current.CaptionHeight;
+ }
}
internal override void MenuToScreen(IntPtr handle, ref int x, ref int y) {
y += rect.top + SystemInformation.FrameBorderSize.Height + ThemeEngine.Current.CaptionHeight;
return;
}
-
+
internal override void SendAsyncMethod (AsyncMethodData method)
{
Win32PostMessage(FosterParent, Msg.WM_ASYNC_MESSAGE, IntPtr.Zero, (IntPtr)GCHandle.Alloc (method));
timer_list[index]=timer;
}
- Win32SetTimer(FosterParent, index, (uint)timer.Interval, IntPtr.Zero);
+ if (Win32SetTimer(FosterParent, index, (uint)timer.Interval, IntPtr.Zero) != IntPtr.Zero)
+ timer.window = FosterParent;
+ else
+ timer.window = IntPtr.Zero;
}
internal override void KillTimer (Timer timer)
index = timer.GetHashCode();
- Win32KillTimer(FosterParent, index);
+ Win32KillTimer(timer.window, index);
lock (timer_list) {
timer_list.Remove(index);
}
}
-
-
- private void CaretCallback(object sender, EventArgs e) {
- Console.WriteLine("CaretCallback hit");
- }
-
- private void SetMdiStyles (CreateParams cp)
- {
- cp.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
- cp.ExStyle = 0;
- }
-
+
internal override void CreateCaret(IntPtr hwnd, int width, int height) {
Win32CreateCaret(hwnd, IntPtr.Zero, width, height);
caret_visible = false;
internal override bool GetFontMetrics(Graphics g, Font font, out int ascent, out int descent) {
IntPtr dc;
+ IntPtr prevobj;
TEXTMETRIC tm;
tm = new TEXTMETRIC();
- dc = Win32GetDC(IntPtr.Zero);
- Win32SelectObject(dc, font.ToHfont());
- if (Win32GetTextMetrics(dc, ref tm) == false) {
- Win32ReleaseDC(IntPtr.Zero, dc);
+ dc = Win32GetDC (IntPtr.Zero);
+ prevobj = Win32SelectObject (dc, font.ToHfont ());
+
+ if (Win32GetTextMetrics (dc, ref tm) == false) {
+ prevobj = Win32SelectObject (dc, prevobj);
+ Win32DeleteObject (prevobj);
+ Win32ReleaseDC (IntPtr.Zero, dc);
ascent = 0;
descent = 0;
return false;
}
- Win32ReleaseDC(IntPtr.Zero, dc);
+ prevobj = Win32SelectObject (dc, prevobj);
+ Win32DeleteObject (prevobj);
+ Win32ReleaseDC (IntPtr.Zero, dc);
ascent = tm.tmAscent;
descent = tm.tmDescent;
Win32Shell_NotifyIcon(NotifyIconMessage.NIM_DELETE, ref nid);
}
+ internal override void SystrayBalloon(IntPtr hwnd, int timeout, string title, string text, ToolTipIcon icon)
+ {
+ NOTIFYICONDATA nid;
- internal override void SetBorderStyle(IntPtr handle, FormBorderStyle border_style) {
- uint style;
- uint exstyle;
-
- style = Win32GetWindowLong(handle, WindowLong.GWL_STYLE);
- exstyle = Win32GetWindowLong(handle, WindowLong.GWL_EXSTYLE);
-
-
- switch (border_style) {
- case FormBorderStyle.None: {
- style &= ~(uint)WindowStyles.WS_BORDER;
- exstyle &= ~(uint)WindowExStyles.WS_EX_CLIENTEDGE;
- break;
- }
-
- case FormBorderStyle.FixedSingle: {
- style |= (uint)WindowStyles.WS_BORDER;
- exstyle &= ~(uint)WindowExStyles.WS_EX_CLIENTEDGE;
- break;
- }
-
- case FormBorderStyle.Fixed3D: {
- style &= ~(uint)WindowStyles.WS_BORDER;
- exstyle |= (uint)WindowExStyles.WS_EX_CLIENTEDGE;
- break;
- }
- }
+ nid = new NOTIFYICONDATA();
- Win32SetWindowLong(handle, WindowLong.GWL_STYLE, style);
- Win32SetWindowLong(handle, WindowLong.GWL_EXSTYLE, exstyle);
+ nid.cbSize = (uint)Marshal.SizeOf(nid);
+ nid.hWnd = hwnd;
+ nid.uID = 1;
+ nid.uFlags = NotifyIconFlags.NIF_INFO;
+ nid.uTimeoutOrVersion = timeout;
+ nid.szInfoTitle = title;
+ nid.szInfo = text;
+ nid.dwInfoFlags = icon;
- Win32SetWindowPos(handle, IntPtr.Zero, 0, 0, 0, 0,
- SetWindowPosFlags.SWP_FRAMECHANGED | SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOACTIVATE | SetWindowPosFlags.SWP_NOOWNERZORDER | SetWindowPosFlags.SWP_NOZORDER);
+ Win32Shell_NotifyIcon(NotifyIconMessage.NIM_MODIFY, ref nid);
+ }
+
+ internal override void SetBorderStyle(IntPtr handle, FormBorderStyle border_style) {
+ // Nothing to do on Win32
}
internal override void SetMenu(IntPtr handle, Menu menu) {
Win32SetWindowPos(handle, IntPtr.Zero, 0, 0, 0, 0, SetWindowPosFlags.SWP_FRAMECHANGED | SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
}
-
internal override Point GetMenuOrigin(IntPtr handle) {
+ Form form = Control.FromHandle (handle) as Form;
+
+ if (form != null) {
+ if (form.FormBorderStyle == FormBorderStyle.None)
+ return Point.Empty;
+
+ int bordersize = (form.Width - form.ClientSize.Width) / 2;
+
+ if (form.FormBorderStyle == FormBorderStyle.FixedToolWindow || form.FormBorderStyle == FormBorderStyle.SizableToolWindow)
+ return new Point (bordersize, bordersize + SystemInformation.ToolWindowCaptionHeight);
+ else
+ return new Point (bordersize, bordersize + SystemInformation.CaptionHeight);
+ }
+
return new Point(SystemInformation.FrameBorderSize.Width, SystemInformation.FrameBorderSize.Height + ThemeEngine.Current.CaptionHeight);
}
internal override void SetIcon(IntPtr hwnd, Icon icon) {
- Win32SendMessage(hwnd, Msg.WM_SETICON, (IntPtr)1, icon.Handle); // 1 = large icon (0 would be small)
+ Win32SendMessage(hwnd, Msg.WM_SETICON, (IntPtr)1, icon == null ? IntPtr.Zero : icon.Handle); // 1 = large icon (0 would be small)
}
internal override void ClipboardClose(IntPtr handle) {
return (int)Win32RegisterClipboardFormat(format);
}
- internal override IntPtr ClipboardOpen() {
+ internal override IntPtr ClipboardOpen(bool primary_selection) {
+ // Win32 does not have primary selection
Win32OpenClipboard(FosterParent);
return clip_magic;
}
}
- internal override void ClipboardStore(IntPtr handle, object obj, int type, XplatUI.ObjectToClipboard converter) {
- byte[] data;
- IntPtr hmem;
- IntPtr hmem_ptr;
+ internal override void ClipboardStore(IntPtr handle, object obj, int type, XplatUI.ObjectToClipboard converter, bool copy)
+ {
+ byte[] data = null;
if (handle != clip_magic) {
throw new ArgumentException("handle is not a valid clipboard handle");
if (obj == null) {
// Just clear it
- Win32EmptyClipboard();
+ if (!Win32EmptyClipboard())
+ throw new ExternalException("Win32EmptyClipboard");
return;
}
}
if (type == DataFormats.GetFormat(DataFormats.Rtf).Id) {
- hmem = Marshal.StringToHGlobalAnsi((string)obj);
- Win32SetClipboardData((uint)type, hmem);
- return;
+ data = StringToAnsi ((string)obj);
} else switch((ClipboardFormats)type) {
case ClipboardFormats.CF_UNICODETEXT: {
- hmem = Marshal.StringToHGlobalUni((string)obj);
- Win32SetClipboardData((uint)type, hmem);
- return;
+ data = StringToUnicode ((string)obj);
+ break;
}
case ClipboardFormats.CF_TEXT: {
- hmem = Marshal.StringToHGlobalAnsi((string)obj);
- Win32SetClipboardData((uint)type, hmem);
- return;
+ data = StringToAnsi ((string)obj);
+ break;
}
case ClipboardFormats.CF_BITMAP:
case ClipboardFormats.CF_DIB: {
- data = ImageToDIB((Image)obj);
-
- hmem = Win32GlobalAlloc(GAllocFlags.GMEM_MOVEABLE | GAllocFlags.GMEM_DDESHARE, data.Length);
- hmem_ptr = Win32GlobalLock(hmem);
- Marshal.Copy(data, 0, hmem_ptr, data.Length);
- Win32GlobalUnlock(hmem);
- Win32SetClipboardData((uint)ClipboardFormats.CF_DIB, hmem);
- return;
+ data = ImageToDIB ((Image)obj);
+ type = (int)ClipboardFormats.CF_DIB;
+ break;
}
default: {
- if (converter != null && converter(ref type, obj, out data)) {
- hmem = Win32GlobalAlloc(GAllocFlags.GMEM_MOVEABLE | GAllocFlags.GMEM_DDESHARE, data.Length);
- hmem_ptr = Win32GlobalLock(hmem);
- Marshal.Copy(data, 0, hmem_ptr, data.Length);
- Win32GlobalUnlock(hmem);
- Win32SetClipboardData((uint)type, hmem);
+ if (converter != null && !converter(ref type, obj, out data)) {
+ data = null; // ensure that a failed conversion leaves null.
}
- return;
+ break;
}
}
+ if (data != null) {
+ SetClipboardData ((uint)type, data);
+ }
}
+ internal static byte[] StringToUnicode (string text)
+ {
+ return Encoding.Unicode.GetBytes (text + "\0");
+ }
+
+ internal static byte[] StringToAnsi (string text)
+ {
+ // FIXME, follow the behaviour of the previous code using UTF-8,
+ // but this should be 'ANSI' on Windows, i.e. the current code page.
+ // Does Encoding.Default work on Windows?
+ return Encoding.UTF8.GetBytes (text + "\0");
+ }
+
+ private void SetClipboardData (uint type, byte[] data)
+ {
+ if (data.Length == 0)
+ // Shouldn't call Win32SetClipboard with NULL, as, from MSDN:
+ // "This parameter can be NULL, indicating that the window provides data
+ // in the specified clipboard format (renders the format) upon request."
+ // and I don't think we support that...
+ // Note this is unrelated to the fact that passing a null obj to
+ // ClipboardStore is actually a request to empty the clipboard!
+ return;
+ IntPtr hmem = CopyToMoveableMemory (data);
+ if (hmem == IntPtr.Zero)
+ // As above, should not call with null.
+ // (Not that CopyToMoveableMemory should ever return null!)
+ throw new ExternalException ("CopyToMoveableMemory failed.");
+ if (Win32SetClipboardData (type, hmem) == IntPtr.Zero)
+ throw new ExternalException ("Win32SetClipboardData");
+ }
+
+ /// <summary>
+ /// Creates a memory block with GlobalAlloc(GMEM_MOVEABLE), copies the data
+ /// into it, and returns the handle to the memory.
+ /// </summary>
+ /// -
+ /// <param name="data">The data. Must not be null or zero-length —
+ /// see the exception notes.</param>
+ /// -
+ /// <returns>The *handle* to the allocated GMEM_MOVEABLE block.</returns>
+ /// -
+ /// <exception cref="T:System.ArgumentException">The data was null or zero
+ /// length. This is disallowed since a zero length allocation can't be made
+ /// </exception>
+ /// <exception cref="T:System.ComponentModel.Win32Exception">The allocation,
+ /// or locking (handle->pointer) failed.
+ /// Either out of memory or the handle table is full (256 max currently).
+ /// Note Win32Exception is a subclass of ExternalException so this is OK in
+ /// the documented Clipboard interface.
+ /// </exception>
+ internal static IntPtr CopyToMoveableMemory (byte[] data)
+ {
+ if (data == null || data.Length == 0)
+ // detect this before GlobalAlloc does.
+ throw new ArgumentException ("Can't create a zero length memory block.");
+
+ IntPtr hmem = Win32GlobalAlloc (GAllocFlags.GMEM_MOVEABLE | GAllocFlags.GMEM_DDESHARE, data.Length);
+ if (hmem == IntPtr.Zero)
+ throw new Win32Exception ();
+ IntPtr hmem_ptr = Win32GlobalLock (hmem);
+ if (hmem_ptr == IntPtr.Zero) // If the allocation was valid this shouldn't occur.
+ throw new Win32Exception ();
+ Marshal.Copy (data, 0, hmem_ptr, data.Length);
+ Win32GlobalUnlock (hmem);
+ return hmem;
+ }
+
+
internal override void SetAllowDrop(IntPtr hwnd, bool allowed) {
if (allowed) {
Win32DnD.RegisterDropTarget(hwnd);
return Win32DnD.StartDrag(hwnd, data, allowedEffects);
}
+ // XXX this doesn't work at all for FrameStyle.Dashed - it draws like Thick, and in the Thick case
+ // the corners are drawn incorrectly.
+ internal override void DrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style) {
+ IntPtr hdc;
+ IntPtr pen;
+ IntPtr oldpen;
+ COLORREF clrRef = new COLORREF();
+
+ // If we want the standard hatch pattern we would
+ // need to create a brush
+
+ clrRef.R = backColor.R;
+ clrRef.G = backColor.G;
+ clrRef.B = backColor.B;
+
+ // Grab a pen
+ pen = Win32CreatePen (style == FrameStyle.Thick ? PenStyle.PS_SOLID : PenStyle.PS_DASH,
+ style == FrameStyle.Thick ? 4 : 2, ref clrRef);
+
+ hdc = Win32GetDC(IntPtr.Zero);
+ Win32SetROP2(hdc, ROP2DrawMode.R2_NOT);
+ oldpen = Win32SelectObject(hdc, pen);
+
+ Win32MoveToEx(hdc, rectangle.Left, rectangle.Top, IntPtr.Zero);
+ if ((rectangle.Width > 0) && (rectangle.Height > 0)) {
+ Win32LineTo(hdc, rectangle.Right, rectangle.Top);
+ Win32LineTo(hdc, rectangle.Right, rectangle.Bottom);
+ Win32LineTo(hdc, rectangle.Left, rectangle.Bottom);
+ Win32LineTo(hdc, rectangle.Left, rectangle.Top);
+ } else {
+ if (rectangle.Width > 0) {
+ Win32LineTo(hdc, rectangle.Right, rectangle.Top);
+ } else {
+ Win32LineTo(hdc, rectangle.Left, rectangle.Bottom);
+ }
+ }
+
+ Win32SelectObject(hdc, oldpen);
+ Win32DeleteObject(pen);
+
+ Win32ReleaseDC(IntPtr.Zero, hdc);
+ }
+
+ internal override void DrawReversibleLine(Point start, Point end, Color backColor) {
+ IntPtr hdc;
+ IntPtr pen;
+ IntPtr oldpen;
+ POINT pt;
+ COLORREF clrRef = new COLORREF();
+
+ pt = new POINT();
+ pt.x = 0;
+ pt.y = 0;
+ Win32ClientToScreen(IntPtr.Zero, ref pt);
+
+ // If we want the standard hatch pattern we would
+ // need to create a brush
+
+ clrRef.R = backColor.R;
+ clrRef.G = backColor.G;
+ clrRef.B = backColor.B;
+
+ // Grab a pen
+ pen = Win32CreatePen(PenStyle.PS_SOLID, 1, ref clrRef);
+
+ hdc = Win32GetDC(IntPtr.Zero);
+ Win32SetROP2(hdc, ROP2DrawMode.R2_NOT);
+ oldpen = Win32SelectObject(hdc, pen);
+
+ Win32MoveToEx(hdc, pt.x + start.X, pt.y + start.Y, IntPtr.Zero);
+ Win32LineTo(hdc, pt.x + end.X, pt.y + end.Y);
+
+ Win32SelectObject(hdc, oldpen);
+ Win32DeleteObject(pen);
+
+ Win32ReleaseDC(IntPtr.Zero, hdc);
+ }
+
+ internal override void FillReversibleRectangle (Rectangle rectangle, Color backColor)
+ {
+ RECT rect;
+
+ rect = new RECT();
+ rect.left = rectangle.Left;
+ rect.top = rectangle.Top;
+ rect.right = rectangle.Right;
+ rect.bottom = rectangle.Bottom;
+
+ IntPtr hdc;
+ IntPtr brush;
+ IntPtr oldbrush;
+ COLORREF clrRef = new COLORREF();
+
+ clrRef.R = backColor.R;
+ clrRef.G = backColor.G;
+ clrRef.B = backColor.B;
+
+ // Grab a brush
+ brush = Win32CreateSolidBrush (clrRef);
+
+ hdc = Win32GetDC(IntPtr.Zero);
+ oldbrush = Win32SelectObject(hdc, brush);
+
+ Win32PatBlt (hdc, rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height, PatBltRop.DSTINVERT);
+
+ Win32SelectObject(hdc, oldbrush);
+ Win32DeleteObject(brush);
+
+ Win32ReleaseDC(IntPtr.Zero, hdc);
+ }
+
internal override void DrawReversibleRectangle(IntPtr handle, Rectangle rect, int line_width) {
IntPtr hdc;
IntPtr pen;
Win32SetROP2(hdc, ROP2DrawMode.R2_NOT);
oldpen = Win32SelectObject(hdc, pen);
- // We might need to add clipping to the WindowRect of 'handle' - right now we're drawing on the desktop
+ Control c = Control.FromHandle (handle);
+ if (c != null) {
+ RECT window_rect;
+ Win32GetWindowRect (c.Handle, out window_rect);
+ Region r = new Region (new Rectangle(window_rect.left, window_rect.top, window_rect.right - window_rect.left, window_rect.bottom - window_rect.top));
+ Win32ExtSelectClipRgn(hdc, r.GetHrgn (Graphics.FromHdc (hdc)), (int) ClipCombineMode.RGN_AND);
+ }
Win32MoveToEx(hdc, pt.x + rect.Left, pt.y + rect.Top, IntPtr.Zero);
if ((rect.Width > 0) && (rect.Height > 0)) {
Win32SelectObject(hdc, oldpen);
Win32DeleteObject(pen);
+ if (c != null)
+ Win32ExtSelectClipRgn(hdc, IntPtr.Zero, (int) ClipCombineMode.RGN_COPY);
+
Win32ReleaseDC(IntPtr.Zero, hdc);
}
return Win32PostMessage(hwnd, message, wParam, lParam);
}
+ internal override int SendInput (IntPtr hwnd, Queue keys) {
+ INPUT[] inputs = new INPUT[keys.Count];
+ const Int32 INPUT_KEYBOARD = 1;
+ uint returns = 0;
+ int i = 0;
+ while (keys.Count > 0) {
+ MSG msg = (MSG)keys.Dequeue();
+
+
+ inputs[i].ki.wScan = 0;
+ inputs[i].ki.time = 0;
+ inputs[i].ki.dwFlags = (Int32)(msg.message == Msg.WM_KEYUP ? InputFlags.KEYEVENTF_KEYUP : 0);
+ inputs[i].ki.wVk = (short)msg.wParam.ToInt32();
+ inputs[i].type = INPUT_KEYBOARD;
+ i++;
+ }
+ returns = Win32SendInput((UInt32)inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT)));
+
+ return (int) returns;
+ }
+
internal override int KeyboardSpeed {
get {
- Console.WriteLine ("KeyboardSpeed: need to query Windows");
-
+ int speed = 0;
+ Win32SystemParametersInfo(SPIAction.SPI_GETKEYBOARDSPEED, 0, ref speed, 0);
//
// Return values range from 0 to 31 which map to 2.5 to 30 repetitions per second.
//
- return 0;
+ return speed;
}
}
internal override int KeyboardDelay {
get {
- Console.WriteLine ("KeyboardDelay: need to query Windows");
-
+ int delay = 1;
+ Win32SystemParametersInfo(SPIAction.SPI_GETKEYBOARDDELAY, 0, ref delay, 0);
//
// Return values must range from 0 to 4, 0 meaning 250ms,
// and 4 meaning 1000 ms.
//
- return 1;
+ return delay;
}
}
-
- internal override event EventHandler Idle;
- // Santa's little helper
- static void Where() {
- Console.WriteLine("Here: {0}", new StackTrace().ToString());
+ private class WinBuffer
+ {
+ public IntPtr hdc;
+ public IntPtr bitmap;
+
+ public WinBuffer (IntPtr hdc, IntPtr bitmap)
+ {
+ this.hdc = hdc;
+ this.bitmap = bitmap;
+ }
+ }
+
+ internal override void CreateOffscreenDrawable (IntPtr handle, int width, int height, out object offscreen_drawable)
+ {
+ Graphics destG = Graphics.FromHwnd (handle);
+ IntPtr destHdc = destG.GetHdc ();
+
+ IntPtr srcHdc = Win32CreateCompatibleDC (destHdc);
+ IntPtr srcBmp = Win32CreateCompatibleBitmap (destHdc, width, height);
+ Win32SelectObject (srcHdc, srcBmp);
+
+ offscreen_drawable = new WinBuffer (srcHdc, srcBmp);
+
+ destG.ReleaseHdc (destHdc);
+ }
+
+ internal override Graphics GetOffscreenGraphics (object offscreen_drawable)
+ {
+ return Graphics.FromHdc (((WinBuffer)offscreen_drawable).hdc);
+ }
+
+ internal override void BlitFromOffscreen (IntPtr dest_handle, Graphics dest_dc, object offscreen_drawable, Graphics offscreen_dc, Rectangle r)
+ {
+ WinBuffer wb = (WinBuffer)offscreen_drawable;
+
+ IntPtr destHdc = dest_dc.GetHdc ();
+ Win32BitBlt (destHdc, r.Left, r.Top, r.Width, r.Height, wb.hdc, r.Left, r.Top, TernaryRasterOperations.SRCCOPY);
+ dest_dc.ReleaseHdc (destHdc);
+ }
+
+ internal override void DestroyOffscreenDrawable (object offscreen_drawable)
+ {
+ WinBuffer wb = (WinBuffer)offscreen_drawable;
+
+ Win32DeleteObject (wb.bitmap);
+ Win32DeleteDC (wb.hdc);
}
+
+ internal override void SetForegroundWindow (IntPtr handle)
+ {
+ Win32SetForegroundWindow(handle);
+ }
+
+ internal override event EventHandler Idle;
#endregion // Public Static Methods
#region Win32 Imports
private extern static uint Win32GetLastError();
[DllImport ("user32.dll", EntryPoint="CreateWindowExW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
- internal extern static IntPtr Win32CreateWindow(uint dwExStyle, string lpClassName, string lpWindowName, uint dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lParam);
+ internal extern static IntPtr Win32CreateWindow(WindowExStyles dwExStyle, string lpClassName, string lpWindowName, WindowStyles dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lParam);
[DllImport ("user32.dll", EntryPoint="DestroyWindow", CallingConvention=CallingConvention.StdCall)]
internal extern static bool Win32DestroyWindow(IntPtr hWnd);
[DllImport ("user32.dll", EntryPoint="DestroyCursor", CallingConvention=CallingConvention.StdCall)]
private extern static bool Win32DestroyCursor(IntPtr hCursor);
+ [DllImport ("user32.dll", EntryPoint = "DrawIcon", CallingConvention = CallingConvention.StdCall)]
+ private extern static bool Win32DrawIcon (IntPtr hDC, int X, int Y, IntPtr hIcon);
+
[DllImport ("user32.dll", EntryPoint="DefWindowProcW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
private extern static IntPtr Win32DefWindowProc(IntPtr hWnd, Msg Msg, IntPtr wParam, IntPtr lParam);
- [DllImport ("user32.dll", EntryPoint="DefDlgProcW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
- private extern static IntPtr Win32DefDlgProc(IntPtr hWnd, Msg Msg, IntPtr wParam, IntPtr lParam);
+ //[DllImport ("user32.dll", EntryPoint="DefDlgProcW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
+ //private extern static IntPtr Win32DefDlgProc(IntPtr hWnd, Msg Msg, IntPtr wParam, IntPtr lParam);
[DllImport ("user32.dll", EntryPoint="PostQuitMessage", CallingConvention=CallingConvention.StdCall)]
private extern static IntPtr Win32PostQuitMessage(int nExitCode);
[DllImport ("user32.dll", EntryPoint="BeginPaint", CallingConvention=CallingConvention.StdCall)]
private extern static IntPtr Win32BeginPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
+ [DllImport ("user32.dll", EntryPoint = "ValidateRect", CallingConvention = CallingConvention.StdCall)]
+ private extern static IntPtr Win32ValidateRect (IntPtr hWnd, ref RECT rect);
+
[DllImport ("user32.dll", EntryPoint="EndPaint", CallingConvention=CallingConvention.StdCall)]
private extern static bool Win32EndPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
[DllImport ("user32.dll", EntryPoint="GetWindowDC", CallingConvention=CallingConvention.StdCall)]
private extern static IntPtr Win32GetWindowDC(IntPtr hWnd);
- [DllImport ("user32.dll", EntryPoint="GetDCEx", CallingConvention=CallingConvention.StdCall)]
- private extern static IntPtr Win32GetDCEx(IntPtr hWnd, IntPtr hRgn, DCExFlags flags);
+ //[DllImport ("user32.dll", EntryPoint="GetDCEx", CallingConvention=CallingConvention.StdCall)]
+ //private extern static IntPtr Win32GetDCEx(IntPtr hWnd, IntPtr hRgn, DCExFlags flags);
[DllImport ("user32.dll", EntryPoint="ReleaseDC", CallingConvention=CallingConvention.StdCall)]
private extern static IntPtr Win32ReleaseDC(IntPtr hWnd, IntPtr hDC);
[DllImport ("user32.dll", EntryPoint="InvalidateRect", CallingConvention=CallingConvention.StdCall)]
private extern static IntPtr Win32InvalidateRect(IntPtr hWnd, ref RECT lpRect, bool bErase);
- [DllImport ("user32.dll", EntryPoint="InvalidateRect", CallingConvention=CallingConvention.StdCall)]
- private extern static IntPtr Win32InvalidateRect(IntPtr hWnd, IntPtr lpRect, bool bErase);
+ //[DllImport ("user32.dll", EntryPoint="InvalidateRect", CallingConvention=CallingConvention.StdCall)]
+ //private extern static IntPtr Win32InvalidateRect(IntPtr hWnd, IntPtr lpRect, bool bErase);
[DllImport ("user32.dll", EntryPoint="SetCapture", CallingConvention=CallingConvention.StdCall)]
private extern static IntPtr Win32SetCapture(IntPtr hWnd);
[DllImport ("user32.dll", EntryPoint="ClientToScreen", CallingConvention=CallingConvention.StdCall)]
private extern static bool Win32ClientToScreen(IntPtr hWnd, ref POINT pt);
+ // This function returns the parent OR THE OWNER!
+ // Use GetAncestor to only get the parent.
[DllImport ("user32.dll", EntryPoint="GetParent", CallingConvention=CallingConvention.StdCall)]
private extern static IntPtr Win32GetParent(IntPtr hWnd);
+ [DllImport ("user32.dll", EntryPoint = "GetAncestor", CallingConvention = CallingConvention.StdCall)]
+ private extern static IntPtr Win32GetAncestor (IntPtr hWnd, AncestorType flags);
+
[DllImport ("user32.dll", EntryPoint="SetActiveWindow", CallingConvention=CallingConvention.StdCall)]
private extern static IntPtr Win32SetActiveWindow(IntPtr hWnd);
[DllImport ("user32.dll", EntryPoint="SetCursorPos", CallingConvention=CallingConvention.StdCall)]
private extern static bool Win32SetCursorPos(int x, int y);
- [DllImport ("user32.dll", EntryPoint="GetWindowPlacement", CallingConvention=CallingConvention.StdCall)]
- private extern static bool Win32GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
+ //[DllImport ("user32.dll", EntryPoint="GetWindowPlacement", CallingConvention=CallingConvention.StdCall)]
+ //private extern static bool Win32GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
[DllImport ("user32.dll", EntryPoint="TrackMouseEvent", CallingConvention=CallingConvention.StdCall)]
private extern static bool Win32TrackMouseEvent(ref TRACKMOUSEEVENT tme);
- [DllImport ("gdi32.dll", EntryPoint="CreateBrushIndirect", CallingConvention=CallingConvention.StdCall)]
- private extern static IntPtr Win32CreateBrushIndirect(ref LOGBRUSH lb);
+ //[DllImport ("gdi32.dll", EntryPoint="CreateBrushIndirect", CallingConvention=CallingConvention.StdCall)]
+ //private extern static IntPtr Win32CreateBrushIndirect(ref LOGBRUSH lb);
+
+ [DllImport ("gdi32.dll", EntryPoint="CreateSolidBrush", CallingConvention=CallingConvention.StdCall)]
+ private extern static IntPtr Win32CreateSolidBrush(COLORREF clrRef);
- [DllImport ("user32.dll", EntryPoint="FillRect", CallingConvention=CallingConvention.StdCall)]
- private extern static int Win32FillRect(IntPtr hdc, ref RECT rect, IntPtr hbr);
+ [DllImport ("gdi32.dll", EntryPoint="PatBlt", CallingConvention=CallingConvention.StdCall)]
+ private extern static int Win32PatBlt(IntPtr hdc, int nXLeft, int nYLeft, int nWidth, int nHeight, PatBltRop dwRop);
[DllImport ("user32.dll", EntryPoint="SetWindowLong", CallingConvention=CallingConvention.StdCall)]
private extern static uint Win32SetWindowLong(IntPtr hwnd, WindowLong index, uint value);
[DllImport ("user32.dll", EntryPoint="SetLayeredWindowAttributes", CallingConvention=CallingConvention.StdCall)]
private extern static uint Win32SetLayeredWindowAttributes (IntPtr hwnd, COLORREF crKey, byte bAlpha, LayeredWindowAttributes dwFlags);
+ [DllImport ("user32.dll", EntryPoint="GetLayeredWindowAttributes", CallingConvention=CallingConvention.StdCall)]
+ private extern static uint Win32GetLayeredWindowAttributes (IntPtr hwnd, out COLORREF pcrKey, out byte pbAlpha, out LayeredWindowAttributes pwdFlags);
+
[DllImport ("gdi32.dll", EntryPoint="DeleteObject", CallingConvention=CallingConvention.StdCall)]
- private extern static bool Win32DeleteObject(IntPtr o);
+ public extern static bool Win32DeleteObject(IntPtr o);
[DllImport ("user32.dll", EntryPoint="GetKeyState", CallingConvention=CallingConvention.StdCall)]
private extern static short Win32GetKeyState(VirtualKeys nVirtKey);
[DllImport ("user32.dll", EntryPoint="SetCaretPos", CallingConvention=CallingConvention.StdCall)]
private extern static bool Win32SetCaretPos(int X, int Y);
- [DllImport ("user32.dll", EntryPoint="GetCaretBlinkTime", CallingConvention=CallingConvention.StdCall)]
- private extern static uint Win32GetCaretBlinkTime();
+ //[DllImport ("user32.dll", EntryPoint="GetCaretBlinkTime", CallingConvention=CallingConvention.StdCall)]
+ //private extern static uint Win32GetCaretBlinkTime();
[DllImport ("gdi32.dll", EntryPoint="GetTextMetricsW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
internal extern static bool Win32GetTextMetrics(IntPtr hdc, ref TEXTMETRIC tm);
[DllImport ("gdi32.dll", EntryPoint="SelectObject", CallingConvention=CallingConvention.StdCall)]
internal extern static IntPtr Win32SelectObject(IntPtr hdc, IntPtr hgdiobject);
- [DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
- private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, ref RECT prcScroll, ref RECT prcClip, IntPtr hrgnUpdate, out RECT prcUpdate, ScrollWindowExFlags flags);
+ //[DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
+ //private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, ref RECT prcScroll, ref RECT prcClip, IntPtr hrgnUpdate, out RECT prcUpdate, ScrollWindowExFlags flags);
- [DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
- private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, IntPtr prcScroll, ref RECT prcClip, IntPtr hrgnUpdate, out RECT prcUpdate, ScrollWindowExFlags flags);
+ //[DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
+ //private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, IntPtr prcScroll, ref RECT prcClip, IntPtr hrgnUpdate, out RECT prcUpdate, ScrollWindowExFlags flags);
- [DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
- private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, ref RECT prcScroll, IntPtr prcClip, IntPtr hrgnUpdate, out RECT prcUpdate, ScrollWindowExFlags flags);
+ //[DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
+ //private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, ref RECT prcScroll, IntPtr prcClip, IntPtr hrgnUpdate, out RECT prcUpdate, ScrollWindowExFlags flags);
[DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, IntPtr prcScroll, ref RECT prcClip, IntPtr hrgnUpdate, IntPtr prcUpdate, ScrollWindowExFlags flags);
- [DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
- private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, ref RECT prcScroll, IntPtr prcClip, IntPtr hrgnUpdate, IntPtr prcUpdate, ScrollWindowExFlags flags);
+ //[DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
+ //private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, ref RECT prcScroll, IntPtr prcClip, IntPtr hrgnUpdate, IntPtr prcUpdate, ScrollWindowExFlags flags);
- [DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
- private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, ref RECT prcScroll, ref RECT prcClip, IntPtr hrgnUpdate, IntPtr prcUpdate, ScrollWindowExFlags flags);
+ //[DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
+ //private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, ref RECT prcScroll, ref RECT prcClip, IntPtr hrgnUpdate, IntPtr prcUpdate, ScrollWindowExFlags flags);
[DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, IntPtr prcScroll, IntPtr prcClip, IntPtr hrgnUpdate, IntPtr prcUpdate, ScrollWindowExFlags flags);
[DllImport ("user32.dll", EntryPoint="IsWindowVisible", CallingConvention=CallingConvention.StdCall)]
private extern static bool IsWindowVisible(IntPtr hwnd);
- [DllImport ("user32.dll", EntryPoint="SetClassLong", CallingConvention=CallingConvention.StdCall)]
- private extern static bool Win32SetClassLong(IntPtr hwnd, ClassLong nIndex, IntPtr dwNewLong);
+ //[DllImport ("user32.dll", EntryPoint="SetClassLong", CallingConvention=CallingConvention.StdCall)]
+ //private extern static bool Win32SetClassLong(IntPtr hwnd, ClassLong nIndex, IntPtr dwNewLong);
[DllImport ("user32.dll", EntryPoint="SendMessageW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
private extern static IntPtr Win32SendMessage(IntPtr hwnd, Msg msg, IntPtr wParam, IntPtr lParam);
[DllImport ("user32.dll", EntryPoint="PostMessageW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
private extern static bool Win32PostMessage(IntPtr hwnd, Msg msg, IntPtr wParam, IntPtr lParam);
+ [DllImport ("user32.dll", EntryPoint="SendInput", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
+ private extern static UInt32 Win32SendInput(UInt32 nInputs, [MarshalAs(UnmanagedType.LPArray)] INPUT[] inputs, Int32 cbSize);
+
[DllImport ("user32.dll", EntryPoint="SystemParametersInfoW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
private extern static bool Win32SystemParametersInfo(SPIAction uiAction, uint uiParam, ref RECT rect, uint fWinIni);
+
+ //[DllImport ("user32.dll", EntryPoint="SystemParametersInfoW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
+ //private extern static bool Win32SystemParametersInfo(SPIAction uiAction, uint uiParam, ref uint value, uint fWinIni);
- [DllImport ("user32.dll", EntryPoint="SystemParametersInfoW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
- private extern static bool Win32SystemParametersInfo(SPIAction uiAction, uint uiParam, ref uint value, uint fWinIni);
+ [DllImport ("user32.dll", EntryPoint = "SystemParametersInfoW", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
+ private extern static bool Win32SystemParametersInfo (SPIAction uiAction, uint uiParam, ref int value, uint fWinIni);
- [DllImport ("user32.dll", EntryPoint="SystemParametersInfoW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
- private extern static bool Win32SystemParametersInfo(SPIAction uiAction, uint uiParam, ref int value, uint fWinIni);
+ [DllImport ("user32.dll", EntryPoint = "SystemParametersInfoW", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
+ private extern static bool Win32SystemParametersInfo (SPIAction uiAction, uint uiParam, ref bool value, uint fWinIni);
+
+ [DllImport ("user32.dll", EntryPoint = "SystemParametersInfoW", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
+ private extern static bool Win32SystemParametersInfo (SPIAction uiAction, uint uiParam, ref ANIMATIONINFO value, uint fWinIni);
[DllImport ("user32.dll", EntryPoint="OpenClipboard", CallingConvention=CallingConvention.StdCall)]
private extern static bool Win32OpenClipboard(IntPtr hwnd);
[DllImport ("gdi32.dll", EntryPoint="CreateHatchBrush", CallingConvention=CallingConvention.StdCall)]
internal extern static IntPtr Win32CreateHatchBrush(HatchStyle fnStyle, ref COLORREF color);
+ [DllImport("gdi32.dll", EntryPoint = "ExcludeClipRect", CallingConvention = CallingConvention.StdCall)]
+ internal extern static int Win32ExcludeClipRect (IntPtr hdc, int left, int top, int right, int bottom);
+
+ [DllImport ("gdi32.dll", EntryPoint="ExtSelectClipRgn", CallingConvention=CallingConvention.StdCall)]
+ internal extern static int Win32ExtSelectClipRgn(IntPtr hdc, IntPtr hrgn, int mode);
+
[DllImport ("winmm.dll", EntryPoint="PlaySoundW", CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Unicode)]
internal extern static IntPtr Win32PlaySound(string pszSound, IntPtr hmod, SndFlags fdwSound);
+ [DllImport ("user32.dll", EntryPoint="GetDoubleClickTime", CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Unicode)]
+ private extern static int Win32GetDoubleClickTime ();
+
[DllImport ("user32.dll", EntryPoint="SetWindowRgn", CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Unicode)]
internal extern static int Win32SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool redraw);
[DllImport ("user32.dll", EntryPoint="GetWindowRgn", CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Unicode)]
internal extern static IntPtr Win32GetWindowRgn(IntPtr hWnd, IntPtr hRgn);
+
+ [DllImport ("user32.dll", EntryPoint="ClipCursor", CallingConvention=CallingConvention.StdCall)]
+ internal extern static bool Win32ClipCursor (ref RECT lpRect);
+
+ [DllImport ("user32.dll", EntryPoint="GetClipCursor", CallingConvention=CallingConvention.StdCall)]
+ internal extern static bool Win32GetClipCursor (out RECT lpRect);
+
+ [DllImport ("gdi32.dll", EntryPoint="BitBlt", CallingConvention=CallingConvention.StdCall)]
+ internal static extern bool Win32BitBlt (IntPtr hObject, int nXDest, int nYDest, int nWidth,
+ int nHeight, IntPtr hObjSource, int nXSrc, int nYSrc, TernaryRasterOperations dwRop);
+
+ [DllImport ("gdi32.dll", EntryPoint="CreateCompatibleDC", CallingConvention=CallingConvention.StdCall, ExactSpelling = true, SetLastError = true)]
+ internal static extern IntPtr Win32CreateCompatibleDC (IntPtr hdc);
+
+ [DllImport ("gdi32.dll", EntryPoint="DeleteDC", CallingConvention=CallingConvention.StdCall, ExactSpelling = true, SetLastError = true)]
+ internal static extern bool Win32DeleteDC (IntPtr hdc);
+
+ [DllImport ("gdi32.dll", EntryPoint="CreateCompatibleBitmap", CallingConvention=CallingConvention.StdCall)]
+ internal static extern IntPtr Win32CreateCompatibleBitmap (IntPtr hdc, int nWidth, int nHeight);
+
+ [DllImport ("kernel32.dll", EntryPoint = "GetSystemPowerStatus", CallingConvention = CallingConvention.StdCall)]
+ internal static extern Boolean Win32GetSystemPowerStatus (SYSTEMPOWERSTATUS sps);
+
+ [DllImport ("user32.dll", EntryPoint = "GetIconInfo", CallingConvention = CallingConvention.StdCall)]
+ internal static extern bool Win32GetIconInfo (IntPtr hIcon, out ICONINFO piconinfo);
+
+ [DllImport ("user32.dll", EntryPoint="SetForegroundWindow", CallingConvention=CallingConvention.StdCall)]
+ extern static bool Win32SetForegroundWindow(IntPtr hWnd);
#endregion
}
}