Created
June 1, 2021 03:25
-
-
Save Jimbly/4bc001741a63ed8d7e8a144e870a0044 to your computer and use it in GitHub Desktop.
Modifying Window Styles in Automato
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dofile("common.inc"); | |
dofile("screen_reader_common.inc"); | |
dofile("ui_utils.inc"); | |
local styles = { | |
WS_BORDER=0x00800000, | |
WS_DLGFRAME=0x00400000, | |
-- WS_CAPTION=0x00C00000, WS_BORDER | WS_DLGFRAME | |
-- WS_CHILD=0x40000000, not relevant | |
WS_CLIPCHILDREN=0x02000000, | |
WS_CLIPSIBLINGS=0x04000000, | |
WS_DISABLED=0x08000000, | |
-- WS_HSCROLL=0x00100000, not relevant | |
WS_MAXIMIZE=0x01000000, | |
WS_MAXIMIZEBOX=0x00010000, | |
WS_MINIMIZE=0x20000000, | |
WS_MINIMIZEBOX=0x00020000, | |
WS_POPUP=0x80000000, | |
WS_SIZEBOX=0x00040000, | |
WS_SYSMENU=0x00080000, | |
-- WS_VISIBLE=0x10000000, not relevant | |
-- WS_VSCROLL=0x00200000, not relevant | |
}; | |
local exstyles = { | |
WS_EX_ACCEPTFILES=0x00000010, | |
WS_EX_APPWINDOW=0x00040000, | |
WS_EX_CLIENTEDGE=0x00000200, | |
WS_EX_COMPOSITED=0x02000000, | |
WS_EX_CONTEXTHELP=0x00000400, | |
WS_EX_CONTROLPARENT=0x00010000, | |
WS_EX_DLGMODALFRAME=0x00000001, | |
WS_EX_LAYERED=0x00080000, | |
WS_EX_LAYOUTRTL=0x00400000, | |
WS_EX_LEFT=0x00000000, | |
WS_EX_LEFTSCROLLBAR=0x00004000, | |
WS_EX_LTRREADING=0x00000000, | |
WS_EX_MDICHILD=0x00000040, | |
WS_EX_NOACTIVATE=0x08000000, | |
WS_EX_NOINHERITLAYOUT=0x00100000, | |
WS_EX_NOPARENTNOTIFY=0x00000004, | |
WS_EX_NOREDIRECTIONBITMAP=0x00200000, | |
WS_EX_RIGHT=0x00001000, | |
WS_EX_RIGHTSCROLLBAR=0x00000000, | |
WS_EX_RTLREADING=0x00002000, | |
WS_EX_STATICEDGE=0x00020000, | |
WS_EX_TOOLWINDOW=0x00000080, | |
WS_EX_TOPMOST=0x00000008, | |
WS_EX_TRANSPARENT=0x00000020, | |
WS_EX_WINDOWEDGE=0x00000100, | |
-- WS_EX_OVERLAPPEDWINDOW = (WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE) | |
-- WS_EX_PALETTEWINDOW = (WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST) | |
}; | |
-- sort by value for UI | |
local function sortedTable(map) | |
local map_sorted = {}; | |
for k,v in pairs(map) do map_sorted[#map_sorted+1] = v end | |
table.sort(map_sorted) | |
for i=1,#map_sorted do | |
for k,v in pairs(map) do | |
if v == map_sorted[i] then | |
map_sorted[i] = k; | |
end | |
end | |
end | |
return map_sorted; | |
end | |
local styles_sorted = sortedTable(styles); | |
local exstyles_sorted = sortedTable(exstyles); | |
local composite = { | |
Regular=0x16cf0000, | |
Maximized=0x17cf0000, | |
WindowedFullscreen=0x96000000, | |
}; | |
function doit() | |
askForWindow(""); | |
local z = 0.0; | |
while not lsButtonText(lsScreenX - 110, lsScreenY - 30, z, 100, 0xFFFFFFff, "Done") do | |
-- Put these everywhere to make sure we don't lock up with no easy way to escape! | |
checkBreak(); | |
local style = srWindowGetStyle(); | |
local y = 10; | |
local scale = 1.0; | |
y = y + lsPrintWrapped(10, y, z, lsScreenX - 20, scale, scale, 0xFFFFFFff, "Window Style: " .. string.format("%08x", style)); | |
scale = 0.5; | |
local line_h = 13; | |
for idx=1,#styles_sorted do | |
local k = styles_sorted[idx]; | |
local v = styles[k]; | |
local clicked = lsMouseClick(20, y, lsScreenX, line_h); | |
local over = clicked or lsMouseOver(20, y, lsScreenX, line_h); | |
if not ((style & v) == 0) then | |
local color = 0xFFFFFFff; | |
if (over) then | |
color = 0x80FF80ff; | |
end | |
lsPrintWrapped(20, y, z, lsScreenX - 20, scale, scale, color, k); | |
if clicked then | |
srWindowSetStyle(style & ~v); | |
end | |
else | |
local color = 0x800000ff; | |
if (over) then | |
color = 0xFF8080ff; | |
end | |
lsPrintWrapped(20, y, z, lsScreenX - 20, scale, scale, color, k); | |
if clicked then | |
srWindowSetStyle(style | v); | |
end | |
end | |
y = y + line_h; | |
end | |
scale = 1.0; | |
local cat = 'Unknown'; | |
for k, v in pairs(composite) do | |
if (v == style) then | |
cat = k; | |
end | |
end | |
y = y + lsPrintWrapped(10, y, z, lsScreenX - 20, scale, scale, 0xFFFFFFff, "State Guess: " .. cat); | |
-- If fullscreen windowed or maximized, button to switch to the readable equivalent | |
if cat == 'Maximized' then | |
if lsButtonText(10, y, z, 150, 0xFFFFFFff, "Remove caption") then | |
srWindowSetStyle(0x170b0000); -- style & ~0x00C00000); -- Remove WS_CAPTION | |
end | |
end | |
-- Doesn't work reliably | |
if cat == 'WindowedFullscreen' then | |
if lsButtonText(10, y, z, 150, 0xFFFFFFff, "Fake fullscreen") then | |
--srWindowSetStyle(0x170B0000); | |
srWindowSetStyleEx(srWindowGetStyleEx() | 0x00080000); | |
end | |
end | |
y = y + 32; | |
style = srWindowGetStyleEx(); | |
scale = 1.0; | |
y = y + lsPrintWrapped(10, y, z, lsScreenX - 20, scale, scale, 0xFFFFFFff, "Window StyleEx: " .. string.format("%08x", style)); | |
scale = 0.5; | |
local line_h = 13; | |
for idx=1,#exstyles_sorted do | |
local k = exstyles_sorted[idx]; | |
local v = exstyles[k]; | |
local clicked = lsMouseClick(20, y, lsScreenX, line_h); | |
local over = clicked or lsMouseOver(20, y, lsScreenX, line_h); | |
if not ((style & v) == 0) then | |
local color = 0xFFFFFFff; | |
if (over) then | |
color = 0x80FF80ff; | |
end | |
lsPrintWrapped(20, y, z, lsScreenX - 20, scale, scale, color, k); | |
if clicked then | |
srWindowSetStyleEx(style & ~v); | |
end | |
else | |
local color = 0x800000ff; | |
if (over) then | |
color = 0xFF8080ff; | |
end | |
lsPrintWrapped(20, y, z, lsScreenX - 20, scale, scale, color, k); | |
if clicked then | |
srWindowSetStyleEx(style | v); | |
end | |
end | |
y = y + line_h; | |
end | |
lsDoFrame(); | |
lsSleep(10); -- Sleep just so we don't eat up all the CPU for no reason | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment