/
HWND-Displayer.lua
252 lines (220 loc) · 9.98 KB
/
HWND-Displayer.lua
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
--[[
################################################################################
#
# Copyright (c) 2014-2019 Ultraschall (http://ultraschall.fm)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
################################################################################
]]
-- written by Meo Mespotine mespotine.de 2nd of June 2019
-- for the ultraschall.fm-project
-- MIT-licensed
-- opens an overlay-window, which displays and draws the position of child-HWNDs of the currently focused window
-- use up/down to browse through them
-- left makes the overlay-window small; right makes it fullscreen
-- f - switches to the currently focused window
-- a - autofocuses on the currently focused window
-- p - pinpoints the window underneath the mousecursor
-- h - toggles help
-- PgUp/PgDn - browse through childHWNDs in steps of 10
-- Home/End - first or last childHWND
-- Backspace - go to parent hwnd
-- Enter - switch to current childHWND as mainHWND, whose childHWNDs you want to browse through
-- Ctrl+C - copies hwnd-information into clipboard
-- +/- adjust the alpha-channel of the transparency of the overlay-window
-- Esc - escapes this app
-- good for analysing the HWND-structure of Reaper
dofile(reaper.GetResourcePath().."/UserPlugins/ultraschall_api.lua")
if ultraschall==nil then reaper.MB("Needs Ultraschall-API installed! Go to ultraschall.fm/api to get it.", "Ultraschall-API missing", 0) return end
pause=false
autofocus=false
pinpoint=false
help=true
scleft, sctop, scright, scbottom = reaper.my_getViewport(0,0,0,0,0,0,0,0,true)
Parent=""
HWND={}
HWND_indexer={}
hwnd=reaper.JS_Window_GetFocus()
if reaper.JS_Window_GetParent(hwnd)~=nil then hwnd=reaper.JS_Window_GetParent(hwnd) end
Focus=hwnd
OldFocus=hwnd
HWND_indexer[reaper.JS_Window_AddressFromHandle(hwnd)]=1
retval, OwnHWND=ultraschall.GFX_Init("Tudelu", scright-10, scbottom-30,0,0,0)
gfx.setfont(1, "Arial", 20, 0)
Maxcount=0
alpha=0.7
Counter=1
reaper.JS_Window_SetOpacity(OwnHWND, "ALPHA", alpha)
Oretval, Oleft, Otop, Oright, Obottom = reaper.JS_Window_GetRect(OwnHWND)
Oretval2, Oleft2, Otop2, Oright2, Obottom2 = reaper.JS_Window_GetClientRect(OwnHWND)
--Offset=Obottom2-Obottom
Offset=Otop2-Otop
Offsetx=Oleft2-Oleft-2
if Offset<0 then Offset=Offset*-1 end
function updatelist(hwnd2)
-- if reaper.JS_Window_GetParent(hwnd)==nil then return end
if hwnd==nil or reaper.JS_Window_ListAllChild(hwnd2)==nil then return end
--[[ if HWND[Counter]~=nil then
HWND_indexer[reaper.JS_Window_AddressFromHandle(HWND[Counter])]=Counter
P3=reaper.JS_Window_AddressFromHandle(HWND[Counter])
end
--]]
HWND={}
HWND["Parent"]=reaper.JS_Window_GetParent(hwnd2)
HWND[0]=hwnd2
Counter=0
Maxcount=0
if reaper.JS_Window_ListAllChild(hwnd2)<1 then return end
Cretval, Clist = reaper.JS_Window_ListAllChild(hwnd2)
Clist=Clist..","
local counter=0
for k in string.gmatch(Clist, "(.-),") do
counter=counter+1
HWND[counter]=reaper.JS_Window_HandleFromAddress(k)
end
--[[
temphwnd2=reaper.JS_Window_AddressFromHandle(hwnd2)
if HWND_indexer[HWND[0] ]~=nil then
P0=HWND_indexer[temphwnd2]
P1=temphwnd2
Counter=P0
else
P0=-1
P1=-1
Counter=1
end
--]]
-- Counter=1
Maxcount=counter
end
updatelist(hwnd)
--gfx.quit()
function main()
if ultraschall.IsValidHWND(hwnd)==false then hwnd=reaper.GetMainHwnd() end
Focus=reaper.JS_Window_GetFocus()
if Focus==OwnHWND or Focus==nil then
Focus=OldFocus
end
if OldFocus~=Focus then
if autofocus==true then
hwnd=Focus
updatelist(Focus)
end
end
OldFocus=Focus
if pinpoint==true then
newhwnd=reaper.JS_Window_FromPoint(reaper.GetMousePosition())
if newhwnd~=nil then
hwnd=newhwnd
updatelist(hwnd)
end
end
Key=gfx.getchar()
if Key==8 then hwnd2=reaper.JS_Window_GetParent(hwnd) if hwnd2~=nil then hwnd=hwnd2 updatelist(hwnd) end end
--if Key~=0 then print3(Key) end
if Maxcount>0 and Key==1685026670.0 then Counter=Counter+1 if Counter>Maxcount then Counter=Maxcount end end
if Maxcount>0 and Key==30064.0 then Counter=Counter-1 if Counter<0 then Counter=0 end end
if Key==13 then hwnd=HWND[Counter] updatelist(HWND[Counter]) end
if Key==102.0 and ultraschall.IsValidHWND(reaper.JS_Window_GetParent(Focus))==true then hwnd=reaper.JS_Window_GetParent(Focus) updatelist(reaper.JS_Window_GetParent(Focus)) end
if Counter==0 then Parent="(Parent)" else Parent="" end
if Key==43.0 then alpha=alpha+0.02 if alpha>1 then alpha=1 end reaper.JS_Window_SetOpacity(OwnHWND, "ALPHA", alpha) end
if Key==45.0 then alpha=alpha-0.02 if alpha<0 then alpha=0 end reaper.JS_Window_SetOpacity(OwnHWND, "ALPHA", alpha) end
if Key==27.0 then quitit=true gfx.quit() end
if Key==1818584692.0 then reaper.JS_Window_Resize(OwnHWND, 300, 500) end
if Key==1919379572.0 then reaper.JS_Window_SetPosition(OwnHWND, 0,0,scright, scbottom) end
if Key==6647396.0 then Counter=Maxcount end
if Key==1752132965.0 then Counter=0 end
if Key==1885824110.0 then Counter=Counter+10 if Counter>Maxcount then Counter=Maxcount end end
if Key==1885828464.0 then Counter=Counter-10 if Counter<0 then Counter=0 end end
if Key==104.0 then if help~=true then help=true else help=false end end
if Key==97.0 then if autofocus~=true then autofocus=true pinpoint=false else autofocus=false end end
if Key==112.0 then if pinpoint~=true then pinpoint=true autofocus=false else pinpoint=false end end
-- if Maxcount>0 then
P=tostring(HWND[Counter])
ID=reaper.JS_Window_GetLongPtr(HWND[Counter], "ID")
if ID~=nil then ID=math.floor(reaper.JS_Window_AddressFromHandle(ID)) else ID="" end
ChildClass=reaper.JS_Window_GetClassName(HWND[Counter], "")
if ChildClass==nil then ChildClass="" end
retval, left, top, right, bottom = reaper.JS_Window_GetRect(HWND[Counter])
left, top = gfx.screentoclient(left, top+Offset)
right, bottom = gfx.screentoclient(right, bottom+Offset)
gfx.set(0,0,0,0.8)
gfx.rect(1+left-Offsetx,1+top-Offset,right-left,bottom-top,0)
gfx.set(1,1,1,0.8)
gfx.rect(left-Offsetx,top-Offset,right-left,bottom-top,0)
gfx.set(1,1,0,0.8)
gfx.line(left-Offsetx,top-Offset,right-Offsetx,bottom-Offset,0)
gfx.set(1,1,1,0.8)
gfx.x=1
gfx.y=1
Title0=reaper.JS_Window_GetTitle(hwnd)
Title=reaper.JS_Window_GetTitle(HWND[Counter])
ParentID=reaper.JS_Window_GetLongPtr(hwnd, "ID")
if ParentID~=nil then ParentID=math.floor(reaper.JS_Window_AddressFromHandle(ParentID)) else ParentID="" end
if Title0:len()>100 then Title0=Title0:sub(1,256).." ... " end
if Title:len()>100 then Title=Title:sub(1,256).." ... " end
gfx.drawstr(Title0.." - ParentID: "..ParentID..
" \nCounter: "..Counter.."/"..Maxcount.." - "..
Title..Parent..
" \nChildClass:"..ChildClass..
" \nID:"..ID..
" \nHas Children:"..
reaper.JS_Window_ListAllChild(HWND[Counter]))
if Key==3.0 then print3(Title0..
" \nCounter: "..Counter.."/"..Maxcount.." - "..
Title..Parent..
" \nChildClass:"..ChildClass..
" \nID:"..ID..
" \nHas Children:"..
reaper.JS_Window_ListAllChild(HWND[Counter])) end
if help~=false then
gfx.x=1
gfx.y=150
gfx.drawstr([[How to use it:
h - toggle this help
Up/Down - change Child-HWND
Enter - browse childHWNDs of currently selected childHWND
BackSpace - change to parentHWND
F - browse childHWNDs of keyboard-focused window
+/- - change opacity of this overlay window
left/right - minimize/maximize this overlay window
PgUp/PgDn - change up/down 10 Child-HWNDs
Home/End - first/last ChildHwnd
Ctrl+C - copies hwnd-information to clipboard
a(]]..tostring(autofocus)..[[) - toggles autofocus, which automatically uses the currently focused window
p(]]..tostring(pinpoint)..[[) - shows the window underneath the mouse-cursor
Esc - quit hwnd-inspector
]])
end
--[[ print_update(reaper.JS_Window_GetTitle(hwnd)..
" \nCounter: "..Counter.."/"..Maxcount.." - "..
reaper.JS_Window_GetTitle(HWND[Counter])..Parent..
" \nChildClass:"..ChildClass..
" \nID:"..ID..
" \nHas Children:"..
reaper.JS_Window_ListAllChild(HWND[Counter]))
--]]
--end
gfx.update()
if quitit~=true and Key~=-1 then reaper.defer(main) end
end
main()
--]]
--gfx.quit()