-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathShowGif().ahk
79 lines (74 loc) · 3.41 KB
/
ShowGif().ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* Example Code
VarSetCapacity(GdiplusStartupInput,3*A_PtrSize,0),NumPut(1,GdiplusStartupInput ,0,"UInt")
GdiplusStartup(getvar(token:=0), &GdiplusStartupInput, 0)
k:=GuiCreate()
f:=showGif(k.hwnd,"D:\float\Synch\Picture\92e8647agy1fcmebv0skdg20aw0cdx6q.gif")
k.show("w" f.width " h" f.height)
MsgBox "destroy gif"
f:=""
return
*/
showGif(hwnd,img:="",w:="",h:="",x:=0,y:=0){
if A_EventInfo
{
KillTimer(0,w)
if isobject((this:=object(A_EventInfo))) and isobject(this.gui)
{
t:=ahktime(),GdipImageSelectActiveFrame(this.pBitmap,this.ad,id:=this.id++)
,GdipDrawImageRectRectI(this.G,this.pBitmap,0,0,this.width,this.height,0,0,this.gifWidth,this.gifHeight,2)
,UpdateLayeredWindow(this.hwnd,0,this.pt[],getvar(temp1:=this.width|this.height<<32),this.hdc, getvar(temp2:=0),0,getvar(temp3:=255<<16|1<<24),2)
,this.st:=SetTimer_(0,0,Abs(this.delay[id]- (ahktime(t)*1000)),this.rc)
if this.id=this.count
this.id:=0
}
} else if isobject(hwnd)
{
f:=hwnd,KillTimer(0,f.st),(f.delete("gui").Destroy())
GlobalFree(f.rc),SelectObject(f.hdc, f.obm)
DeleteObject(f.hbm),DeleteDC(f.hdc),GdipDeleteGraphics(f.G),GdipDisposeImage(f.pBitmap)
}
else
{
this:={gui:gui:=GuiCreate("+E0x80000 +Parent" hwnd),id:1,x:x,y:y,Base:{__Delete: Func("showGif")},pt:pt:=Struct("x,y"),hwnd:gui.hwnd},gui.show("x" x " y" y)
GdipCreateBitmapFromFile(&img,getvar(pBitmap:=0))
GdipGetImageDimension(pBitmap,__w:=getvar(width:=0), __h:=getvar(height:=0))
this.gifwidth:=width:=NumGet(__w,"Float"),this.gifheight:=height:=NumGet(__h,"Float")
this.width:=w?w:width,this.height:=h?h:height,VarSetCapacity(bi, 40, 0)
,NumPut(this.width,bi,4),NumPut(this.height,bi,8),NumPut(40, bi, 0),NumPut(1,bi,12,"ushort"),NumPut(0, bi, 16),NumPut(32, bi, 14, "ushort")
this.hbm:=hbm := CreateDIBSection( hdc:=GetDC(), &bi),ReleaseDC(0,hdc)
this.hdc:=hdc := CreateCompatibleDC(),this.obm :=obm := SelectObject(hdc, hbm)
GdipCreateFromHDC(hdc,getvar(G:=0)),GdipSetInterpolationMode(this.G:=G, 7)
GdipImageGetFrameDimensionsCount(pBitmap,getvar(frameDimensions:=0))
this.SetCapacity("dimensionIDs", 32)
GdipImageGetFrameDimensionsList(pBitmap,this.ad:=this.GetAddress("dimensionIDs"), frameDimensions)
GdipImageGetFrameCount(pBitmap,this.ad,getvar(count:=0))
this.pBitmap:=pBitmap,this.count:=count,this.hdc:=hdc
GdipGetPropertyItemSize(pBitmap, 0x5100, getvar(ItemSize:=0))
VarSetCapacity(Item, ItemSize,0)
GdipGetPropertyItem(pBitmap,0x5100, ItemSize, &Item)
PropLen := NumGet(Item, 4,"UInt"),PropVal := NumGet(Item, 8 + A_PtrSize, "UPtr")
this.delay :=r := [],pt.x:=this.x,pt.y:=this.y
Loop PropLen//4
r[A_Index-1] := (n := NumGet(PropVal+0, (A_Index-1)*4, "UInt"))?n * 10:100
GdipImageSelectActiveFrame(pBitmap,this.ad,0)
GdipDrawImageRectRectI(G,pBitmap,0,0,this.width,this.height,0,0,width,height,2)
UpdateLayeredWindow(this.hwnd,0,pt[],getvar(temp1:=this.width|this.height<<32),this.hdc, getvar(temp2:=0),0,getvar(temp3:=255<<16|1<<24),2)
this.rc := RegisterCallback("showGif","F",4,&this)
this.st := SetTimer_(0,0,Abs(this.delay[0]),this.rc)
return this
}
}
ahkTime(s:=0,i:=6){
static r:=(DllCall("QueryPerformanceFrequency",Int64P,r),r)
DllCall("QueryPerformanceCounter",Int64P,n)
if !i
{
p:=s/1000*r,n2:=n,c:=A_IsCritical,Critical("on")
if s>15
sleep(((s-5)//15)*15)
while ((n2-n)<p)
DllCall("QueryPerformanceCounter", "Int64P", n2)
Return (Critical("c"),Round((n2-n)/r, 6))
}
Return (s ? Round((n-s)/r, i) : n)
}