C# .NET中如何使用GetCursorPos函数 例程
来源:互联网 发布:欧姆龙plc网络通信 编辑:程序博客网 时间:2024/04/19 21:50
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace CursorPosition
{
public partial class frmMain : Form
{
// We need to use unmanaged code
[DllImport("user32.dll")]
// GetCursorPos() makes everything possible
static extern bool GetCursorPos(ref Point lpPoint);
// Variable we will need to count the traveled pixels
static protected long totalPixels = 0;
static protected int currX;
static protected int currY;
static protected int diffX;
static protected int diffY;
public frmMain()
{
InitializeComponent();
}
private void tmrDef_Tick(object sender, EventArgs e)
{
// New point that will be updated by the function with the current coordinates
Point defPnt = new Point();
// Call the function and pass the Point, defPnt
GetCursorPos(ref defPnt);
// Now after calling the function, defPnt contains the coordinates which we can read
lblCoordX.Text = "X = " + defPnt.X.ToString();
lblCoordY.Text = "Y = " + defPnt.Y.ToString();
// If the cursor has moved at all
if (diffX != defPnt.X | diffY != defPnt.Y)
{
// Calculate the distance of movement (in both vertical and horizontal movement)
diffX = (defPnt.X - currX);
diffY = (defPnt.Y - currY);
// The difference will be negative if the cursor was moved left or up
// and if it is so, make the number positive
if (diffX < 0)
{
diffX *= -1;
}
if (diffY < 0)
{
diffY *= -1;
}
// Add to the "pixels traveled" counter
totalPixels += diffX + diffY;
// And display inside a label
lblTravel.Text = "You have traveled " + totalPixels + " pixels";
}
// We need this to see the difference of pixels between two mouse movements
currX = defPnt.X;
currY = defPnt.Y;
}
private void btnReset_Click(object sender, EventArgs e)
{
totalPixels = 0;
}
}
}
- C# .NET中如何使用GetCursorPos函数 例程(转载)
- C# .NET中如何使用GetCursorPos函数 例程
- C# .NET中如何使用GetCursorPos函数
- C#中使用GetCursorPos获取屏幕坐标
- ASP.NET中使用Cache例程
- ASP.NET中使用Cache例程
- GetClinetRect GetWindowRect ScreenToClient ClientToScreen GetCursorPos几个函数的正确使用
- GetCursorPos
- GetCursorPos
- GetCursorPos
- Windows硬件系统函数 - GetCursorPos
- js中函数、变量如何在C#中使用?C#中函数、变量如何在js中使用?
- .NET中常用C#函数
- .Net C# - 如何获得一个事件(Event)的订阅者(Handler)的数量和列表?(例程)
- MFC中InvalidateRect 、GetCursorPos、静态或全局变量使用、 error RC1121 四个问题
- C#中如何退出函数
- typedef 函数指针使用例程
- GetCursorPos()函数的奇怪现象
- 游标练习
- 数据挖掘之关联规则挖掘之SETM算法实现
- 设置和读取Cookie
- 对oracle当中子查询建表,merge操作,创建,修改,删除约束,创建使用触发器的复习练习
- 将CentOS多个CD镜像合并成一个DVD镜像
- C# .NET中如何使用GetCursorPos函数 例程
- 利用java io 将从iteye或者csdn复制的的代码的行号去掉的
- string容器
- zzuli 1661--0的个数
- 时间格式化方式,由Date对象生成Calander对象
- Lucene中索引的删除,更新与查找以及恢复(lucene3.5)
- 文件读写的实验
- Android 射击类游戏 (一)
- ABAP 指針常用语法