首页 > 开发 > 综合 > 正文

C#中获得系统当前鼠标的图案

2024-07-21 02:25:52
字体:
来源:转载
供稿:网友
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);
}
 
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表