Jump to content

Do a mouse bounce like dvd bounce screen


KenKen
 Share

Recommended Posts

#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
; #include <WinAPISysWin.au3>
#include <WinAPI.au3>
HotKeySet("{ESC}", "_Exit")
Global $hGUI, $iWidth, $iHeight
example()

Func example()
    Local $sFileImage = @TempDir & "\logo.png"
    Local $sImageURL = "https://logodix.com/logo/1059815.png"
    Local $x = 10, $y = 10, $xDirection = 3, $yDirection = 3, $aPos
    If Not FileExists($sFileImage) Then InetGet($sImageURL, $sFileImage)
    _SetImage($x, $y, $sFileImage)
    ; FileDelete($sFileImage)

    While 1
        $aPos = WinGetPos($hGUI)
        $x = $aPos[0]
        $y = $aPos[1]
        If $x + $iWidth > @DesktopWidth Then
            $x = @DesktopWidth - $iWidth
            $xDirection *= -1
        EndIf
        If $x < 0 Then
            $x = 0
            $xDirection *= -1
        EndIf
        If $y + $iHeight > @DesktopHeight Then
            $y = @DesktopHeight - $iHeight
            $yDirection *= -1
        EndIf
        If $y < 0 Then
            $y = 0
            $yDirection *= -1
        EndIf
        $x += $xDirection
        $y += $yDirection
        WinMove($hGUI, '', $x, $y)
        Sleep(10)
    WEnd
    FileDelete($sFileImage)
EndFunc   ;==>example

Func _SetImage($Left, $Top, $Picture, $iOpacity = 255)
    _GDIPlus_Startup()
    Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
    Local $hImage = _GDIPlus_ImageLoadFromFile($Picture)
    $iWidth = _GDIPlus_ImageGetWidth($hImage)
    $iHeight = _GDIPlus_ImageGetHeight($hImage)
    $hGUI = GUICreate('', $iWidth, $iHeight, $Left, $Top, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
    Local $hLabel = GUICtrlCreateLabel('', 0, 0, $iWidth, $iHeight, -1, $GUI_WS_EX_PARENTDRAG)
    GUISetState(@SW_SHOW, $hGUI)
    $hScrDC = _WinAPI_GetDC(0)
    $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", $iWidth)
    DllStructSetData($tSize, "Y", $iHeight)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", 1)
    _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteDC($hMemDC)
    _GDIPlus_Shutdown()
    Return $hGUI
EndFunc   ;==>_SetImage

Func _Exit()
    If WinActive("[ACTIVE]") = $hGUI Then Exit
EndFunc   ;==>_Exit

 

Edited by Chimp
removed FileDelete()

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...