Automatically Restore Last Window Position For Each Process

Post your working scripts, libraries and tools
brutus_skywalker
Posts: 179
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: Automatically Restore Last Window Position For Each Process

26 Mar 2018, 06:27

ovnis wrote:Hello Brutus,

Thx for your script, but there are problems.

There are issues with Taskmgr.exe and explorer.exe. Windows don't appear at the right place.


Edit: Fixed version on next post.
Last edited by brutus_skywalker on 27 Mar 2018, 02:40, edited 1 time in total.
Outsourcing Clicks & Presses Since 2004.
ovnis
Posts: 12
Joined: 25 Mar 2018, 13:40

Re: Automatically Restore Last Window Position For Each Process

26 Mar 2018, 12:55

Edit: you might alternatively try 'Title' based repositioning i added in my last edit to my version of the script,it might be more precise,at least for task manager.

But "Title_Filter" adds windows to the automatic window manager or the opposite ?

I use your last script. But with title filter, i don't figure out how to manage better explorer folder or the taskmanager.

Otherwise, is not possible to add a filter with whom "ahk_class #32770" or "ahk_class CabinetWClass" are automatically saved ?

One note, Firefox, Windows 10 mail haven't box. :)
brutus_skywalker
Posts: 179
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: Automatically Restore Last Window Position For Each Process

27 Mar 2018, 02:39

Edit: removed a bad post.
Last edited by brutus_skywalker on 27 Mar 2018, 07:35, edited 1 time in total.
Outsourcing Clicks & Presses Since 2004.
ovnis
Posts: 12
Joined: 25 Mar 2018, 13:40

Re: Automatically Restore Last Window Position For Each Process

27 Mar 2018, 05:38

Hi,

Same issue with taskmgr.exe et explorer.exe. OneNote, Windows mail doesn't work anymore.
brutus_skywalker
Posts: 179
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: Automatically Restore Last Window Position For Each Process

27 Mar 2018, 07:40

ovnis wrote:Hi,

Same issue with taskmgr.exe et explorer.exe. OneNote, Windows mail doesn't work anymore.


Yeah, my code got really tangled, with the original authors code,so i've decided to rewrite the concept with the simplicity that it implicitly should have,so i'll post it here when i have time, i reckon i can shrink it down to <50lines and actually make it readable. Cheers & sorry for my previous bad post. But if in the mean time my last code post should be more functional with just the taskmgr & explorer kinks...
Outsourcing Clicks & Presses Since 2004.
brutus_skywalker
Posts: 179
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: Automatically Restore Last Window Position For Each Process

29 Mar 2018, 12:31

Rewrote my version of the OP, it took more code than the 50 lines i was hoping for the rewrite, and even ended up being more than the original code, to make it easier to maintain, more efficient & easier to modify for anyone who wants to modify to their whims. It now uses ProcessName,ClassName,WindowStyle to uniquely identify windows, uses PID for window management sessions(move window on first run only), only saves position data from windows that are niether maximised nor minimised and idles until active window belongs to a managed process.

Recommend adding and removing managed processes using the default hotkey, Ctrl+Shift+Ins.

Known Issues:
    If explorer.exe is added as a managed process, ensure the class names saved to INI are of the actual explorer window, and not the start menu or such,which are also windows under explorer.exe...

    It uses first encounter window attributes to pair a window's attributes with a designated ManagedProcess,i.e if a process has a dialog box open when it's first encountered then that dialog box will be identified as the processes main window, so if that is the case, simply remove the INI entry and have it detect the window again or modify INI entry manually using the script provided below.

    NOT COMPATIBLE WITH Windows 10 Universal Windows Platform apps(ApplicationFrameHost.exe apps), TESTED ON WinXP/7/8/10.


Script to gather info about active window,to verfiy window identifiers in INI are the correct ones.

Code: [Select all] [Expand] [Download] (AutomaticWindowManager-v2-Helper.ahk)GeSHi © Codebox Plus



