/// <summary> /// Replaces the specified system cursor with the given cursor. The cursor will /// be destroyed and as such must not be loaded from a resource. Use CopyCursor /// on cursors loaded from resources before calling this method. /// </summary> public static void SetSystemCursor(CursorHandle cursor, SystemCursor id) { if (!Imports.SetSystemCursor(cursor, id)) { throw Error.GetExceptionForLastError(); } }
public static CursorHandle CopyCursor(CursorHandle cursor) { CursorHandle copy = Imports.CopyCursor(cursor); if (copy.IsInvalid) { Error.ThrowLastError(); } return(copy); }
public static CursorHandle CopyCursor(CursorHandle cursor) { CursorHandle copy = Imports.CopyCursor(cursor); if (copy.IsInvalid) { throw Error.GetExceptionForLastError(); } return(copy); }
/// <summary> /// Replaces the specified system cursor with the given cursor. The cursor will /// be destroyed and as such must not be loaded from a resource. Use CopyCursor /// on cursors loaded from resources before calling this method. /// </summary> public static void SetSystemCursor(CursorHandle cursor, SystemCursor id) => Error.ThrowLastErrorIfFalse(Imports.SetSystemCursor(cursor, id));
public static CursorHandle SetCursor(CursorHandle cursor) { return(new CursorHandle(Imports.SetCursor(cursor), ownsHandle: false)); }
public unsafe WindowClass( string className = default, ModuleInstance moduleInstance = default, ClassStyle classStyle = ClassStyle.HorizontalRedraw | ClassStyle.VerticalRedraw, BrushHandle backgroundBrush = default, IconHandle icon = default, IconHandle smallIcon = default, CursorHandle cursor = default, string menuName = null, int menuId = 0, int classExtraBytes = 0, int windowExtraBytes = 0) { // Handle default values className = className ?? Guid.NewGuid().ToString(); if (backgroundBrush == default) { backgroundBrush = SystemColor.Window; } else if (backgroundBrush == BrushHandle.NoBrush) { backgroundBrush = default; } if (icon == default) { icon = IconId.Application; } else if (icon == IconHandle.NoIcon) { icon = default; } if (cursor == default) { cursor = CursorId.Arrow; } else if (cursor == CursorHandle.NoCursor) { cursor = default; } // Unfortunately GetHINSTANCE isn't part of .NET Standard if (moduleInstance == default) { var method = typeof(Marshal).GetMethod("GetHINSTANCE"); Module module = Assembly.GetCallingAssembly().Modules.First(); moduleInstance = (IntPtr)method.Invoke(null, new object[] { module }); } if (menuId != 0 && menuName != null) { throw new ArgumentException("Can only set menu name or ID."); } _windowProcedure = WindowProcedure; ModuleInstance = moduleInstance; _className = className; _menuName = menuName ?? string.Empty; _wndClass = new WNDCLASSEX { cbSize = (uint)sizeof(WNDCLASSEX), style = classStyle, lpfnWndProc = Marshal.GetFunctionPointerForDelegate(_windowProcedure), cbClassExtra = classExtraBytes, cbWndExtra = windowExtraBytes, hInstance = (IntPtr)moduleInstance, hIcon = icon, hCursor = cursor, hbrBackground = backgroundBrush, hIconSm = smallIcon, lpszMenuName = (char *)menuId }; }
public static CursorHandle SetCursor(CursorHandle cursor) => ResourceMethods.SetCursor(cursor);
public unsafe WindowClass( string?className = default, ModuleInstance?moduleInstance = default, ClassStyle classStyle = ClassStyle.HorizontalRedraw | ClassStyle.VerticalRedraw, BrushHandle backgroundBrush = default, IconHandle icon = default, IconHandle smallIcon = default, CursorHandle cursor = default, string?menuName = null, int menuId = 0, int classExtraBytes = 0, int windowExtraBytes = 0) { // Handle default values className ??= Guid.NewGuid().ToString(); if (backgroundBrush == default) { backgroundBrush = SystemColor.Window; } else if (backgroundBrush == BrushHandle.NoBrush) { backgroundBrush = default; } if (icon == default) { icon = IconId.Application; } else if (icon == IconHandle.NoIcon) { icon = default; } if (cursor == default) { cursor = CursorId.Arrow; } else if (cursor == CursorHandle.NoCursor) { cursor = default; } moduleInstance ??= new ModuleInstance(Marshal.GetHINSTANCE(Assembly.GetCallingAssembly().Modules.First())); if (menuId != 0 && menuName != null) { throw new ArgumentException($"Can't set both {nameof(menuName)} and {nameof(menuId)}."); } _windowProcedure = WindowProcedure; ModuleInstance = moduleInstance; _className = className; _menuName = menuName ?? string.Empty; _wndClass = new WNDCLASSEX { cbSize = (uint)sizeof(WNDCLASSEX), style = classStyle, lpfnWndProc = Marshal.GetFunctionPointerForDelegate(_windowProcedure), cbClassExtra = classExtraBytes, cbWndExtra = windowExtraBytes, hInstance = (IntPtr)moduleInstance, hIcon = icon, hCursor = cursor, hbrBackground = backgroundBrush, hIconSm = smallIcon, lpszMenuName = (char *)menuId }; }