检测窗口标题栏的高度
我正在使用 ClipCursor 将鼠标锁定在窗口中。如何检测窗口标题栏和窗口边框的高度(这样鼠标唯一不能点击标题栏和最小化、恢复和最大化按钮的地方)?
- 标题栏的高度取决于操作系统(我无法为此给出明确的值)。
- 我不确定不同操作系统的边框是否有不同的宽度。
- 我在经典模式下使用 Windows XP。
- 当我更改为主题模式时,标题栏的高度会发生变化,因此它不起作用。
- 没有使用特定的语言。
I am using ClipCursor to lock a mouse in a window. How do I detect the height of the window's title bar and border of the window (so the only place the mouse can't click the title bar and the minimize, restore and maximize button)?
- The height of the title bar depends on OS (I can't give a definite value for this).
- I'm not sure if the borders have different widths with different operating systems.
- I'm using windows XP on classic mode.
- When I change to themed mode the height of the title bar changes so it won't work.
- No specific language used.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用 AutoIt。
您不必处理特定的标题栏高度和边框宽度。相反,尝试将
MouseCoordMode
设置为相对客户端位置,将鼠标移动到顶部/左侧位置并获取窗口客户端大小。这正是您希望鼠标被困在的区域。然后可以在
_MouseTrap
函数中使用这些值。它应该类似于您的ClipCursor()
。旧的鼠标位置可以保存和恢复,但这没有意义,因为您的鼠标可能会重新定位到陷阱字段中,所以我将其注释掉。
You can use AutoIt.
You don't have to deal with that specific titlebar height and border width. Instead try to set the
MouseCoordMode
to relative client position, move the mouse to the top/left position and get the window client size. This is the exact area you want your mouse to be trapped into.These values can then be used in the
_MouseTrap
function. It should be similar to yourClipCursor()
.The old mouse Position could be saved and restored but it won't make sense as your mouse might be repositioned into the trap field anyways so I commented this out.
是否可以获取窗口的客户端矩形,而不是完整的矩形?我相信这将返回窗口的客户区域,即窗口的矩形减去边框和标题栏。
不过,如果您选择这条路线,则需要在调用
ClipCursor()
之前将矩形转换为屏幕坐标。Would it work to get the window's client rect, rather than its full rect? I believe that will return the client area of the window, which is the window's rect minus the border and title bar.
If you go this route, you will need to convert the rect into screen coordinates before calling
ClipCursor()
, though.我刚刚在浏览 AutoIt 帮助时找到了针对您问题的更具体答案。在函数的描述中
_WinAPI_CreateRectRgn()
有以下方法可以获得所需的尺寸:I just found out a more specific answer to your problem while browsing the AutoIt help. In the description of the function
_WinAPI_CreateRectRgn()
there is the following way to get the wished sizes:看起来
标题栏的高度是正确的
looks like
is the correct height of title bar
AutoHotKey 中的一种解决方案是简单地删除该栏!不过,这仍然允许人们使用快捷方式来操作窗口......
One solution in AutoHotKey is to simply remove the bar! That will still allow people to use short cuts to manipulate the window though...