Code: Select all
SetBatchLines, -1
filePath := A_ScriptDir . "\Asus ROG logo.png"
if !FileExist(filePath)
URLDownloadToFile, https://www.autohotkey.com/boards/download/file.php?id=7738&sid=0f8912e745b2ee776d94be4553372ad7, % filePath
view := new ImageViewer
x := w := 0
y := A_ScreenHeight/2.2
Loop {
i := A_Index
view.Show(filePath, x += A_Index, y, w += i**1.3, -1)
Sleep, 10
} until w > 800
Sleep 1200
WinGetPos, x, y, w, h, % "ahk_id" view.hwnd
Loop 30 {
view.Show(filePath, x + mod(A_Index, 2)*2, y + mod(A_Index, 2)*2, w, h)
Sleep, 50
}
Loop {
view.Show(filePath, x += A_Index**2.5, y -= A_Index*4, w -= (i - A_Index)**1.4, -1)
Sleep, 30
} until w < 2 || i - A_Index < 2
view := ""
ExitApp
class ImageViewer
{
__New() {
static exStyles := "E" . (WS_EX_LAYERED := 0x80000) | (WS_EX_TRANSPARENT := 0x20)
Gui, New, -Caption +%exStyles% +LastFound +AlwaysOnTop +ToolWindow +hwndhGui -DPIScale
Gui, Show, NA
this.hwnd := hGui
}
__Delete() {
Gui, % this.hwnd . ": Destroy"
}
Show(imageFilePath, x := "", y := "", w := "", h := "") {
oGDIP := new GDIp
if !pBitmap := oGDIP.BitmapFromFile(imageFilePath) {
oGDIP := ""
throw Exception("Failed to get bitmap from file")
}
oGDIP.GetImageDimensions(pBitmap, width, height)
, ( w = -1 && w := width * h / height )
, ( h = -1 && h := height * w / width )
, ( w = "" && w := width)
, ( h = "" && h := height )
, ( x = "" && x := (A_ScreenWidth - w)//2 )
, ( y = "" && y := (A_ScreenHeight - h)//2 )
, oCDC := new this.CompatibleDC(0, w, h)
, hDC := oCDC.hCDC
, G := oGDIP.GraphicsFromHDC(hDC)
, oGDIP.SetSmoothingMode(G, 4)
, oGDIP.DrawImage(G, pBitmap, 0, 0, w, h, 0, 0, width, height)
, oGDIP.UpdateLayeredWindow(this.hwnd, hDC, x, y, w, h)
, oCDC := ""
, oGDIP.DeleteGraphics(G)
, oGDIP.DisposeImage(pBitmap)
}
class CompatibleDC
{
__New(hDC, w, h) {
this.hCDC := DllCall("CreateCompatibleDC", Ptr, hDC, Ptr)
, this.hBM := this.CreateDibSection(w, h, this.hCDC)
, this.oBM := DllCall("SelectObject", Ptr, this.hCDC, Ptr, this.hBM, Ptr)
}
__Delete() {
DllCall("SelectObject", Ptr, this.hCDC, Ptr, this.oBM, Ptr)
, DllCall("DeleteDC", Ptr, this.hCDC)
, DllCall("DeleteObject", Ptr, this.hBM)
}
CreateDibSection(w, h, hdc, bpp := 32, ByRef ppvBits := 0) {
VarSetCapacity(bi, 40, 0)
, NumPut(w, bi, 4, "UInt")
, NumPut(h, bi, 8, "UInt")
, NumPut(40, bi, 0, "UInt")
, NumPut(1, bi, 12, "ushort")
, NumPut(0, bi, 16, "uInt")
, NumPut(bpp, bi, 14, "ushort")
Return hbm := DllCall("CreateDIBSection", Ptr, hdc, Ptr, &bi, UInt, 0, PtrP, ppvBits, Ptr, 0, UInt, 0, Ptr)
}
}
}
class GDIp {
__New() {
if !DllCall("GetModuleHandle", Str, "gdiplus", Ptr)
DllCall("LoadLibrary", Str, "gdiplus")
VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1)
, DllCall("gdiplus\GdiplusStartup", UPtrP, pToken, Ptr, &si, Ptr, 0)
, this.token := pToken
}
__Delete() {
DllCall("gdiplus\GdiplusShutdown", Ptr, this.token)
if hModule := DllCall("GetModuleHandle", Str, "gdiplus", Ptr)
DllCall("FreeLibrary", Ptr, hModule)
}
BitmapFromFile(sFile) {
DllCall("gdiplus\GdipCreateBitmapFromFile", WStr, sFile, PtrP, pBitmap)
Return pBitmap
}
GraphicsFromHDC(hdc) {
DllCall("gdiplus\GdipCreateFromHDC", Ptr, hdc, PtrP, pGraphics)
return pGraphics
}
SetSmoothingMode(pGraphics, SmoothingMode) {
return DllCall("gdiplus\GdipSetSmoothingMode", Ptr, pGraphics, Int, SmoothingMode)
}
DrawImage(pGraphics, pBitmap, dx, dy, dw, dh, sx, sy, sw, sh) {
DllCall("gdiplus\GdipDrawImageRectRect", Ptr, pGraphics, Ptr, pBitmap
, Float, dx, Float, dy, Float, dw, Float, dh
, Float, sx, Float, sy, Float, sw, Float, sh
, Int, 2, Ptr, 0, Ptr, 0, Ptr, 0)
}
GetImageDimensions(pBitmap, ByRef Width, ByRef Height) {
DllCall("gdiplus\GdipGetImageWidth", Ptr, pBitmap, UIntP, Width)
, DllCall("gdiplus\GdipGetImageHeight", Ptr, pBitmap, UIntP, Height)
}
UpdateLayeredWindow(hwnd, hdc, x, y, w, h, Alpha := 255) {
VarSetCapacity(pt, 8)
, NumPut(x, pt, 0, "UInt")
, NumPut(y, pt, 4, "UInt")
return DllCall("UpdateLayeredWindow", Ptr, hwnd, Ptr, 0, Ptr, &pt, Int64P, w|h<<32
, Ptr, hdc, Int64P, 0, UInt, 0, UIntP, Alpha<<16|1<<24, UInt, 2)
}
DisposeImage(pBitmap) {
return DllCall("gdiplus\GdipDisposeImage", Ptr, pBitmap)
}
DeleteGraphics(pGraphics) {
return DllCall("gdiplus\GdipDeleteGraphics", Ptr, pGraphics)
}
}
External libraries are not required.