StrokesPlus.net Forum
»
General Discussion
»
General Discussion
»
Active the explorer or notepad as the window before minimized
Rank: Advanced Member
Groups: Moderators, Approved Joined: 4/23/2020(UTC) Posts: 161 Thanks: 46 times Was thanked: 23 time(s) in 17 post(s)
|
No matter whether I use the TidyTabs that a program to group the same program such as the explorer or notepad in one window like Chrome tabs, it will auto change to the next one when I active the window that is minimized. I don't know whether it is a case for me. I use the following script to keep the window as before minimized when active by an action. And there is no special name for the explorer to recognize except ClassName, but the window that gets from ClassName seems not in an array. Code:var hCMD = sp.WindowFromClassOrTitle('CabinetWClass', '');
var wnds = sp.AllApplications();
var apps = new Array();
for(var i = 0, len = wnds.Length; i < len; i++) {
if(wnds[i].ClassName == "CabinetWClass") {
apps.push(wnds[i]);
}
}
if (hCMD !== null){
var num = apps.length - 1;
sp.WindowsFromTitlePartial(apps[num].Title).First().Activate();;
}else{
sp.SendModifiedVKeys([vk.LWIN], [vk.VK_E]);
}
Code:var wnd = sp.WindowsFromTitlePartial("- notepad");
if(wnd.Count() === 0) {
sp.RunOrActivate('notepad.exe');
} else {
wnd[wnd.Length-1].Activate();
wnd[wnd.Length-1].BringToFront();
}
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,359 Location: Tampa, FL Thanks: 28 times Was thanked: 419 time(s) in 356 post(s)
|
Yeah, WindowFromClassOrTitle is simply a wrapper for FindWindowA - which only returns the first. You're right that you need to enumerate all windows. WindowsFromTitlePartial just enumerates all windows and does regex on each title - so there's really no difference in S+ doing it or you calling AllApplications and looping through.
|
1 user thanked Rob for this useful post.
|
|
|
Rank: Advanced Member
Groups: Moderators, Approved Joined: 4/23/2020(UTC) Posts: 161 Thanks: 46 times Was thanked: 23 time(s) in 17 post(s)
|
Thank you Rob for your explanation.
The strange is that the active Window is not the one before minimized and I don’t find it these years.
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,359 Location: Tampa, FL Thanks: 28 times Was thanked: 419 time(s) in 356 post(s)
|
Do you have Always Activate Window Where Gesture Began checked under Options > General?
That will activate the window below the mouse before your script executes.
|
|
|
|
Rank: Advanced Member
Groups: Moderators, Approved Joined: 4/23/2020(UTC) Posts: 161 Thanks: 46 times Was thanked: 23 time(s) in 17 post(s)
|
It shows chenked.
It is more and more strange, and I set Three Hotkeys to active Chrome, Explorer, and Notepad.
If I minimize the Explorer or Notepad, use the normal wnd.First().Activate() will show the next Window of that, but it is normal if I don't minimize the Window, just active Chrome and then active that Window directly.
So if I use the script I post to change the .length-1 index Window, the first is normal, but the second will show the previous Window. HAHAHAHA.
Never mind it.
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,359 Location: Tampa, FL Thanks: 28 times Was thanked: 419 time(s) in 356 post(s)
|
So AllApplications and WindowsFromTitlePartial both use the EnumWindows API call. Generally speaking, the order in which the window handles are returned is in Z-order, starting from the top-most (usually the active) window down the the bottom-most (oldest app that has been activated). See this post for some in-depth discussions on the topic. Meaning, the order of the array will change as different windows are activated, constantly moving the active window to the top [0] and the last application (alt+tab) becoming [1], then downward after that. Hopefully this helps to understand why you could be having unexpected or confusing results! This script below is a refactored version of yours, simplifying the logic and reducing the calls to EnumWindows. Code:var wnds = sp.AllApplications()
.Where(x => x.ClassName == "CabinetWClass")
.ToList();
// Just to debug, so you can see current window order of Explorer windows
for(var i = 0, len = wnds.Count; i < len; i++) {
StrokesPlus.Console.Log(`${wnds[i].ClassName} - ${wnds[i].Title}`);
}
if(wnds.Count > 0) {
wnds.First().Activate(); // Can also use Last: wnds.Last().Activate();
} else {
sp.SendModifiedVKeys([vk.LWIN], [vk.VK_E]);
}
Edited by user Saturday, February 12, 2022 3:17:31 AM(UTC)
| Reason: Not specified
|
1 user thanked Rob for this useful post.
|
|
|
Rank: Advanced Member
Groups: Moderators, Approved Joined: 4/23/2020(UTC) Posts: 161 Thanks: 46 times Was thanked: 23 time(s) in 17 post(s)
|
After many attempts, I find an effective way is to get the Title of the Explorer Window before minimizing it, then activate it by the stored Title. Also, thank you for your advanced code. I get the Title in the minimize script. Code:sp.StoreString('title', sp.WindowFromPoint(sp.GetCurrentMousePoint(), true).Title);
Code:var hCMD = sp.WindowFromClassOrTitle('CabinetWClass', '');
if (hCMD !== null){
if(hCMD.Minimized) {
sp.WindowsFromTitlePartial(sp.GetStoredString('title')).First().Activate();
} else {
hCMD.Activate();
hCMD.BringToFront();
}
}else{
sp.SendModifiedVKeys([vk.LWIN], [vk.VK_E]);
}
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,359 Location: Tampa, FL Thanks: 28 times Was thanked: 419 time(s) in 356 post(s)
|
You can also just store the actual window object itself, so you don't have to try to find it again by title - it will be a direct reference to that window. Code:// In minimize
sp.StoreObject("minWindow", sp.WindowFromPoint(sp.GetCurrentMousePoint(), true));
// Later code
sp.GetStoredObject("minWindow").Activate();
Not really much different, but just so you're aware :)
|
1 user thanked Rob for this useful post.
|
|
|
StrokesPlus.net Forum
»
General Discussion
»
General Discussion
»
Active the explorer or notepad as the window before minimized
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.
Important Information:
The StrokesPlus.net Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close