zoukankan      html  css  js  c++  java
  • 获取鼠标句柄

    (1)引用

    using System.Runtime.InteropServices;

    (2)调用方法

    1、获取窗口标题

    [DllImport( "user32.dll" )]  
    public static extern int GetWindowText( IntPtr hWnd, StringBuilder lpString,int nMaxCount );

    注:hWnd 窗口句柄 lpString 窗口标题 nMaxCount 最大值

    2、获取类名

    [DllImport( "user32.dll" )]  
    public static extern int GetClassName( IntPtr hWnd, StringBuilder lpString,int nMaxCount );

    注:hWnd 句柄 lpString 类名 nMaxCount 最大值

    3、根据坐标获取窗口句柄

    [DllImport( "user32.dll" )]  
    public static extern IntPtr WindowFromPoint(Point point);

    注:point 坐标

    二、显示数据

    (1) 获取鼠标坐标

    int x = Cursor.Position.X;
    int y = Cursor.Position.Y;
    this.textBox4.Text = string.Format( "({0},{1})" , x, y);

    (2) 获取句柄

    Point p = new Point(x,y);
    IntPtr formHandle = WindowFromPoint(p);
    this.textBox1.Text = formHandle.ToString();

    (3) 得到窗口标题

    GetWindowText(formHandle,title,title.Capacity);
    this.textBox2.Text = title.ToString();

    (4)得到窗体的类名

    StringBuilder cllassName = new StringBuilder();
    GetClassName(formHandle,cllassName,cllassName.Capacity);
    this.textBox3.Text = cllassName.ToString();

    (5)Load事件

    this.timer1.Enabled = !this.timer1.Enabled;

    注:动态显示信息

  • 相关阅读:
    《人月神话》阅读笔记02
    学习进度条-4
    课堂作业3
    MySql 8.0及对应驱动包匹配注意点
    关于Ubuntu中Could not get lock /var/lib/dpkg/lock解决方案
    STM32之ADC配置,ADC_Mode模式理解
    STM32串口中断的方式发送
    RTC 与RCC 之间的关系
    stm32 MDK5软件仿真之查看io口输出
    STM32 PWM学习
  • 原文地址:https://www.cnblogs.com/edangame/p/7637543.html
Copyright © 2011-2022 走看看