public void ShowSymbol(CursorNames c) { switch(c) { case CursorNames.None: cursor_index = 0; break; case CursorNames.Identify: cursor_index = 1; break; case CursorNames.Use: cursor_index = 2; break; case CursorNames.Talk: cursor_index = 3; break; } }
/// <summary> /// Enables an application to customize the system cursors. It replaces the contents of the system cursor /// specified by the id parameter with the contents of the cursor specified by the curHwnd parameter and then /// destroys curHwnd. /// </summary> /// <param name="curHwnd"> /// A handle to the cursor. The function replaces the contents of the system cursor /// specified by id with the contents of the cursor handled by curHwnd. /// </param> /// <param name="id">The system cursor to replace with the contents of curHwnd.</param> /// <param name="destroyCur">Specify whether the cursor handle is destroyed.</param> /// <returns>True if succeed; false otherwise.</returns> public static bool TrySetSystemCursor(IntPtr curHwnd, CursorNames id, bool destroyCur) { if ((destroyCur && !SetSystemCursor(curHwnd, id) || (!destroyCur && !SetSystemCursor(CopyCursor(curHwnd), id)))) { return false; } return true; }
/// <summary> /// Enables an application to customize the system cursors. It replaces the contents of the system cursor specified by /// the id parameter with the contents of the cursor specified by the curHwnd parameter and then destroys curHwnd. /// </summary> /// <param name="curHwnd"> /// A handle to the cursor. The function replaces the contents of the system cursor specified by id /// with the contents of the cursor handled by curHwnd. /// </param> /// <param name="id">The system cursor to replace with the contents of curHwnd.</param> /// <param name="preCur"> /// If the function succeeds, the return value is the handle to the previous cursor, if there was one. /// <para>If there was no previous cursor, the return value is NULL.</para> /// </param> /// <param name="destroyCur">Specify whether the cursor handle is destroyed.</param> /// <returns>True if succeed; false otherwise.</returns> public static bool TrySetSystemCursor(IntPtr curHwnd, CursorNames id, out IntPtr preCur, bool destroyCur) { preCur = CopyCursor(GetSystemCursor(id)); var currentCursor = SetCursor(curHwnd); if ((destroyCur && !SetSystemCursor(curHwnd, id) || (!destroyCur && !SetSystemCursor(CopyCursor(curHwnd), id)))) { DestroyCursor(preCur); return false; } return true; }
/// <summary> /// Enables an application to customize the system cursors. It replaces the contents of the system cursor /// specified by the id parameter with the contents of the cursor specified by the curHwnd parameter and then /// destroys curHwnd. /// </summary> /// <param name="curHwnd"> /// A handle to the cursor. The function replaces the contents of the system cursor /// specified by id with the contents of the cursor handled by curHwnd. /// </param> /// <param name="id">The system cursor to replace with the contents of curHwnd.</param> /// <param name="preCur"> /// If the function succeeds, the return value is the handle to the previous cursor, if there /// was one. /// <para>If there was no previous cursor, the return value is NULL.</para> /// </param> /// <param name="destroyCur">Specify whether the cursor handle is destroyed.</param> public static void SetSystemCursor(IntPtr curHwnd, CursorNames id, out IntPtr preCur, bool destroyCur) { /*preCur = CopyCursor(GetSystemCursor(id)); IntPtr currentCursor = SetCursor(curHwnd); if ((destroyCur && !SetSystemCursor(curHwnd, id) || (!destroyCur && !SetSystemCursor(CopyCursor(curHwnd), id)))) { DestroyCursor(preCur); throw new Win32Exception(Marshal.GetLastWin32Error()); }*/ if (!TrySetSystemCursor(curHwnd, id, out preCur, destroyCur)) { throw new Win32Exception(Marshal.GetLastWin32Error()); } }
/// <summary> /// Enables an application to customize the system cursors. It replaces the contents of the system cursor /// specified by the id parameter with the contents of the cursor specified by the curHwnd parameter and then /// destroys curHwnd. /// </summary> /// <param name="curHwnd"> /// A handle to the cursor. The function replaces the contents of the system cursor /// specified by id with the contents of the cursor handled by curHwnd. /// </param> /// <param name="id">The system cursor to replace with the contents of curHwnd.</param> /// <param name="destroyCur">Specify whether the cursor handle is destroyed.</param> public static void SetSystemCursor(IntPtr curHwnd, CursorNames id, bool destroyCur) { /*if ((destroyCur && !SetSystemCursor(curHwnd, id) || (!destroyCur && !SetSystemCursor(CopyCursor(curHwnd),id)))) throw new Win32Exception(Marshal.GetLastWin32Error());*/ }
/// <summary> /// Load one of the predefined cursors /// </summary> /// <param name="name">Name of the predefined cursors</param> public static IntPtr GetSystemCursor(CursorNames name) { return LoadCursor(IntPtr.Zero, name); }
public static extern bool SetSystemCursor(IntPtr hcur, CursorNames id);
public static extern IntPtr LoadCursor(IntPtr hInstance, CursorNames lpCursorName);