Beispiel #1
0
        public static void UpdateCursorInfo()
        {
            // TODO - make sure everything here is cleaned up properly?
            // I'm pretty sure it is but it is good to check
            //int x = 0, y = 0;
            //return CaptureCursor (ref x, ref y);

            Win32Types.CursorInfo ci = new Win32Types.CursorInfo();
            ci.cbSize = Marshal.SizeOf(typeof(Win32Types.CursorInfo));

            if (!Win32Funcs.GetCursorInfo(ref ci))
            {
                return;
            }

            // Todo: this will change if cursor icon changes (via http://stackoverflow.com/questions/358527/how-to-tell-if-mouse-pointer-icon-changed?rq=1),
            // So then we can make more expensive and accurate cursor things and only update as needed

            IntPtr cursorPointer = ci.hCursor;

            cursorHandle = cursorPointer;

            int iconWidth  = Win32Funcs.GetSystemMetrics(Win32Consts.SystemMetric.SM_CXICON) + 1;
            int iconHeight = Win32Funcs.GetSystemMetrics(Win32Consts.SystemMetric.SM_CYICON) + 1;


            iconDims = new System.Drawing.Point(iconWidth, iconHeight);


            Win32Types.IconInfo hotSpotInfo = new Win32Types.IconInfo();
            Win32Funcs.GetIconInfo(cursorPointer, out hotSpotInfo);



            //Win32funcs.DrawIcon(hdcBitmap, 1, 1, cursorPointer);


            hotspot = new System.Drawing.Point(hotSpotInfo.xHotspot + 1, hotSpotInfo.yHotspot + 1);


            if (hotSpotInfo.hbmColor != IntPtr.Zero)
            {
                Win32Funcs.DeleteObject(hotSpotInfo.hbmColor);
            }
            if (hotSpotInfo.hbmMask != IntPtr.Zero)
            {
                Win32Funcs.DeleteObject(hotSpotInfo.hbmMask);
            }


            Win32Types.PointL cursorPos;
            Win32Funcs.GetCursorPos(out cursorPos);
            int cursorX = cursorPos.x - hotspot.X;
            int cursorY = cursorPos.y - hotspot.Y;

            cursorRect = new Win32Types.RECT(cursorX, cursorY, cursorX + iconDims.X, cursorY + iconDims.Y);
        }