Mausangucker

  • Hallo,

    Der Titel ist zwar etwas komisch, aber ich berkläre es: Ich möchte ein Programm schreiben, wo man in der Bildschirmmitte einen Pfeil hat und dieser Pfeil zeigt immer auf die Maus, und zwar in 45° Winkel, also etwas so:
    autoit.de/wcf/attachment/13668/
    Wie kann ich nun prüfen ob die Maus nun ganz oben ist, oder eher an der seite, sodass sich also der Pfeil zum Mauszeiger wendet?

    mfg
    hauke96

  • Such mal nach SpeedStarter oder so ähnlich, da siehst du wie das geht, ansonstem mit WInkelberechnung.

  • Hab mal was gebastelt...
    Da ich recht wenig Ahnung von GDI+ hab, musste ein Uhr-Script von name22 dran glauben (Danke dafür!)

    Nicht schön, aber selten :D:

    Spoiler anzeigen
    [autoit]

    #NoTrayIcon
    #include <GDIP.au3>
    #include <GDIPConstants.au3>
    #include <GUIConstants.au3>
    #include <WindowsConstants.au3>
    #include <GUIConstantsEx.au3>

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

    HotKeySet("{ESC}", "_Exit")

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

    Global $Winkel_akt, $Winkel, $DX, $DY, $AK, $GK
    $GUIColorBG = 0xFFFFFF00

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

    Global $GUI = GUICreate("", 100, 100, @DesktopWidth / 2 - 50, @DesktopHeight / 2 - 50, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
    GUISetState(@SW_SHOW, $GUI)

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

    _GDIPlus_Startup()

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

    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($GUI)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics(100, 100, $hGraphic)
    $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2)
    $Zeiger = _GDIPlus_PenCreate(0xFFFF0000, 3)

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

    Global $MX = @DesktopWidth / 2
    Global $MY = @DesktopHeight / 2
    Global $pi = 3.14159265358979
    Global $RadToDeg = 180 / $pi

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

    While 1
    Global $Pos = MouseGetPos()

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

    If $Pos[0] > $MX And $Pos[1] > $MY Then ;Quadrant 2
    $DX = $Pos[0] - $MX
    $DY = $Pos[1] - $MY
    $AK = $DX
    $GK = $DY
    $QP = 90
    ElseIf $Pos[0] < $MX And $Pos[1] > $MY Then ;Quadrant 3
    $DX = $MX - $Pos[0]
    $DY = $Pos[1] - $MY
    $AK = $DY
    $GK = $DX
    $QP = 180
    ElseIf $Pos[0] < $MX And $Pos[1] < $MY Then ;Quadrant 4
    $DX = $MX - $Pos[0]
    $DY = $MY - $Pos[1]
    $AK = $DX
    $GK = $DY
    $QP = 270
    ElseIf $Pos[0] > $MX And $Pos[1] < $MX Then ;Quadrant 1
    $DX = $Pos[0] - $MX
    $DY = $MY - $Pos[1]
    $AK = $DY
    $GK = $DX
    $QP = 0
    EndIf
    $Winkel = (ATan($GK / $AK) * $RadToDeg)+$QP

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

    If $Winkel <> $Winkel_akt Then
    _GDIPlus_GraphicsClear($hBuffer, $GUIColorBG)
    _GDIPlus_GraphicsDrawLineWithAngle($hBuffer, 50, 50, 0, 0, 0, -40, $Winkel, $Zeiger)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, 100, 100)
    $Winkel_akt = $Winkel
    EndIf
    WEnd

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

    Func _GDIPlus_GraphicsDrawLineWithAngle($hGraphics, $iX_Rotate, $iY_Rotate, $iX_Point1, $iY_Point1, $iX_Point2, $iY_Point2, $iAngle, $hPen = 0)
    _GDIPlus_GraphicsTranslateTransform($hGraphics, $iX_Rotate, $iY_Rotate)
    _GDIPlus_GraphicsRotateTransform($hGraphics, $iAngle)
    _GDIPlus_GraphicsDrawLine($hGraphics, $iX_Point1, $iY_Point1, $iX_Point2, $iY_Point2, $hPen)
    _GDIPlus_GraphicsResetTransform($hGraphics)
    EndFunc ;==>_GDIPlus_GraphicsDrawLineWithAngle

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

    Func _exit()
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_GraphicsDispose($hBuffer)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_PenDispose($Zeiger)
    _GDIPlus_Shutdown()
    Exit
    EndFunc ;==>_Exit

    [/autoit]
    UNPLEASANT SPOILER

    You just lost the game!