-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGDIPHelper.ahk
156 lines (113 loc) · 4 KB
/
GDIPHelper.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
GDIP_JustTheBasics() {
global
; Start gdi+
If !GDIP_pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
ExitApp
}
OnExit, Exit
return
Exit:
; gdi+ may now be shutdown on exiting the program
Gdip_Shutdown(GDIP_pToken)
ExitApp
Return
}
GDIP_SetUp(width=-1, height=-1, posX=0, posY=0) {
global
; Flag for indicating when we are drawing (only applicable in this Helper)
GDIP_IsDrawing := false
; Setting up position and size
if( width<0 || height<0 ){
SysGet, GDIP_MonitorNum, MonitorCount
GDIP_TopLeftPoint := {}
GDIP_TopLeftPoint.x := 0
GDIP_TopLeftPoint.y := 0
Loop, %GDIP_MonitorNum%
{
SysGet, GDIP_MonitorBorderPos, Monitor, %A_Index%
if(GDIP_MonitorBorderPosLeft <= GDIP_TopLeftPoint.x)
GDIP_TopLeftPoint.x := GDIP_MonitorBorderPosLeft
if(GDIP_MonitorBorderPosTop <= GDIP_TopLeftPoint.y)
GDIP_TopLeftPoint.y := GDIP_MonitorBorderPosTop
}
SysGet, GDIP_FullWidth, 78
SysGet, GDIP_FullHeight, 79
GDIP_width := GDIP_FullWidth
GDIP_height := GDIP_FullHeight
GDIP_posX := GDIP_TopLeftPoint.x
GDIP_posY := GDIP_TopLeftPoint.y
} else{
GDIP_width := width
GDIP_height := height
GDIP_posX := posX
GDIP_posY := posY
}
GDIP_JustTheBasics()
; Create a layered window (+E0x80000 : must be used for UpdateLayeredWindow to work!) that is always on top (+AlwaysOnTop), has no taskbar entry or caption
Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs
; Hide the window when not being used, to avoid interfering with some applications due to its always on top nature
Gui, 1: Show, Hide
; Get a handle to this window we have created in order to update it later
GDIP_hwnd := WinExist()
return
}
GDIP_StartDraw() {
global
; Nothing to do when already drawing
if(GDIP_IsDrawing){
return
}
; Show the window when drawing
Gui, 1: Show, NA
; Create a gdi bitmap with width and height of what we are going to draw into it. This is the entire drawing area for everything
GDIP_BitmapHandle := CreateDIBSection(GDIP_width, GDIP_height)
; Get a device context compatible with the screen
GDIP_DeviceContextHandle := CreateCompatibleDC()
; Select the bitmap into the device context
GDIP_BitmapObject := SelectObject(GDIP_DeviceContextHandle, GDIP_BitmapHandle)
; Get a pointer to the graphics of the bitmap, for use with drawing functions
GDIP_Graphics := Gdip_GraphicsFromHDC(GDIP_DeviceContextHandle)
; Indicate that we are drawing
GDIP_IsDrawing := true
}
GDIP_EndDraw() {
global
; Nothing to do when already not drawing
if(!GDIP_IsDrawing){
return
}
; Hide the window when not being used, to avoid interfering with some applications due to its always on top nature
Gui, 1: Show, Hide
; Update the specified window we have created (GDIP_hwnd) with a handle to our bitmap (GDIP_DeviceContextHandle), specifying the x,y,w,h we want it positioned on our screen
; So this will position our gui at (GDIP_posX,GDIP_posY) with the Width and Height specified earlier
UpdateLayeredWindow(GDIP_hwnd, GDIP_DeviceContextHandle, GDIP_posX, GDIP_posY, GDIP_width, GDIP_height)
; Select the object back into the GDIP_DeviceContextHandle
SelectObject(GDIP_DeviceContextHandle, GDIP_BitmapObject)
; Now the bitmap may be deleted
DeleteObject(GDIP_BitmapHandle)
; Also the device context related to the bitmap may be deleted
DeleteDC(GDIP_DeviceContextHandle)
; The graphics may now be deleted
Gdip_DeleteGraphics(GDIP_Graphics)
; Indicate that we are drawing
GDIP_IsDrawing := false
}
GDIP_Clean() {
global
Gdip_GraphicsClear(GDIP_Graphics)
}
GDIP_Update(){
global
UpdateLayeredWindow(GDIP_hwnd, GDIP_DeviceContextHandle, GDIP_posX, GDIP_posY, GDIP_width, GDIP_height)
}
; The axis should be "x" or "y"
GDIP_DesktopPos(screenPos, axis){
global
if(axis == "x")
return -GDIP_TopLeftPoint.x + screenPos
if(axis == "y")
return -GDIP_TopLeftPoint.y + screenPos
Throw "Wrong axis value. It should be either 'x' or 'y', but it is: '" . axis . "'"
}