EDIT(FIXES):

    Now properly handles snapped windows,it didn't before.My Bad...

    Multimonitor compatible,at least it should be, i can't test it(single monitor setup) but logically code no longer has hardcoded boundries like it did before.

EDIT(FIXES):

    Added Hotkey 'Ctrl+Shift+Ins' to add or remove windows to managedProcesses list, easier and more precise addition of windows.
    >If window is already managed user will be prompted to remove managed processes, else user will be prompted to add active window to managed processes list.

    NOTE ON HOTKEY: hotkey neither adds nor removes to managedProcesses added manually to script, instead it only manages managedProcesses added by Hotkey,reasoning for this is simply a matter of personal preference, nothing more.

    Optimised core logic to make it more reliable and less likely to trigger unexpected outcomes.

FINAL EDIT:

    Now uses unique window ID's instead of PID to manage window management sessions, such that a process with multiple managed windows will have them all managed instead of only the very first one as was the case before. i.e new explorer windows for example under a single process(identical PID's) will now all be managed instead of only the very first explorer window,a very silly bug that's now squashed.


AutomaticWindowManager-v2-

Code: [Select all] [Expand] [Download] (AutomaticWindowManager-v2-.ahk)GeSHi © Codebox Plus

Last edited by brutus_skywalker on 12 Apr 2018, 04:20, edited 8 times in total.
Outsourcing Clicks & Presses Since 2004.
ovnis
Posts: 12
Joined: 25 Mar 2018, 13:40

Re: Automatically Restore Last Window Position For Each Process

29 Mar 2018, 17:17

Hello,

Thx for your code, but "AutomaticWindowManager-v2-" works not as good than previous scripts... Explorer.exe,taskmgr.exe,ApplicationFrameHost.exe (OneNote, Skype, Mail etc.) don't work.

notepad.exe behaviour is strange...

file.ahk doesen't work :error paramter #2 invalid
brutus_skywalker
Posts: 179
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: Automatically Restore Last Window Position For Each Process

29 Mar 2018, 23:59

ovnis wrote:Hello,

Thx for your code, but "AutomaticWindowManager-v2-" works not as good than previous scripts... Explorer.exe,taskmgr.exe,ApplicationFrameHost.exe (OneNote, Skype, Mail etc.) don't work.

notepad.exe behaviour is strange...

file.ahk doesen't work :error paramter #2 invalid


Fixed file.ahk, it was a typo from when i posted, as for explorer.exe & taskmgr.exe i tested them explicitly for about 2days, no issues on win7/8, and as for all applications that use ApplicationFrameHost.exe as parent exe, that is a given they won't work,there can only be one ini entry for a managed process(exe), and for those that don't such as notepad.exe i suggest you use the fixed 'file.ahk' to manually change classname & style in the .INI file,and check the log file next to the ini for more info on malfunctions.

Cheers.
Outsourcing Clicks & Presses Since 2004.
jeka
Posts: 8
Joined: 30 Mar 2018, 05:24

Re: Automatically Restore Last Window Position For Each Process

30 Mar 2018, 05:32

brutus_skywalker wrote:Rewrote my version of the OP, it took more code than the 50 lines i was hoping for the rewrite, and even ended up being more than the original code, to make it easier to maintain, more efficient & easier to modify for anyone who wants to modify to their whims. It now uses ProcessName,ClassName,WindowStyle to uniquely identify windows, uses PID for window management sessions(move window on first run only), only saves position data from windows that are niether maximised nor minimised and idles until active window belongs to a managed process.


