〓〓◆怎么把鼠标限制在一个范围里?◆〓〓马上给分!!!

anjy 2002-05-15 05:47:18
怎么把鼠标限制在一个范围里?比如,在一个对话框的应用程序里,吧鼠标限制在该窗口内。请具体点!
...全文
285 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
g_windy 2002-05-17
  • 打赏
  • 举报
回复
//Start
RECT rc;
GetWindowRect( &rc );
rc.top = rc.top+25;
SetForegroundWindow();
SetCapture();
ClipCursor( &rc );

//End
ReleaseCapture();
ClipCursor(NULL);
anjy 2002-05-16
  • 打赏
  • 举报
回复
当然是系统范围内了
webber84 2002-05-16
  • 打赏
  • 举报
回复
关键是看你要在多大程度上限制鼠标。
anjy 2002-05-16
  • 打赏
  • 举报
回复
啊,又是钩子!!不用钩子不行吗?我对钩子实在没把握,好像系统钩子要用DLL,又是一大难点!
webber84 2002-05-16
  • 打赏
  • 举报
回复
如果你想在系统范围内限制鼠标移动的话,好像只能用HOOK。因为用ClipCusor总能通过alt+tab来切换窗口,只要一切换到别的窗口,ClipCusor就不起作用了。
golq 2002-05-16
  • 打赏
  • 举报
回复
补充问一下,如果窗口是园的呢?

我以前作了一个院窗口,没法用clipcursor,只有用mousemove判断,有没有好办法呀
anjy 2002-05-16
  • 打赏
  • 举报
回复
TO:dou_ya(豆芽菜)
按你的方法,虽然一开始可以限定鼠标范围,但是,但用鼠标拖动一下改对话框,或新开一个其他任何窗口(如:资源管理器)后,限制范围就不起作用了。
eastrock 2002-05-15
  • 打赏
  • 举报
回复
BOOL ClipCursor(
CONST RECT *lpRect);
tifaling 2002-05-15
  • 打赏
  • 举报
回复
RECT rect;
rect.top=0;rect.botton=640;
rect.left=0;rect.right=480;
ClipCursor(&rect);
把鼠标限定在(0,0)~(640,480)
dou_ya 2002-05-15
  • 打赏
  • 举报
回复
ClipCursor 是 Win32 API,MFC 没有进行封装。

ClipCursor
The ClipCursor function confines the cursor to a rectangular area on the screen. If a subsequent cursor position (set by the SetCursorPos function or the mouse) lies outside the rectangle, the system automatically adjusts the position to keep the cursor inside the rectangular area.

BOOL ClipCursor(
CONST RECT *lpRect // screen coordinates
);
Parameters
lpRect
[in] Pointer to the RECT structure that contains the screen coordinates of the upper-left and lower-right corners of the confining rectangle. If this parameter is NULL, the cursor is free to move anywhere on the screen.
Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks
The cursor is a shared resource. If an application confines the cursor, it must release the cursor by using ClipCursor before relinquishing control to another application.

The calling process must have WINSTA_WRITEATTRIBUTES access to the window station.
dou_ya 2002-05-15
  • 打赏
  • 举报
回复
BOOL C***Dlg::StartClipCusor()
{
RECT rc;
GetWindowRect( &rc );

return ClipCursor( &rc );
}

BOOL C***Dlg::EndClipCursor()
{
return ClipCursor(NULL);
}
linning6 2002-05-15
  • 打赏
  • 举报
回复
找本参考书看看嘛。
vc8 2002-05-15
  • 打赏
  • 举报
回复
RECT rc;
RECT oldRc;
GetClipCursor( &oldRc );
GetWindowRect( &rc );
ClipCursor( &rc );
....
//退出
ClipCursor( &oldRc );
webber84 2002-05-15
  • 打赏
  • 举报
回复
masterz() 说的是SDK的方法。如果你用MFC的话,直接用CWnd*调用函数就是了。
anjy 2002-05-15
  • 打赏
  • 举报
回复
hwnd是什么,如何得到?
masterz 2002-05-15
  • 打赏
  • 举报
回复
Confining a Cursor
The following example confines the cursor to the application's window and then restores the cursor to its previous window. The example uses the GetClipCursor function to record the area in which the cursor can move and the ClipCursor function to confine and restore the cursor.

RECT rcClip; // new area for ClipCursor
RECT rcOldClip; // previous area for ClipCursor

// Record the area in which the cursor can move.

GetClipCursor(&rcOldClip);

// Get the dimensions of the application's window.

GetWindowRect(hwnd, &rcClip);

// Confine the cursor to the application's window.

ClipCursor(&rcClip);

//
// Process input from the confined cursor.
//

// Restore the cursor to its previous area.

ClipCursor(&rcOldClip);
Because there is only one cursor at a time available in the system, an application that confines the cursor must restore the cursor before relinquishing control to another window.
anjy 2002-05-15
  • 打赏
  • 举报
回复
范围怎么设?
webber84 2002-05-15
  • 打赏
  • 举报
回复
ClipCursor()

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