C#获取系统当前鼠标的图案代码如下:
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]struct CURSORINFO
{public int cbSize;public int flags;public IntPtr hCursor;
public Point ptScreenPos;
}[DllImport("user32.dll")]
static extern bool GetCursorInfo(out CURSORINFO pci);private const int CURSOR_SHOWING= 0x00000001;private void button1_Click(object sender, EventArgs e){CURSORINFO vCurosrInfo;vCurosrInfo.cbSize = Marshal.SizeOf(typeof(CURSORINFO));
GetCursorInfo(out vCurosrInfo);
if ((vCurosrInfo.flags & CURSOR_SHOWING) != CURSOR_SHOWING) return;Cursor vCursor = new Cursor(vCurosrInfo.hCursor);
Graphics vGraphics = Graphics.FromHwnd(Handle);Rectangle vRectangle = new Rectangle(0, 0, 32, 32);
vGraphics.FillRectangle(new SolidBrush(BackColor), vRectangle);
vCursor.Draw(vGraphics, vRectangle);}
[出处:http://www.csharpwin.com/csharpspace/9106r1765.shtml]
=============================================================================
自己是在扩展WebBrowser时使用的,使用WebBrowser+MSHTML写编辑器时,需要让浮动对象可以移动,而在移动时,如果是在做resize就不要移动,两个事件有些冲突,所以通过判断鼠标的状态来知道当前的用户操作是什么。
/*
* hCursor values:
*
* Default: 65553
* Input: 65555
* Move: 65571
* SizeWE: 65567
* SizeNS: 65569
* SizeNWSE: 65565
* SizeNESW: 65563
**/