ClipCursor() -- 限制鼠标活动区域

函数原型

BOOL ClipCursor(CONST RECT * lpRect);

函数功能

该函数把鼠标限制在屏幕上的一个矩形区域内,如果调用SetCursor或用鼠标设置的一个随后的鼠标位置在该矩形区域的外面,

则系统自动调整该位置以保持鼠标在矩形区域之内。

参数

IpRect:指向RECT结构的指针,该结构包含限制矩形区域左上角和右下角的屏幕坐标,

如果该指针为NULL(空),则鼠标可以在屏幕的任何区域移动。

返回值

如果成功,返回值非零;如果失败,返回值为零。若想获得更多错误信息,请调用GetLastError。

备注

光标是一个共享资源,如果一个应用控制了鼠标,在将控制转向另一个应用之前,必须要使用ClipCursor来释放鼠标,

该调用过程必须具有对窗口的WINSTA_WRITEATTRIBUTES访问权。

例如:
#include <stdio.h>
#include <windows.h>
int main(intargc,char*argv[])
{
    printf("\n别害怕15秒后你的鼠标就可以使用了^_^\n");
    RECT rect;
    rect.bottom = 1;
    rect.right = 1;
//-----------add------
    rect.left = 0;
    rect.top = 0;
//-----------end-----
    ClipCursor(&rect);
    ::Sleep(15000);
    ClipCursor(NULL);//释放
    return 0;
}
时间: 2024-08-25 10:23:51

ClipCursor() -- 限制鼠标活动区域的相关文章

接触/限制鼠标活动区域

this.Cursor = new Cursor(Cursor.Current.Handle); Cursor.Position = new Point(Cursor.Position.X,Cursor.Position.Y);//鼠标位置 Cursor.Clip = new Rectangle(this.Location,this.Size);//设置鼠标活动区域窗体的位置和大小 Screen screen = Screen.PrimaryScreen; //创建Screen对象 this.C

限制鼠标活动区域

实现效果: 知识运用: Cursor类中的相关属性 实现代码: private void button1_Click(object sender, EventArgs e) { this.Cursor = new Cursor(Cursor.Current.Handle); //创建Cursor对象 Cursor.Position = new Point(Cursor.Position.X,Cursor.Position.Y); //设置鼠标位置 Cursor.Clip = new Rectan

把鼠标限制在窗口内

玩魔兽和LOL时注意到即时游戏窗口最小化,鼠标仍限制在窗口内,这具体是怎么实现的呢? Msdn上有个例子 Confining a Cursor: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 RECT rcClip;           // new area for ClipCursor RECT rcOldClip;        // previous area for ClipCursor   // Record t

Delphi锁定鼠标 模拟左右键 静止一会自动隐藏鼠标

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ImgList, ComCtrls, ExtCtrls; type TForm1 = class(TForm) Button1: TButton; Edit1: TEdit; Button2: TButton; Button3: TButton; Butto

Windows鼠标键盘消息处理

1 #include <windows.h> 2 #include <tchar.h> //swprintf_s函数所需的头文件 3 4 #pragma comment(lib, "winmm.lib") //playSound 5 #pragma comment(lib, "Msimg32.lib") //TransparentBlt 6 7 #define WINDOW_WIDTH 800 8 #define WINDOW_HEIGHT

鼠标悬停图片移动的效果

当前很多购物网站,像京东,蘑菇街这些都有对展示的图片做这种鼠标悬停图片上移,下移,左移或者右移效果, 实现代码很简单,就用css3的transform便可实现. 下列代码实现的是鼠标悬停,div向上移动30px,鼠标拿开div恢复原始位置. css: <style> div{ margin-top: 100px; width: 100px; height: 100px; background: pink; transition:All 0.4s ease-in-out;//让移动效果变得平滑自

更换鼠标垫(鼠标)的心路历程

先给我自己的结论吧, 列个提纲, 有心情的话, 去写. 结论: 感觉无线的鼠标还是好, 但是要想鼠标顺滑的话, 需要鼠标脚垫与鼠标垫的共同配合. 金属鼠标垫虽然好用, 夏天也不错, 但磨损脚垫厉害, 所以反而不顺滑了. 如果可以更换脚垫, 那自然是极好的, 并且用个平常的布的鼠标垫就可以了. 桌子如果不输入的话, 入手一个 50 * 100 的鼠标垫吧. 会感觉很舒服, 不会再咯到胳膊了. 先列一个提纲吧. 换了好多鼠标, 鼠标垫, 还有键盘. 似乎是对外设有些追求. 不过目前就是笔记本(mac

QCustomPlot 鼠标消息获取,以及对应坐标转换

1 首先在 MainWindow.h 中加入 消息处理程序(槽) private slots: void my_mouseMove(QMouseEvent* event); 2 在 MainWindow.cpp 中实现 (槽) void MainWindow::my_mouseMove(QMouseEvent* event) { //获取鼠标坐标点 int x_pos = event->pos().x(); int y_pos = event->pos().y(); // 把鼠标坐标点 转换为

[读码时间] 图片列表:鼠标移入/移出改变图片透明度

说明:代码来自网络.注释为笔者学习时添加. <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>图片列表:鼠标移入/移出改变图片透明度</title> <style> ul,li{ /*去除内外边距,去除列表默认样式*/ margin:0; padding:0; list-style-type:none; } #imgList{ /