Maus-in-Region-funktion funktioniert nicht

  • Hallo Community,
    grade erst frisch registriert und schon eine Frage ;) .
    Ich hab vor einen Videoplayer zu programmieren, scheitre aber schon an der gui ;(.
    Mein problem ist folgendes:
    Ich habe eine funktion geschrieben die überprüft ob sich die maus im eine bestimmten feld befindet. Nur das problem is das die funktion das scheibar nicht tut. Theoretisch müsste sich eine MsgBox öffnen sobald die Maus in der Region ist, aber passieren tut nix und den fehler finde ich auch nicht :(.
    Könnt mir bitte jemand helfen ?

    Die Funktion:

    [autoit]

    Func _Mouse_bereich_($X, $Y, $X2, $Y2)local $Mousepos = MouseGetPos() If ($Mousepos[0] >= $X And $Mousepos[0] <= $X2) and ($Mousepos[1] <= $Y And $Mousepos[1] >= $Y2) Thenreturn true else return falseEndif EndFunc

    [/autoit]

    und zum aufrufen:

    [autoit]

    if _Mouse_bereich_(0,50,400,356) then MsgBox(0,"test","test")Endif

    [/autoit]

    Den ganze Code häng ich mal an, weils den ganz unleserlich formatiert :S

  • kanstes auch mit

    [autoit]

    _WinAPI_PtInRect

    [/autoit]


    machen

    edit
    hier deine func

    [autoit]

    Func _Mouse_bereich_1($X, $Y, $X2, $Y2)
    local $Mousepos = MouseGetPos()
    If ($Mousepos[0] >= $X And $Mousepos[0] <= $X2) and ($Mousepos[1] >= $Y And $Mousepos[1] <= $Y2) Then
    return true
    else
    return false
    Endif
    EndFunc

    [/autoit]


    und hier noch mit winapi :D

    [autoit]

    Func _Mouse_bereich_($X, $Y, $X2, $Y2)
    $pos = MouseGetPos()
    $tRect = DllStructCreate("uint Left;uint Top;uint Right;uint Bottom")
    DllStructSetData($tRect, "Left", $X)
    DllStructSetData($tRect, "Top", $Y)
    DllStructSetData($tRect, "Right", $X2)
    DllStructSetData($tRect, "Bottom", $Y2)
    $tPoint = DllStructCreate("int x;int y")
    DllStructSetData($tPoint, "x", $pos[0])
    DllStructSetData($tPoint, "y", $pos[1])
    Return _WinAPI_PtInRect($tRect, $tPoint)
    EndFunc

    [/autoit]
  • Hi BOSSnier,

    oder so, da wird das Fenster auch noch mit einbezogen (so eine Art Erweiterung ;)) (nicht getestet)

    [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("MouseCoordMode", 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 ;==>_MouseIsInArea

    [/autoit]
  • hmm okay werd mir das mal durchlesen was die hilfe dazu sagt und versuchen :D
    Aber nur rein aus interesse, wiso hat das nicht so funktioniert wie ich es geschrieben hab :?:

    /e: Okay danke euch beiden werd mal gucken ob ichs damit hinbekommen :thumbup:

    versteh aber immer noch net wo des problem bei der funktion lag wie ich sie am anfang geschrieben hab (ich will damit jetzt nicht nerven, es interessiert mich einfach nur :D )

    2 Mal editiert, zuletzt von BOSSnier (28. August 2010 um 00:29)

  • Hallo BOSSnier,

    [autoit]

    While 1
    if _Mouse_bereich_(0,50,400,356) then MsgBox(0,"test","test")
    WEnd

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

    Func _Mouse_bereich_($X, $Y, $X2, $Y2)
    local $Mousepos = MouseGetPos()
    If ($Mousepos[0] >= $X And $Mousepos[0] <= $X2) and ($Mousepos[1] <= $Y And $Mousepos[1] >= $Y2) Then
    return true
    else
    return false
    Endif
    EndFunc

    [/autoit]

    deine Abfrage konnte nicht klappen, da die Maus die Bedingungen für $Y Und $Y2 nicht gleichzeitig erfüllen kann, denke mal Tippfehler (jeweils < > verwechselt) und später übersehen,

    mfg autoBert

    Einmal editiert, zuletzt von autoBert (28. August 2010 um 00:53)

  • Hallo yxyx,

    Deine erste Version geht so kürzer:

    [autoit]

    Func _Mouse_bereich_1($iLeft, $iTop, $iRight, $iBottom)
    local $Mousepos = MouseGetPos()
    Return ($Mousepos[0] >= $iLeft And $Mousepos[0] <= $iRight) and ($Mousepos[1] >= $iTop And $Mousepos[1] <= $iBottom)
    EndFunc

    [/autoit]


    Und deine zweite geht so kürzer:

    [autoit]

    Func _Mouse_bereich_($iLeft, $iTop, $iRight, $iBottom)
    Local $tRECT = DllStructCreate('int Left;int Top;int Right;int Bottom'), $aMPos = MouseGetPos(), $aRet
    DllCall("user32", 'long', 'SetRect', 'ptr', DllStructGetPtr($tRECT), 'long', $iLeft, 'long', $iTop, 'long', $iRight, 'long', $iBottom)
    $aRet = DllCall("user32", 'long', 'PtInRect', 'ptr', DllStructGetPtr($tRECT), 'long', $aMPos[0], 'long', $aMPos[1])
    Return $ret[0] > 0
    EndFunc

    [/autoit]

    Wollte das nur mal loswerden ^^