I wonder why this script does not launch (I don't see AutoHotkey icon in the system tray). But file.ahk launches and works. Incidentally, the very first script from OP works, albeit with dialog boxes issue reported earlier.

I'm on Win7 64b Ultimate. Any ideas?
ovnis
Posts: 12
Joined: 25 Mar 2018, 13:40

Re: Automatically Restore Last Window Position For Each Process

30 Mar 2018, 06:33

for all applications that use ApplicationFrameHost.exe as parent exe, that is a given they won't work

I have some difficulty to understand you (the english is not my native language). Your last script will not work with Onenote, Mail and Skype ? If this is the case, your last script has strictly no interest for me. :(

as for explorer.exe & taskmgr.exe i tested them explicitly for about 2days, no issues on win7/8,

I only use Windows 10. And explorer.exe & taskmgr.exe don't work.
Last edited by ovnis on 30 Mar 2018, 07:42, edited 1 time in total.
ovnis
Posts: 12
Joined: 25 Mar 2018, 13:40

Re: Automatically Restore Last Window Position For Each Process

30 Mar 2018, 06:36

I wonder why this script does not launch (I don't see AutoHotkey icon in the system tray).

Because, I don't understand why but inside the script there is #NoTrayIcon. :)
jeka
Posts: 8
Joined: 30 Mar 2018, 05:24

Re: Automatically Restore Last Window Position For Each Process

30 Mar 2018, 07:48

ovnis wrote:
I wonder why this script does not launch (I don't see AutoHotkey icon in the system tray).

Because, I don't understand why but inside the script there is #NoTrayIcon. :)



I see. Thanks. Still, I don't see any effect of the script AutomaticWindowManager-v2, but the very AutomaticWindowManager script works.

Am I still missing something?
ovnis
Posts: 12
Joined: 25 Mar 2018, 13:40

Re: Automatically Restore Last Window Position For Each Process

30 Mar 2018, 09:54

Still, I don't see any effect of the script AutomaticWindowManager-v2,

Me too (and too much complicated for my use). For the moment I stay on the first script. His only issue is than I would prefer than the script manages only programs reported in an filter list. Actually it manages all programs, that can be an issue (box issue with programs which work without bug with the native Windows snaping/recall).
brutus_skywalker
Posts: 179
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: Automatically Restore Last Window Position For Each Process

30 Mar 2018, 10:58

So the -v2- rewrite does work, i disable tray icon as it's a preference of mine,given i run 50+ scripts on my system, i use https://autohotkey.com/board/topic/26153-ahkcontrol/ to manage my scripts,i've commented it out though,if it's important apparently.

Unlike the OP script, -v2- only manages processes added to 'managedProcesses' variable,hence you have to define the process that you want to add, i could add a hotkey but i think anyone who wants to can do that anyways, the point of the rewrite was to simply make this concept modular and easily modifiable without imposing my preference on others.

So in a nut shell if you want the -v2- version to manage any window, just add the exe of the process the window belongs to, to the managedProcesses variable which should be near the top of the script, it's this line:
managedProcesses = xulrunner.exe,firefox.exe,notepad.exe,chrome.exe,notepad++.exe,ProcessHacker.exe,Cmd.exe,mintty.exe,FoxitReader.exe,taskmgr.exe

As for windows 10, let me reiterate, anywindows that share the same executable as 'Universal Windows Apps' such as OneNote, Mail,... will not work in a desired manner, i.e It might save the position of a window in the 'OneNote' app but it'll use that position to resize & reposition the 'Mail' app as they share a class name, a parent exe & almost always window style. As such i don't recommend you use it in windows 10 with windows 10 exclusive apps, or any app from the windows store as it is a 'Universal Windows App', i simply don't know how to better clarify this matter.
Outsourcing Clicks & Presses Since 2004.
jeka
Posts: 8
Joined: 30 Mar 2018, 05:24

Re: Automatically Restore Last Window Position For Each Process

30 Mar 2018, 11:20

brutus_skywalker wrote:
So in a nut shell if you want the -v2- version to manage any window, just add the exe of the process the window belongs to, to the managedProcesses variable which should be near the top of the script, it's this line:
managedProcesses = xulrunner.exe,firefox.exe,notepad.exe,chrome.exe,notepad++.exe,ProcessHacker.exe,Cmd.exe,mintty.exe,FoxitReader.exe,taskmgr.exe



Ah, I see. Well, I see 'mintty.exe' in there already. However v2 script does not manage 'mintty.exe' for me. I also tried to add 'gvim.exe' to the var, which also does nothing. Any pointers? Btw, I used file.ahk to identify correctly process names.
jeka
Posts: 8
Joined: 30 Mar 2018, 05:24

Re: Automatically Restore Last Window Position For Each Process

30 Mar 2018, 11:28

Playing a bit more with v2, noticed that if I resize-reposition mintty.exe window in the main monitor, the position is remembered/restored. If I move mintty.exe to the secondary, then close and re-open, it opens up in the last position for the main monitor. Is this expected?
jeka
Posts: 8
Joined: 30 Mar 2018, 05:24

Re: Automatically Restore Last Window Position For Each Process

30 Mar 2018, 11:32

Update: the OP version works correctly across both displays.
jeka
Posts: 8
Joined: 30 Mar 2018, 05:24

Re: Automatically Restore Last Window Position For Each Process

30 Mar 2018, 11:35

Here's how WindowSizePosLog.ini looks after frist running v2 then OP, perhaps it will shed some light.

[managed processes]
mintty.exe=mintty.exe,451,1446,515,12,mintty,0x14EF0000
gvim.exe=gvim.exe,415,813,6,329,Vim,0x16CF0000
notepad.exe=notepad.exe,484,1099,21,73,Notepad,0x14CF0000
[Process Names]
Explorer.EXE=-2210,554,797,1099
gvim.exe=-2369,689,577,866
taskmgr.exe=-1146,856,710,498
chrome.exe=-2569,471,2578,1426
NOTEPAD.EXE=21,73,1083,1810
ovnis
Posts: 12
Joined: 25 Mar 2018, 13:40

Re: Automatically Restore Last Window Position For Each Process

30 Mar 2018, 12:03

Thx for yours explanations.

With your last version :
Notepad++.exe box ("Save file ?") is randomly buged (too much tiny) and there is no position recall at all (at snaping positions).
I don't know how manage explorer.exe. It seems to not to work :

Code: [Select all] [Download] GeSHi © Codebox Plus

managedProcesses = Explorer.exe

taskmgr.exe is not recalled very well. It doesn't feet exactly with the screen edges (when it was previously snapped).
When I snap notepad.exe the recall works only with the bottom right and bottom left corners. With the top right or top left corners or right or left cornes, the recall is buged.
Sometimes, Onenote, Skype & co doesn't recall.
Last edited by ovnis on 30 Mar 2018, 16:03, edited 1 time in total.
brutus_skywalker
Posts: 179
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: Automatically Restore Last Window Position For Each Process

30 Mar 2018, 15:52

jeka wrote:Playing a bit more with v2, noticed that if I resize-reposition mintty.exe window in the main monitor, the position is remembered/restored. If I move mintty.exe to the secondary, then close and re-open, it opens up in the last position for the main monitor. Is this expected?


EDIT: i updated -v2- post, try it now, let me know how it performs, i can't test it because i have a single monitor, but i removed the constraints that were logically causing the issue.

@ovnis:

Given your issues, i actually installed a win10 VM to test if your problems are accurate, as expected 'Universal Windows Platform Apps' didn't work as they should(OneNote,Mail..), however explorer,task manager & notepad worked with out fault,given their classnames & styles were accurate,& incase of explorer i had to use the 'file.ahk' to manually modify the classname & style for the explorer window,as expressed in my -v2- post,in the 'Known Issues' section. All i can say is check the log file, 'WindowSizePosLog.ini.LOG.log' to debug your issues and use 'file.ahk' to verify the classname & styles info in the ini is accurate.
And i do use Notepad++ to deal with all things text,so i can't account for your issues there,given i have none.

Cheers.
Outsourcing Clicks & Presses Since 2004.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 23 guests