检测窗口标题栏的高度

发布于 2024-10-03 21:22:41 字数 256 浏览 2 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

万水千山粽是情ミ 2024-10-10 21:22:41

您可以使用 AutoIt。

您不必处理特定的标题栏高度和边框宽度。相反,尝试将 MouseCoordMode 设置为相对客户端位置,将鼠标移动到顶部/左侧位置并获取窗口客户端大小。这正是您希望鼠标被困在的区域。

然后可以在 _MouseTrap 函数中使用这些值。它应该类似于您的 ClipCursor()

旧的鼠标位置可以保存和恢复,但这没有意义,因为您的鼠标可能会重新定位到陷阱字段中,所以我将其注释掉。

#include <GuiConstantsEx.au3>
#include <Misc.au3>

Opt("MustDeclareVars", 1)

_Main()

Func _Main()
    Local $GUI, $oldMouseCoordMode, $topLeft, $size ;,$oldMousePos

    $GUI = GUICreate("Example MouseTrap", 392, 323)
    GUISetBkColor( 0xff0000, $GUI)

    GUISetState()

;~  $oldMousePos = MouseGetPos()
    $oldMouseCoordMode = Opt("MouseCoordMode", 2)
    MouseMove(0, 0, 0)
    Opt("MouseCoordMode", 1)
    $topLeft = MouseGetPos()
;~  MouseMove($oldMousePos[0], $oldMousePos[1], 0)
    $size = WinGetClientSize($GUI)
    Opt("MouseCoordMode", $oldMouseCoordMode)
    _MouseTrap($topLeft[0], $topLeft[1], $topLeft[0] + $size[0], $topLeft[1] + $size[1])

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case Else
                ;;;
        EndSwitch
    WEnd
    _MouseTrap()
    Exit
EndFunc   ;==>_Main

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 your ClipCursor().

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.

#include <GuiConstantsEx.au3>
#include <Misc.au3>

Opt("MustDeclareVars", 1)

_Main()

Func _Main()
    Local $GUI, $oldMouseCoordMode, $topLeft, $size ;,$oldMousePos

    $GUI = GUICreate("Example MouseTrap", 392, 323)
    GUISetBkColor( 0xff0000, $GUI)

    GUISetState()

;~  $oldMousePos = MouseGetPos()
    $oldMouseCoordMode = Opt("MouseCoordMode", 2)
    MouseMove(0, 0, 0)
    Opt("MouseCoordMode", 1)
    $topLeft = MouseGetPos()
;~  MouseMove($oldMousePos[0], $oldMousePos[1], 0)
    $size = WinGetClientSize($GUI)
    Opt("MouseCoordMode", $oldMouseCoordMode)
    _MouseTrap($topLeft[0], $topLeft[1], $topLeft[0] + $size[0], $topLeft[1] + $size[1])

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case Else
                ;;;
        EndSwitch
    WEnd
    _MouseTrap()
    Exit
EndFunc   ;==>_Main
多像笑话 2024-10-10 21:22:41

是否可以获取窗口的客户端矩形,而不是完整的矩形?我相信这将返回窗口的客户区域,即窗口的矩形减去边框和标题栏。

不过,如果您选择这条路线,则需要在调用 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.

可是我不能没有你 2024-10-10 21:22:41

我刚刚在浏览 AutoIt 帮助时找到了针对您问题的更具体答案。在函数的描述中 _WinAPI_CreateRectRgn() 有以下方法可以获得所需的尺寸:

#include <WinAPI.au3>

; get height of window title and width of window frame - may be different when
; XP theme is ON/OFF
Global $htit = _WinAPI_GetSystemMetrics($SM_CYCAPTION)
Global $frame = _WinAPI_GetSystemMetrics($SM_CXDLGFRAME)

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:

#include <WinAPI.au3>

; get height of window title and width of window frame - may be different when
; XP theme is ON/OFF
Global $htit = _WinAPI_GetSystemMetrics($SM_CYCAPTION)
Global $frame = _WinAPI_GetSystemMetrics($SM_CXDLGFRAME)
琉璃梦幻 2024-10-10 21:22:41

看起来

GetSystemMetrics(SM_CYCAPTION)+GetSystemMetrics(SM_CYSIZEFRAME) 

标题栏的高度是正确的

looks like

GetSystemMetrics(SM_CYCAPTION)+GetSystemMetrics(SM_CYSIZEFRAME) 

is the correct height of title bar

等待我真够勒 2024-10-10 21:22:41

AutoHotKey 中的一种解决方案是简单地删除该栏!不过,这仍然允许人们使用快捷方式来操作窗口......

^F11:: ; Ctrl+F11 = Toggle show Window title bar
WinSet, Style, ^0xC00000, A  ; Toggle the active window's title bar (WS_CAPTION).
If (TopbarHide := !TopbarHide) ;
    ToolTip Topbar Ctrl F11,A_ScreenWidth/2-50,0
else
    Tooltip
Return

One solution in AutoHotKey is to simply remove the bar! That will still allow people to use short cuts to manipulate the window though...

^F11:: ; Ctrl+F11 = Toggle show Window title bar
WinSet, Style, ^0xC00000, A  ; Toggle the active window's title bar (WS_CAPTION).
If (TopbarHide := !TopbarHide) ;
    ToolTip Topbar Ctrl F11,A_ScreenWidth/2-50,0
else
    Tooltip
Return
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文