WPF:绘制自己的游标 - 非平凡问题 [英] WPF: drawing own cursor - nontrivial problem

查看:304
本文介绍了WPF:绘制自己的游标 - 非平凡问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要实现一个具有一些非常具体功能的游标:

i need to implement a cursor with some very specific features:


  • 它必须是动画的


    • 因为在n秒后它会自动点击 - 所以动画会在用户点击发生时反馈。

    到目前为止的方法:


    • 将我的WPF控件转换为位图,使用user32.dll / SetSystemCursor将其设置为


      • PRO


      • 捕捉是相当困难的,尤其是因为我们有绝对的和相对inputdevices和我将不得不重置mouseposition所有的时间或使用user32.dll / ClipCursor(System.Windows.Forms.Cursor.Clip做同样),但被捕捉的光标总是在捕捉位置周围颤抖(试图逃跑,


      • PRO

      • 可以轻松完成贴图
      • 当鼠标点击并点击游标获得点击的光标,而不是之外的窗口时,$ b
      • CON

      • <
      • PRO
      • snapping can be (easily) done
      • CON
      • when the mouse clicks and hit's the cursor the cursor get's clicked and not the window beyond
      • polling the mouseposition in a dispatcher-background-loop all the time doesn't seem very beautiful to me

      为了解决第二种方法,我的光标必须在热点中至少有一个透明像素
      ,这样鼠标可以点击通过...看起来不像是真实的解决方案...

      to solve the second approach my cursor would have to have at least one transparent pixel in the hotspot, so that the mouse can click through... that doesn't seem like a real solution to me...

      任何想法的任何人?

      编辑:
      some example-source显示问题...:

      some example-source to show the problems...:

      示例应用程式&源显示将鼠标捕捉到固定位置的问题:ClipIt.rar

      example app & source to show the problem with snapping the mouse to a fixed position: ClipIt.rar

      示例app&源在随机时间后失败 - 设置自动绘制的光标:TryOwnCur.rar

      example app & source that fails after random time - setting a self-drawn cursor: TryOwnCur.rar

      可以在 http://sourcemonk.com/Cursor

      推荐答案

      a href =http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a3cb7db6-5014-430f-a5c2-c9746b077d4f =nofollow noreferrer> http://social.msdn .microsoft.com / Forums / zh-CN / wpf / thread / a3cb7db6-5014-430f-a5c2-c9746b077d4f

      thanks to http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a3cb7db6-5014-430f-a5c2-c9746b077d4f

      通过
      设置窗口样式的鼠标位置的绘制光标:none和allowtransparent如我已经做的那样,
      然后

      i can click through my self-drawn cursor which follows the mouse-position by setting the window style:none, and allowtransparent as i already did and then

      public const int WS_EX_TRANSPARENT = 0x00000020;
        public const int GWL_EXSTYLE = (-20);
      
        [DllImport("user32.dll")]
        public static extern int GetWindowLong(IntPtr hwnd,
        int index);
      
        [DllImport("user32.dll")]
        public static extern int SetWindowLong(IntPtr hwnd,
        int index, int newStyle);
      
        public static void makeTransparent(IntPtr hwnd) {
           int extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
           SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT);
        }
      

      并从OnSourceInitialized调用makeTransparent ...

      and call makeTransparent from OnSourceInitialized...

      这篇关于WPF:绘制自己的游标 - 非平凡问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