StrokesPlus Forum
                       
StrokesPlus Forum
Home | Profile | Register | Active Topics
Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Feature Updates
 New Features
 [ADDED] acGetAllWindows()
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Rob

USA
2605 Posts

Posted - 01/29/2013 :  06:44:45  Show Profile  Visit Rob's Homepage  Reply with Quote
Added in 2.6.0:

acGetAllWindows([0 or 1]) action which populates a global table (created in C++, not by you) named sp_all_windows. This allows you to loop through the table and do whatever you'd like. For example, you want an action which finds all windows of a certain title/class/EXE and does something with them. Passing 1 only returns top-level desktop windows (usually what you'll want to do), passing 0 returns ALL window handles (a lot); for example, I had 5 programs open, passing 1 returns 5 results consisting of just the main window handles for each app. Passing 0 returned a table of 380 handles! Remember, each button, text box, etc. is considered a window and gets a handle. I'm certain there will be apps which use weird hidden windows as the owner and might be incorrectly represented in a top-level request, but that should be very rare.

Example script (only gets top-level windows):
acGetAllWindows(1)
for num, handle in pairs(sp_all_windows) do 
	local sMsg = "EXE: "..acGetExecutableName(handle,0,0)
	sMsg = sMsg.."\nClass: "..acGetClassName(handle,0,0)
	sMsg = sMsg.."\nTitle: "..acGetWindowTitle(handle,0,0)
	acMessageBox(sMsg,"Index: "..num,nil)
end
Note that this function only considers desktop top-level windows, not Win 8 Metro apps; you'd need to pass 0 and work through that yourself...not that there's much use I can think of for this functionality in dealing with Metro apps.

boombyte

Croatia
18 Posts

Posted - 02/25/2013 :  16:13:27  Show Profile  Reply with Quote
Thank you Rob, this is great! I can finally find and activate toplevel windows without cmdow and it's much faster and simpler this way. Also you provided a way to list all hidden windows and that is something I really needed! You're really making S+ into a powerful tool.
Using this action I can circumvent default behavior of some applications (for example show hidden Outlook window without clicking the tray icon), but this is where something else comes to mind (again ). I would really like to force some apps to hide instead of minimizing to taskbar (Skype, for example). Would it be possible to add something like acHideWindow? Or maybe there's another way you could point me to?
Go to Top of Page

Rob

USA
2605 Posts

Posted - 02/25/2013 :  16:24:43  Show Profile  Visit Rob's Homepage  Reply with Quote
I haven't tested the exact snippets below, but should get you going:

Global Lua:
--the following two lines if user32 not already initialized
aliencore = alien.core
user32 = aliencore.load("user32.dll")

SW_FORCEMINIMIZE = 11 --Minimize (force)
SW_HIDE = 0 --Hide
SW_MAXIMIZE = 3 --Maximize
SW_MINIMIZE = 6 --Minimize
SW_RESTORE = 9 --Restore
SW_SHOW = 5 --Activate and show
SW_SHOWDEFAULT = 10 --Sets the show state based on the SW_ value 
                    --specified in the STARTUPINFO structure passed 
                    --to the CreateProcess function by the program 
                    --that started the application.
SW_SHOWMAXIMIZED = 3 --Activates the window and displays it as a maximized window.
SW_SHOWMINIMIZED = 2 --Activates the window and displays it as a minimized window.
SW_SHOWMINNOACTIVE = 7 --Displays the window as a minimized window. (doesn't activate)
SW_SHOWNA = 8 --Show (no activate)
SW_SHOWNOACTIVATE = 4 --Show (no activate)
SW_SHOWNORMAL = 1 --Show normal

gShowWindow = user32.ShowWindow
gShowWindow:types{ ret = 'int', abi = 'stdcall', 'long', 'int' }

function aShowWindow(iWnd, iStyle)
	return gShowWindow(iWnd, iStyle)
end
Action:
aShowWindow(HandleHere, SW_HIDE)
Go to Top of Page

boombyte

Croatia
18 Posts

Posted - 02/26/2013 :  07:02:27  Show Profile  Reply with Quote
Perfect! Works great! Thank you for a lightning fast reply, as usual! ;)
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
StrokesPlus Forum © 2011-2018 Rob Yapchanyk Go To Top Of Page
Snitz Forums 2000