animatedwaitcursor.cs

来自「windows mobile中的动画指针」· CS 代码 · 共 63 行

CS
63
字号
using System;
using System.Runtime.InteropServices;

namespace AnimatedCursorTest
{
  public sealed class AnimatedWaitCursor : IDisposable
  {
    private IntPtr hLib;
    private IntPtr hOldCursor;
    private IntPtr hNewCursor;

    public AnimatedWaitCursor(string dll, UInt32 ResourceId, int cFrames, int FrameTimeInterval)
    {
      // Load the dll that contains the animated cursor bitmaps
      hLib = LoadLibrary(dll);
      if (hLib == IntPtr.Zero)
        throw new ArgumentException("Could not load specified dll", "dll");

      // Load the animated cursor
      hNewCursor = LoadAnimatedCursor(hLib, ResourceId, cFrames, FrameTimeInterval);
      if (hNewCursor == IntPtr.Zero)
        throw new ArgumentException("Could not load specified cursor");

      // Make the animated cursor the active cursor
      // and keep track of the previously active cursor.
      hOldCursor = SetCursor(hNewCursor);
    }

    public void Dispose()
    {
      // Replace the cursor with the
      // previous cursor.
      if (hNewCursor != IntPtr.Zero)
      {
        SetCursor(hOldCursor);
      }

      // Unload the DLL that contains th
      // animated cursor bitmaps.
      if (hLib != IntPtr.Zero)
      {
        FreeLibrary(hLib);
      }
    }

    #region Platform Invokes

    [DllImport("coredll.dll")]
    private static extern IntPtr LoadLibrary(string lpLibFileName);

    [DllImport("coredll.dll")]
    private static extern int FreeLibrary(IntPtr hLibModule);

    [DllImport("coredll.dll")]
    private static extern IntPtr LoadAnimatedCursor(IntPtr hInstance, UInt32 ResourceId, int cFrames, int FrameTimeInterval);

    [DllImport("coredll.dll")]
    private static extern IntPtr SetCursor(IntPtr hCursor);

    #endregion
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?