Author |
Topic |
|
Rob
USA
2615 Posts |
Posted - 05/18/2012 : 15:32:54
|
This Lua script will tell you if a window is visible or not (checks the WS_VISIBLE style):
It's a little messy, but should be easy enough to follow and make it do what you want!
local xortbl = { { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, }, { 1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, }, { 2, 3, 0, 1, 6, 7, 4, 5, 10, 11, 8, 9, 14, 15, 12, 13, }, { 3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12, }, { 4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11, }, { 5, 4, 7, 6, 1, 0, 3, 2, 13, 12, 15, 14, 9, 8, 11, 10, }, { 6, 7, 4, 5, 2, 3, 0, 1, 14, 15, 12, 13, 10, 11, 8, 9, }, { 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8, }, { 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, }, { 9, 8, 11, 10, 13, 12, 15, 14, 1, 0, 3, 2, 5, 4, 7, 6, }, {10, 11, 8, 9, 14, 15, 12, 13, 2, 3, 0, 1, 6, 7, 4, 5, }, {11, 10, 9, 8, 15, 14, 13, 12, 3, 2, 1, 0, 7, 6, 5, 4, }, {12, 13, 14, 15, 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3, }, {13, 12, 15, 14, 9, 8, 11, 10, 5, 4, 7, 6, 1, 0, 3, 2, }, {14, 15, 12, 13, 10, 11, 8, 9, 6, 7, 4, 5, 2, 3, 0, 1, }, {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, }, }
function bxor(a,b) local res, mult = 0, 1 while a > 0 and b > 0 do local a2, b2 = a % 16, b % 16 res = res + xortbl[a2+1][b2+1] * mult a = (a-a2) / 16 b = (b-b2) / 16 mult = mult * 16 end res = res + (a+b) * mult return res end
function band(a,b) return ((a+b) - bxor(a,b))/2 end
local alien = alien.core local mb = alien.load("user32.dll") local GetWindowLong = mb.GetWindowLongA GetWindowLong:types{ ret = 'uint', abi = 'stdcall', 'long', 'long'}
acRunProgram("c:\\windows\\notepad.exe","",0, 0) acMessageBox("notepad opened HIDDEN, click OK to check VISIBLE status","",nil)
local hWnd = acFindWindowByTitleRegex(".*Notepad")
if hWnd > 0 then local iStyles = GetWindowLong(hWnd, -16) if band(iStyles,268435456) == 268435456 then acMessageBox("Window is Visible (killing notepad after you click OK)","Visible?",nil) else acMessageBox("Window is NOT Visible (killing notepad after you click OK)","Visible?",nil) end acCloseApplication(hWnd, nil, nil) end
acRunProgram("c:\\windows\\notepad.exe","",0, 1) acDelay(200)
hWnd = acFindWindowByTitleRegex(".*Notepad") if hWnd > 0 then local iStyles = GetWindowLong(hWnd, -16) acActivateWindow(hWnd, nil, nil) acMessageBox("notepad opened VISIBLE, click OK to check VISIBLE status","",nil) if band(iStyles,268435456) == 268435456 then acMessageBox("Window is Visible (killing notepad after you click OK)","Visible?",nil) else acMessageBox("Window is NOT Visible (killing notepad after you click OK)","Visible?",nil) end acCloseApplication(hWnd, nil, nil) end |
|
Rob
USA
2615 Posts |
|
Rob
USA
2615 Posts |
Posted - 05/18/2012 : 16:00:10
|
Ack, I had messed up a line, updated the script above. |
|
|
imafishimafish
USA
19 Posts |
Posted - 05/18/2012 : 17:26:24
|
Sweet badger soup! Thanks Rob! I'm new to Lua, so it was kind of a surprise that you were implementing home-grown bitwise operators. So I looked it up, and discovered that it wasn't until Lua 5.2 that it started shipping with the bit32 library. But S+ must be using Lua 5.2 because it looks like the bit32 library is available in S+. Anyway, here is what I came up with, in case anyone wants a similar function to get the style of a window.
New function in StrokesPlus.lua:
function spGetWinStyle(hwnd, x, y)
if hwnd == nil then hwnd = acGetOwnerWindowByPoint(x, y) end
local user32 = alien.core.load("user32.dll")
local GetWindowLong = user32.GetWindowLongA
GetWindowLong:types{ ret = 'uint', abi = 'stdcall', 'ulong', 'long'}
return GetWindowLong(hwnd, GWL_STYLE)
end
Lua Script for Action to toggle properties window in Visual Studio:
local hw = acFindWindow("VBFloatingPalette", "Properties")
if bit32.band(spGetWinStyle(hw, 0, 0, true), WS_VISIBLE) == WS_VISIBLE then
acSendMessage(hw, WM_CLOSE, 0, 0)
else
acSendKeys("%{ENTER}")
end
|
|
|
Rob
USA
2615 Posts |
Posted - 05/18/2012 : 17:59:46
|
Ah, yes it is 5.2, I try to keep Lua and Boost up-to-date.
Thanks for the info about the bit32 stuff. I don't really know anything about Lua, I just knew it would be good to have in there for times like these =) |
|
|
|
Topic |
|
|
|