我一直在尝试做这件事,但是一直没有成功,以下是我得到的结果:
[DllImport("user32.dll")]
static extern bool SetSystemCursor(IntPtr hcur, uint id);
[DllImport("user32.dll", EntryPoint = "GetCursorInfo")]
public static extern bool GetCursorInfo(out CURSORINFO pci);
[DllImport("user32.dll", EntryPoint = "CopyIcon")]
public static extern IntPtr CopyIcon(IntPtr hIcon);
[StructLayout(LayoutKind.Sequential)]
public struct CURSORINFO
{
public Int32 cbSize; // Specifies the size, in bytes, of the structure.
public Int32 flags; // Specifies the cursor state. This parameter can be one of the following values:
public IntPtr hCursor; // Handle to the cursor.
public POINT ptScreenPos; // A POINT structure that receives the screen coordinates of the cursor.
}
public void etc()
{
IntPtr hwndic = new IntPtr();
CURSORINFO curin = new CURSORINFO();
curin.cbSize = Marshal.SizeOf(curin);
if (GetCursorInfo(out curin))
{
if (curin.flags == CURSOR_SHOWING)
{
hwndic = CopyIcon(curin.hCursor);
SetSystemCursor(hwndic, OCR_NORMAL);
}
}
}
问题在于复制的图标有时与默认的鼠标图标不同。例如,如果它在等待位置捕获到了鼠标,则可能会给我鼠标等待图标。
我希望能够获取正在运行系统的默认光标图标(空闲时的图标),我该怎么做?
提前感谢。