bereich definieren

  • Hi com,

    ich hab mal n bissle gebastelt und will meine udf bald veröffentlichen (recht was von mir, ein bisschen was zusammengesammeltes, aber verbessert;))
    hier mal die func, sie soll einen bereich erfassen, wenn sich die maus in diesem bereich befindet, dann kommt true raus, wenn nicht, dann False ^^

    Spoiler anzeigen
    [autoit]

    While 1
    MsgBox(0, "Ergebnis", _WinIsHovered(@DesktopHeight / 2 - 100, @DesktopWidth - 2, 200, 2))
    WEnd
    Func _WinIsHovered($iXPoint, $iYPoint, $iXLenght, $iYLenght)
    Opt("MouseCoordMode", 1)
    If Not IsDeclared("aResult") Then Global $aResult
    Local $aResult, $aMPos = MouseGetPos()
    If $aMPos[0] > $iXPoint Then
    If $aMPos[0] < $iXPoint + $iXLenght Then
    If $aMPos[1] > $iYPoint Then
    If $aMPos[1] < $iYPoint + $iYLenght Then
    $aResult = True
    EndIf
    EndIf
    EndIf
    Else
    $aResult = False
    EndIf
    Return $aResult
    EndFunc ;==>_WinIsHovered

    [/autoit]

    (SEuBo wird das villt wiedererkennen (an dem namen))

  • Also ich persönlich würd es so machen (So lässt man die Arbeit direkt von einer DLL machen)

    Spoiler anzeigen
    [autoit]

    MsgBox(0,"",_MouseIsInArea(0,0,100,100))

    [/autoit] [autoit][/autoit] [autoit]

    Func _MouseIsInArea($iX, $iY, $iWidth, $iHeight)
    Local $aResult, $tRct, $aMPos = MouseGetPos()
    $tRct = DllStructCreate("int Left;int Top;int Right;int Bottom")
    DllStructSetData($tRct, "Left", $iX)
    DllStructSetData($tRct, "Top", $iY)
    DllStructSetData($tRct, "Right", $iX + $iWidth)
    DllStructSetData($tRct, "Bottom", $iY + $iHeight)

    [/autoit] [autoit][/autoit] [autoit]

    $aResult = DllCall("user32.dll", "bool", "PtInRect", "ptr", DllStructGetPtr($tRct), "long", $aMPos[0], "long", $aMPos[1])
    Local $iErr = @error, $tRct = 0
    If $iErr Then Return SetError(@error, @extended, False)
    Return ($aResult[0] = True)
    EndFunc ;==>_MouseIsInArea

    [/autoit]


    Edit: Alternativ geht es natürlich auch mit deiner Methode:

    Spoiler anzeigen
    [autoit]

    Func _WinIsHovered($iXPoint, $iYPoint, $iXLenght, $iYLenght)
    Opt("MouseCoordMode", 1)
    Local $aResult, $aMPos = MouseGetPos()
    If $aMPos[0] >= $iXPoint Then
    If $aMPos[0] <= $iXPoint + $iXLenght Then
    If $aMPos[1] >= $iYPoint Then
    If $aMPos[1] <= $iYPoint + $iYLenght Then
    Return True
    EndIf
    EndIf
    EndIf
    EndIf
    Return False
    EndFunc ;==>_WinIsHovered

    [/autoit]
    • Offizieller Beitrag

    Und um es noch kürzer zu machen, befüllt man die Struktur in einem Aufruf. ;)

    [autoit]

    HotKeySet('#!e', '_exit')

    [/autoit][autoit][/autoit][autoit]

    While 1
    ConsoleWrite( _MouseOverRECT(10, 10, 200, 200) & @CRLF)
    Sleep(100)
    WEnd

    [/autoit][autoit][/autoit][autoit]

    Func _exit()
    Exit
    EndFunc

    [/autoit][autoit][/autoit][autoit]

    Func _MouseOverRECT($iLeft, $iTop, $iRight, $iBottom)
    Local $tRECT = DllStructCreate('int Left;int Top;int Right;int Bottom')
    Local $old = Opt("MouseCoordMode", 1), $aMousePos = MouseGetPos()
    Opt("MouseCoordMode", $old)
    DllCall("user32", 'long', 'SetRect', 'ptr', DllStructGetPtr($tRECT), 'long', $iLeft, 'long', $iTop, 'long', $iRight, 'long', $iBottom)
    Local $ret = DllCall("user32", 'long', 'PtInRect', 'ptr', DllStructGetPtr($tRECT), 'long', $aMousePos[0], 'long', $aMousePos[1])
    If $ret[0] > 0 Then Return True
    Return False
    EndFunc

    [/autoit]

    Verwendung von Opt("MouseCoordMode", 1) ist richtig und wichtig. Aber auch bitte den vorherigen Wert speichern und anschließend zurücksetzen. Es kann ja sein, dass im Programm momentan ein anderer Modus genutzt wird.

  • sry bugfix, deins geht, ich hatte das nur noch nicht gelesen, als ich die anchricht geschickt hatte... ich probier mal weiter rum, aber das thema ist an sich [gelößt]
    edit1:
    habe nur seiten vertauscht ;)
    edit2:
    sry, dass ich den thread wieder geöffnet habe, aber es funktioniert immernoch nicht ganz korrekt

    Spoiler anzeigen
    [autoit]

    Func _MouseIsInArea($iYPoint, $iXPoint, $iYLenght, $iXLenght, $hWnd = 1)
    Opt("MouseCoordMode", 1)
    Global $OnhWnd = False, $aMPos = MouseGetPos()
    If $OnhWnd = False And $aMPos[0] >= $iYPoint And $aMPos[0] <= $iYPoint + $iYLenght And $aMPos[1] >= $iXPoint And $aMPos[1] <= $iXPoint + $iXLenght Then
    Return True
    $OnhWnd = True
    EndIf
    If $OnhWnd = True And $hWnd <> 1 Then
    Opt("MousCoordMode", 2)
    Global $aMPos = MouseGetPos(), $ahWndPos = WinGetPos($hWnd)
    If $aMPos[0] >= $ahWndPos[0] And $aMPos[0] <= $ahWndPos[0] + $ahWndPos[2] And $aMPos[1] >= $ahWndPos[1] And $aMPos[1] <= $ahWndPos[1] + $ahWndPos[3] Then
    Return True
    EndIf
    Else
    $OnhWnd = False
    Return False
    EndIf
    EndFunc ;==>_WinIsHovered

    [/autoit]

    wenn einmal true rauskam, soll erst wieder false kommen, wenn das fenster (der bereich) verlassen wurde