【问题标题】:How can i allow actions with my GUI only when mouse hovers the GUI仅当鼠标悬停在 GUI 上时,我如何才能允许对我的 GUI 进行操作
【发布时间】:2019-07-04 19:52:47
【问题描述】:

我只想在鼠标悬停在 GUI 上时才允许对我创建的 GUI 进行操作。现在我可以通过 ESC 关闭我的 GUI,但这只有在我将鼠标悬停在 GUI 上时才有可能。

  • 我该怎么做?

在我的一个爱好项目中,我尝试了一些微型游戏。现在我想在 Autoit 中做点什么。下面的代码只是一个例子。当你能给我一些提示时,我会增加我的 GUI。

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("GameTryout", 500, 500, -1, -1)
$cEdit = GUICtrlCreateEdit("test", 20, 20, 200, 100)
GUISetState(@SW_SHOW, $hGUI)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIDelete($hGui)
            Exit
    EndSwitch
WEnd
  • 如何避免在不使用鼠标在 GUI 上的情况下关闭我的 GUI?

感谢您的建议。

【问题讨论】:

    标签: user-interface mouseover autoit


    【解决方案1】:

    您可以使用MouseGetPos()WinGetPos() 来检查鼠标光标是否悬停在您的GUI 上。 _isMouseOnGui() 应该符合您的要求:

    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    
    $hGUI = GUICreate("GameTryout", 500, 500, -1, -1)
    $cEdit = GUICtrlCreateEdit("test", 20, 20, 200, 100)
    GUISetState(@SW_SHOW, $hGUI)
    
    Func _isMouseOnGui($hGui)
        Local $aMouse = MouseGetPos()
        Local $aGui   = WinGetPos($hGui)
    
        If $aMouse[0] >= $aGui[0] And _
           $aMouse[1] >= $aGui[1] And _
           $aMouse[0] <= $aGui[0] + $aGui[2] And _
           $aMouse[1] <= $aGui[1] + $aGui[3] Then
           Return True
        EndIf
    
        Return False
    EndFunc
    
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                If _isMouseOnGui($hGui) Then
                    GUIDelete($hGui)
                    Exit
                EndIf
        EndSwitch
    WEnd
    

    通过检查窗口/GUI 位置和鼠标位置来扩展您的 GUI 操作以了解未来的功能。

    【讨论】:

      猜你喜欢
      • 2019-09-10
      • 1970-01-01
      • 1970-01-01
      • 2010-12-12
      • 2012-11-20
      • 2023-03-07
      • 2020-02-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多