• 光标跟随


           #region 得到光标在屏幕上的位置
     
            [DllImport("user32")]
     
             public static extern bool GetCaretPos(out Point lpPoint);
     
             [DllImport("user32.dll")]
     
             private static extern IntPtr GetForegroundWindow();
     
             [DllImport("user32.dll")]
     
             private static extern IntPtr GetFocus();
     
             [DllImport("user32.dll")]
     
             private static extern IntPtr AttachThreadInput(IntPtr idAttach, IntPtr idAttachTo, int fAttach);
     
             [DllImport("user32.dll")]
     
             private static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, IntPtr ProcessId);
     
             [DllImport("kernel32.dll")]
     
             private static extern IntPtr GetCurrentThreadId();
     
             [DllImport("user32.dll")]
     
             private static extern void ClientToScreen(IntPtr hWnd, ref Point p);
     
     
             private Point CaretPos()
     
             {
     
                 IntPtr ptr = GetForegroundWindow();
     
                 Point p = new Point();
     
     
                 //得到Caret在屏幕上的位置   
     
                 if (ptr.ToInt32() != 0)
     
                 {
     
                     IntPtr targetThreadID = GetWindowThreadProcessId(ptr, IntPtr.Zero);
     
                     IntPtr localThreadID = GetCurrentThreadId();
     
     
                     if (localThreadID != targetThreadID)
     
                     {
     
                         AttachThreadInput(localThreadID, targetThreadID, 1);
     
                         ptr = GetFocus();
     
                         if (ptr.ToInt32() != 0)
     
                         {
     
                             GetCaretPos(out   p);
     
                             ClientToScreen(ptr, ref   p);
     
                         }
     
                         AttachThreadInput(localThreadID, targetThreadID, 0);
     
                     }
     
                 }
     
                 return p;
     
             }
     
             #endregion
  • 相关阅读:
    前端如何进阶架构师
    NPOI使用记录
    ArcGis 中空间数据的插入与更新
    (转载).net 缓存处理
    ASP.NET(c#)实现重定向的三种方法的总结
    数据库关联表之间的更新语句
    C#net多线程多文件压缩下载
    关于写文件流的情况
    C# Class获取项目的绝对路径
    C# .net中DatailsView的JS简易版
  • 原文地址:https://www.cnblogs.com/swtool/p/6546937.html
Copyright © 2020-2023  润新知