public static Bitmap CaptureCursor(ref int x, ref int y) { Bitmap bmp; IntPtr hicon; Win32Stuff.CURSORINFO ci = new Win32Stuff.CURSORINFO(); Win32Stuff.ICONINFO icInfo; ci.cbSize = Marshal.SizeOf(ci); if (Win32Stuff.GetCursorInfo(out ci)) { if (ci.flags == Win32Stuff.CURSOR_SHOWING) { hicon = Win32Stuff.CopyIcon(ci.hCursor); if (Win32Stuff.GetIconInfo(hicon, out icInfo)) { x = ci.ptScreenPos.x - ((int)icInfo.xHotspot); y = ci.ptScreenPos.y - ((int)icInfo.yHotspot); Icon ic = Icon.FromHandle(hicon); bmp = ic.ToBitmap(); return bmp; } } } return null; }
static Bitmap CaptureCursor(ref int x, ref int y) { Bitmap bmp; IntPtr hicon; Win32Stuff.CURSORINFO ci = new Win32Stuff.CURSORINFO(); Win32Stuff.ICONINFO icInfo; ci.cbSize = Marshal.SizeOf(ci); if (Win32Stuff.GetCursorInfo(out ci)) { if (ci.flags == Win32Stuff.CURSOR_SHOWING) { hicon = Win32Stuff.CopyIcon(ci.hCursor); if (Win32Stuff.GetIconInfo(hicon, out icInfo)) { x = ci.ptScreenPos.x - ((int)icInfo.xHotspot); y = ci.ptScreenPos.y - ((int)icInfo.yHotspot); Icon ic = Icon.FromHandle(hicon); bmp = ic.ToBitmap(); return(bmp); } } } return(null); }
public static Icon CaptureCursorIcon(out int x, out int y) { IntPtr hicon; Win32Stuff.CURSORINFO ci = new Win32Stuff.CURSORINFO(); Win32Stuff.ICONINFO icInfo; ci.cbSize = Marshal.SizeOf(ci); if (Win32Stuff.GetCursorInfo(out ci)) { hicon = Win32Stuff.CopyIcon(ci.hCursor); if (Win32Stuff.GetIconInfo(hicon, out icInfo)) { x = ci.ptScreenPos.x - icInfo.xHotspot; y = ci.ptScreenPos.y - icInfo.yHotspot; return(Icon.FromHandle(hicon)); } else { x = ci.ptScreenPos.x; y = ci.ptScreenPos.y; } } else { x = 0; y = 0; } return(null); }
internal Bitmap CaptureCursor(ref int cursorX, ref int cursorY) { //cursorX = Cursor.Position.X; //cursorY = Cursor.Position.Y; //var icon = Icon.FromHandle(Cursor.Current.Handle); //var cursorBmp = icon.ToBitmap(); //return cursorBmp; Bitmap bmp; IntPtr hicon; Win32Stuff.CURSORINFO ci = new Win32Stuff.CURSORINFO(); Win32Stuff.ICONINFO icInfo; ci.cbSize = Marshal.SizeOf(ci); if (Win32Stuff.GetCursorInfo(out ci)) { if (ci.flags == Win32Stuff.CURSOR_SHOWING) { hicon = Win32Stuff.CopyIcon(ci.hCursor); if (Win32Stuff.GetIconInfo(hicon, out icInfo)) { cursorX = ci.ptScreenPos.x - ((int)icInfo.xHotspot); cursorY = ci.ptScreenPos.y - ((int)icInfo.yHotspot); Icon ic = Icon.FromHandle(hicon); bmp = ic.ToBitmap(); return bmp; } } } return null; }
public static Bitmap CaptureCursor(ref int x, ref int y) { Bitmap bmp = null; // lock (_lock) { Win32Stuff.CURSORINFO ci = new Win32Stuff.CURSORINFO(); Win32Stuff.ICONINFO icInfo; ci.cbSize = Marshal.SizeOf(ci); if (Win32Stuff.GetCursorInfo(out ci)) { if (ci.flags == Win32Stuff.CURSOR_SHOWING) { IntPtr hicon = Win32Stuff.CopyIcon(ci.hCursor); if (Win32Stuff.GetIconInfo(hicon, out icInfo)) { if (icInfo.hbmMask != IntPtr.Zero) { GDIStuff.DeleteObject(icInfo.hbmMask); } if (icInfo.hbmColor != IntPtr.Zero) { GDIStuff.DeleteObject(icInfo.hbmColor); } x = ci.ptScreenPos.x - icInfo.xHotspot; y = ci.ptScreenPos.y - icInfo.yHotspot; Icon ic = Icon.FromHandle(hicon); if (ic.Width > 0 && ic.Height > 0) { bmp = ic.ToBitmap(); } Win32Stuff.DestroyIcon(hicon); } } } } return bmp; }
Bitmap CaptureCursor(ref int x, ref int y) { Process A = Process.GetCurrentProcess(); A.MaxWorkingSet = Process.GetCurrentProcess().MaxWorkingSet; A.Dispose(); Bitmap bmp; IntPtr hicon; Win32Stuff.CURSORINFO ci = new Win32Stuff.CURSORINFO(); Win32Stuff.ICONINFO icInfo; ci.cbSize = Marshal.SizeOf(ci); if (Win32Stuff.GetCursorInfo(out ci)) { if (ci.flags == Win32Stuff.CURSOR_SHOWING) { hicon = Win32Stuff.CopyIcon(ci.hCursor); if (Win32Stuff.GetIconInfo(hicon, out icInfo)) { x = ci.ptScreenPos.x - ((int)icInfo.xHotspot); y = ci.ptScreenPos.y - ((int)icInfo.yHotspot); Icon ic = Icon.FromHandle(hicon); try { bmp = ic.ToBitmap(); } catch { bmp = new Bitmap(global::tcpip_server.Properties.Resources.reeor); } return(bmp); } } } bmp = new Bitmap(global::tcpip_server.Properties.Resources.lv);//这句代码运行长时间 就会执行,why??? return(bmp); }
Bitmap CaptureCursor(ref int x, ref int y) { Process A = Process.GetCurrentProcess(); A.MaxWorkingSet = Process.GetCurrentProcess().MaxWorkingSet; A.Dispose(); Bitmap bmp; IntPtr hicon; Win32Stuff.CURSORINFO ci = new Win32Stuff.CURSORINFO(); Win32Stuff.ICONINFO icInfo; ci.cbSize = Marshal.SizeOf(ci); if (Win32Stuff.GetCursorInfo(out ci)) { if (ci.flags == Win32Stuff.CURSOR_SHOWING) { hicon = Win32Stuff.CopyIcon(ci.hCursor); if (Win32Stuff.GetIconInfo(hicon, out icInfo)) { x = ci.ptScreenPos.x - ((int)icInfo.xHotspot); y = ci.ptScreenPos.y - ((int)icInfo.yHotspot); Icon ic = Icon.FromHandle(hicon); try { bmp = ic.ToBitmap(); } catch { bmp = new Bitmap(global::tcpip_server.Properties.Resources.reeor); } return bmp; } } } bmp = new Bitmap(global::tcpip_server.Properties.Resources.lv);//这句代码运行长时间 就会执行,why??? return bmp; }