Remember window locations when docked and undocked
I find this beyond frustrating.
I have two extra screens on my laptop at work. I take my laptop and go home, with no extra screens connected. I come back, dock the laptop, and the windows need to be rearranged again.
Is there a way to get windows (or a utility) to keep track of the overall screen configuration (#, size, resolution), and remember where windows were placed, so when the screen configuration matches again, it puts applications BACK where they were?
windows-7 multiple-monitors
add a comment |
I find this beyond frustrating.
I have two extra screens on my laptop at work. I take my laptop and go home, with no extra screens connected. I come back, dock the laptop, and the windows need to be rearranged again.
Is there a way to get windows (or a utility) to keep track of the overall screen configuration (#, size, resolution), and remember where windows were placed, so when the screen configuration matches again, it puts applications BACK where they were?
windows-7 multiple-monitors
I run into the same issue but my complaint is when I open the laptop later and the application window is still off-screen (end up using the arrow keys to move it back onscreen). I don't think there is a built-in solution to this.
– Brad Patton
May 10 '13 at 0:38
add a comment |
I find this beyond frustrating.
I have two extra screens on my laptop at work. I take my laptop and go home, with no extra screens connected. I come back, dock the laptop, and the windows need to be rearranged again.
Is there a way to get windows (or a utility) to keep track of the overall screen configuration (#, size, resolution), and remember where windows were placed, so when the screen configuration matches again, it puts applications BACK where they were?
windows-7 multiple-monitors
I find this beyond frustrating.
I have two extra screens on my laptop at work. I take my laptop and go home, with no extra screens connected. I come back, dock the laptop, and the windows need to be rearranged again.
Is there a way to get windows (or a utility) to keep track of the overall screen configuration (#, size, resolution), and remember where windows were placed, so when the screen configuration matches again, it puts applications BACK where they were?
windows-7 multiple-monitors
windows-7 multiple-monitors
edited Apr 20 '15 at 8:36
Montag451
6371827
6371827
asked May 9 '13 at 21:58
CaffGeek
3051519
3051519
I run into the same issue but my complaint is when I open the laptop later and the application window is still off-screen (end up using the arrow keys to move it back onscreen). I don't think there is a built-in solution to this.
– Brad Patton
May 10 '13 at 0:38
add a comment |
I run into the same issue but my complaint is when I open the laptop later and the application window is still off-screen (end up using the arrow keys to move it back onscreen). I don't think there is a built-in solution to this.
– Brad Patton
May 10 '13 at 0:38
I run into the same issue but my complaint is when I open the laptop later and the application window is still off-screen (end up using the arrow keys to move it back onscreen). I don't think there is a built-in solution to this.
– Brad Patton
May 10 '13 at 0:38
I run into the same issue but my complaint is when I open the laptop later and the application window is still off-screen (end up using the arrow keys to move it back onscreen). I don't think there is a built-in solution to this.
– Brad Patton
May 10 '13 at 0:38
add a comment |
7 Answers
7
active
oldest
votes
I'm currently using DisplayFusion Pro for window location (not only). I don't know how this works when you disconnect and connect your monitor - I have three always.
I think, that you must close and reopen your apps to be re-arranged.
Edit: This is feature is available only in Pro version. - Information from comments.
homepage of DisplayFusion
2
FYI, the Window Location feature appears to solve my request. It should be noted to anyone else that this is a PRO version requiring a purchased license.
– MADCookie
Oct 7 '14 at 19:35
See the "Save or Restore all window locations" feature in the Feature Comparison for Free vs. Pro. Unfortunately the cheapest solution is $25.
– Chiramisu
Jan 19 '17 at 20:47
1
Does this work when you have multiple native virtual desktops in Windows 10?
– K Robinson
Jan 9 at 19:19
add a comment |
The problem is that Windows applications don't really see multiple monitors. The window manager keeps track of window positions in reference to the Top-Left corner or your main display. I'm not aware of any commercial applications that do, but you could write an application in C# or even VB.NET that could write these values to a file and restore them later, but there would be no "trigger" for it. You'd have to tell the program when to store and retrieve the data manually.
add a comment |
Try this script, written for Excel. It stores the window positions in a sheet and restores them from there. You may have buttons on one of the sheets to run the store and restore macros, or shortcuts to VBS scripts that run the Excel macros, maybe with shortcut keys assigned. That way the Excel workbook can remain minimized. Of course something similar may be written in a compiled program.
Public Declare PtrSafe Function GetWindowPlacement Lib "user32" (ByVal hwnd As LongPtr, lpwndpl As WINDOWPLACEMENT) As Long
Public Declare PtrSafe Function SetWindowPlacement Lib "user32" (ByVal hwnd As LongPtr, lpwndpl As WINDOWPLACEMENT) As Long
Public Declare PtrSafe Function GetWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare PtrSafe Function IsWindowVisible Lib "user32.dll" (ByVal hwnd As Long) As Boolean
Public Declare PtrSafe Function GetParent Lib "user32.dll" (ByVal hwnd As Long) As Long
Public Declare PtrSafe Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As LongPtr, ByVal lpString As String, ByVal cch As LongPtr) As Long
Public Type POINTAPI
X As Long
Y As Long
End Type
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Type WINDOWPLACEMENT
Length As Long
flags As Long
showCmd As Long
MinPosition As POINTAPI
MaxPosition As POINTAPI
rcNormalPosition As RECT
End Type
Global Const gw_hwndnext = 2
Global Const fwp_startswith = 0
Global Const fwp_contains = 1
Global title As String
Global Visible As Boolean
Global RowCount
Public prog As String
Public Sub StoreActiveWindows()
Dim hwndapp As Long
Dim hwndmax As Long
Dim nret As Long
Dim WinFrm As WINDOWPLACEMENT
Dim RectFrm As RECT
PleaseWait.Show vbModeless
DoEvents
RowCount = 1
hwndmax = findwindow(0&, 0&)
Do Until hwndmax = 0
hwndapp = findthiswindow(hwndmax)
If hwndapp Then
If title <> "CURRENT WINDOWS OPEN" And Visible Then
rtn = GetWindowPlacement(hwndapp, WinFrm)
RectFrm = WinFrm.rcNormalPosition
FrmTop = RectFrm.Top
FrmRight = RectFrm.Right
FrmLeft = RectFrm.Left
FrmBottom = RectFrm.Bottom
Workbooks(Filename).Activate
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 1) = title
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 2) = hwndapp
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 3) = FrmTop
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 4) = FrmRight
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 5) = FrmLeft
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 6) = FrmBottom
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 7) = WinFrm.MaxPosition.X
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 8) = WinFrm.MaxPosition.Y
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 9) = WinFrm.MinPosition.X
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 10) = WinFrm.MinPosition.Y
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 11) = WinFrm.showCmd
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 12) = WinFrm.flags
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 13) = WinFrm.Length
RowCount = RowCount + 1
End If
End If
hwndmax = GetWindow(hwndmax, gw_hwndnext)
Loop
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 1) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 2) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 3) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 4) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 5) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 6) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 7) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 8) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 9) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 10) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 11) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 12) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 13) = ""
Unload PleaseWait
End Sub
Public Function findthiswindow(ByVal hwndtopmost As Long) As Long
Dim hwndtmp As Long
Dim nret As Long
Dim titletmp As String
'Get the first window
hwndtmp = hwndtopmost
If GetParent(hwndtmp) = 0 Then
'Set its visibility
If IsWindowVisible(hwndtmp) Then
Visible = True
Else
Visible = False
End If
'Get its title
titletmp = Space(256)
nret = GetWindowText(hwndtmp, titletmp, Len(titletmp))
If nret Then
findthiswindow = hwndtmp
End If
End If
If Visible Then
title = titletmp & " - Visible"
Else
title = titletmp & " - Invisible"
End If
title = titletmp
If titletmp <> "" Then
'If title = "SETTINGS" Then
HasNoOWner = Not (GetWindow(hwndtmp, 4))
n = 1
'End If
If (UCase(Left(title, 15)) = "PROGRAM MANAGER" Or UCase(title) = "SETTINGS") Then
n = 1
title = ""
findthiswindow = 0
End If
End If
End Function
Sub RestoreWindowsLocations()
Dim WinFrm As WINDOWPLACEMENT
Dim RectFrm As RECT
PleaseWait.Show vbModeless
DoEvents
Workbooks(Filename).Activate
RowCount = 1
Do Until Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 1) = ""
hwndapp = Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 2)
' rtn = GetWindowPlacement(hwndapp, WinFrm)
WinFrm.rcNormalPosition.Top = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 3))
WinFrm.rcNormalPosition.Right = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 4))
WinFrm.rcNormalPosition.Left = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 5))
WinFrm.rcNormalPosition.Bottom = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 6))
WinFrm.MaxPosition.X = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 7))
WinFrm.MaxPosition.Y = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 8))
WinFrm.MinPosition.X = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 9))
WinFrm.MinPosition.Y = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 10))
WinFrm.showCmd = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 11))
WinFrm.flags = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 12))
WinFrm.Length = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 13))
rtn = SetWindowPlacement(hwndapp, WinFrm)
rtn = SetWindowPlacement(hwndapp, WinFrm)
RowCount = RowCount + 1
Loop
Unload PleaseWait
End Sub
Please explain what this is supposed to do and clean up and format the entire code block properly as it's hard to read as-is.
– Pimp Juice IT
Aug 4 '17 at 4:42
And can you explain how to have VBS scripts that run the Excel macros? How can something similar be written into a compiled program?
– G-Man
Aug 4 '17 at 5:43
This is an interesting approach. Have you yourself uses it? I am sure a lot of people would benefit if you can create an end-to-end working sample
– Miserable Variable
Feb 1 at 16:43
add a comment |
DISCLAIMER: I'm the creator of this tool.
I've created a little tool to rearrange windows on a traybar icon click.
You may compile it from source or ask to have a (portable) binary through the issues link.
It is hosted at Github: https://github.com/manutalcual/winredock
I would be glad to hear from you if you have suggestions.
EDIT: 2018/11/22
It is fully automated now.
This looks nice but I am looking for something more automatic.
– Mr Universe
Oct 30 at 1:24
1
I've added the automation feature due to user requests.
– Manuel
Nov 22 at 15:35
add a comment |
I've used Stardock’s Fences before in a similar scenario:
Fences helps you organize your PC by automatically placing your
shortcuts and icons into resizable shaded areas on your desktop called
fences. Its many customization features are what make Fences the
world's most popular Windows desktop enhancement.
7
That arranges icons. Not windows. My issue is that I have 8 programs open across three screens. When I close the laptop, and re-open it with the three screens all my application windows are open on one screen, not arranged how I had them.
– CaffGeek
May 10 '13 at 13:17
add a comment |
Alot of windows users had this issue, an application was developed and shared within the windows 7 forums as shown here:
http://www.sevenforums.com/free-developer-programs-projects/40916-shellfolderfix-manage-folder-window-positions-size.html#post396744
There are instructions on the site which help and it should fix your issue.
The forum says "This is an app to make Windows 7 explorer folder windows remember their size and position" and " It does NOT manage window size/positions of regular applications, if you want that, other apps like Window Manager do it". What is meant by Window Manager? Is that the Microsoft Windows Manager service or the product from DeskSoft link
– MADCookie
Oct 7 '14 at 19:26
yes it is the product from DeskSoft
– DarkEvE
Oct 7 '14 at 19:50
add a comment |
This one was looking promising: https://github.com/adamsmith/WindowsLayoutSnapshot
Unfortunately in my case, when saving the layout on 3x 24" 1920x1200 monitors, changing to one laptop 1920x1080, and then going back to three and trying to restore layout, windows didn't really move to other monitors. But maybe for someone else on other setup it will work.
Looks promising, but that won't run on my PC (Windows 8.1)
– Dunc
Jan 5 '17 at 12:09
Discontinued unfortunately, and it loses all the config when the program is closed or the PC is restarted, which the author doesn't plan to fix.
– this.lau_
Jun 24 '17 at 21:04
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f593701%2fremember-window-locations-when-docked-and-undocked%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
I'm currently using DisplayFusion Pro for window location (not only). I don't know how this works when you disconnect and connect your monitor - I have three always.
I think, that you must close and reopen your apps to be re-arranged.
Edit: This is feature is available only in Pro version. - Information from comments.
homepage of DisplayFusion
2
FYI, the Window Location feature appears to solve my request. It should be noted to anyone else that this is a PRO version requiring a purchased license.
– MADCookie
Oct 7 '14 at 19:35
See the "Save or Restore all window locations" feature in the Feature Comparison for Free vs. Pro. Unfortunately the cheapest solution is $25.
– Chiramisu
Jan 19 '17 at 20:47
1
Does this work when you have multiple native virtual desktops in Windows 10?
– K Robinson
Jan 9 at 19:19
add a comment |
I'm currently using DisplayFusion Pro for window location (not only). I don't know how this works when you disconnect and connect your monitor - I have three always.
I think, that you must close and reopen your apps to be re-arranged.
Edit: This is feature is available only in Pro version. - Information from comments.
homepage of DisplayFusion
2
FYI, the Window Location feature appears to solve my request. It should be noted to anyone else that this is a PRO version requiring a purchased license.
– MADCookie
Oct 7 '14 at 19:35
See the "Save or Restore all window locations" feature in the Feature Comparison for Free vs. Pro. Unfortunately the cheapest solution is $25.
– Chiramisu
Jan 19 '17 at 20:47
1
Does this work when you have multiple native virtual desktops in Windows 10?
– K Robinson
Jan 9 at 19:19
add a comment |
I'm currently using DisplayFusion Pro for window location (not only). I don't know how this works when you disconnect and connect your monitor - I have three always.
I think, that you must close and reopen your apps to be re-arranged.
Edit: This is feature is available only in Pro version. - Information from comments.
homepage of DisplayFusion
I'm currently using DisplayFusion Pro for window location (not only). I don't know how this works when you disconnect and connect your monitor - I have three always.
I think, that you must close and reopen your apps to be re-arranged.
Edit: This is feature is available only in Pro version. - Information from comments.
homepage of DisplayFusion
edited Feb 16 at 7:52
answered Oct 7 '14 at 13:23
Wild_A
20124
20124
2
FYI, the Window Location feature appears to solve my request. It should be noted to anyone else that this is a PRO version requiring a purchased license.
– MADCookie
Oct 7 '14 at 19:35
See the "Save or Restore all window locations" feature in the Feature Comparison for Free vs. Pro. Unfortunately the cheapest solution is $25.
– Chiramisu
Jan 19 '17 at 20:47
1
Does this work when you have multiple native virtual desktops in Windows 10?
– K Robinson
Jan 9 at 19:19
add a comment |
2
FYI, the Window Location feature appears to solve my request. It should be noted to anyone else that this is a PRO version requiring a purchased license.
– MADCookie
Oct 7 '14 at 19:35
See the "Save or Restore all window locations" feature in the Feature Comparison for Free vs. Pro. Unfortunately the cheapest solution is $25.
– Chiramisu
Jan 19 '17 at 20:47
1
Does this work when you have multiple native virtual desktops in Windows 10?
– K Robinson
Jan 9 at 19:19
2
2
FYI, the Window Location feature appears to solve my request. It should be noted to anyone else that this is a PRO version requiring a purchased license.
– MADCookie
Oct 7 '14 at 19:35
FYI, the Window Location feature appears to solve my request. It should be noted to anyone else that this is a PRO version requiring a purchased license.
– MADCookie
Oct 7 '14 at 19:35
See the "Save or Restore all window locations" feature in the Feature Comparison for Free vs. Pro. Unfortunately the cheapest solution is $25.
– Chiramisu
Jan 19 '17 at 20:47
See the "Save or Restore all window locations" feature in the Feature Comparison for Free vs. Pro. Unfortunately the cheapest solution is $25.
– Chiramisu
Jan 19 '17 at 20:47
1
1
Does this work when you have multiple native virtual desktops in Windows 10?
– K Robinson
Jan 9 at 19:19
Does this work when you have multiple native virtual desktops in Windows 10?
– K Robinson
Jan 9 at 19:19
add a comment |
The problem is that Windows applications don't really see multiple monitors. The window manager keeps track of window positions in reference to the Top-Left corner or your main display. I'm not aware of any commercial applications that do, but you could write an application in C# or even VB.NET that could write these values to a file and restore them later, but there would be no "trigger" for it. You'd have to tell the program when to store and retrieve the data manually.
add a comment |
The problem is that Windows applications don't really see multiple monitors. The window manager keeps track of window positions in reference to the Top-Left corner or your main display. I'm not aware of any commercial applications that do, but you could write an application in C# or even VB.NET that could write these values to a file and restore them later, but there would be no "trigger" for it. You'd have to tell the program when to store and retrieve the data manually.
add a comment |
The problem is that Windows applications don't really see multiple monitors. The window manager keeps track of window positions in reference to the Top-Left corner or your main display. I'm not aware of any commercial applications that do, but you could write an application in C# or even VB.NET that could write these values to a file and restore them later, but there would be no "trigger" for it. You'd have to tell the program when to store and retrieve the data manually.
The problem is that Windows applications don't really see multiple monitors. The window manager keeps track of window positions in reference to the Top-Left corner or your main display. I'm not aware of any commercial applications that do, but you could write an application in C# or even VB.NET that could write these values to a file and restore them later, but there would be no "trigger" for it. You'd have to tell the program when to store and retrieve the data manually.
answered Oct 6 '14 at 18:12
Mr. Mascaro
36518
36518
add a comment |
add a comment |
Try this script, written for Excel. It stores the window positions in a sheet and restores them from there. You may have buttons on one of the sheets to run the store and restore macros, or shortcuts to VBS scripts that run the Excel macros, maybe with shortcut keys assigned. That way the Excel workbook can remain minimized. Of course something similar may be written in a compiled program.
Public Declare PtrSafe Function GetWindowPlacement Lib "user32" (ByVal hwnd As LongPtr, lpwndpl As WINDOWPLACEMENT) As Long
Public Declare PtrSafe Function SetWindowPlacement Lib "user32" (ByVal hwnd As LongPtr, lpwndpl As WINDOWPLACEMENT) As Long
Public Declare PtrSafe Function GetWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare PtrSafe Function IsWindowVisible Lib "user32.dll" (ByVal hwnd As Long) As Boolean
Public Declare PtrSafe Function GetParent Lib "user32.dll" (ByVal hwnd As Long) As Long
Public Declare PtrSafe Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As LongPtr, ByVal lpString As String, ByVal cch As LongPtr) As Long
Public Type POINTAPI
X As Long
Y As Long
End Type
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Type WINDOWPLACEMENT
Length As Long
flags As Long
showCmd As Long
MinPosition As POINTAPI
MaxPosition As POINTAPI
rcNormalPosition As RECT
End Type
Global Const gw_hwndnext = 2
Global Const fwp_startswith = 0
Global Const fwp_contains = 1
Global title As String
Global Visible As Boolean
Global RowCount
Public prog As String
Public Sub StoreActiveWindows()
Dim hwndapp As Long
Dim hwndmax As Long
Dim nret As Long
Dim WinFrm As WINDOWPLACEMENT
Dim RectFrm As RECT
PleaseWait.Show vbModeless
DoEvents
RowCount = 1
hwndmax = findwindow(0&, 0&)
Do Until hwndmax = 0
hwndapp = findthiswindow(hwndmax)
If hwndapp Then
If title <> "CURRENT WINDOWS OPEN" And Visible Then
rtn = GetWindowPlacement(hwndapp, WinFrm)
RectFrm = WinFrm.rcNormalPosition
FrmTop = RectFrm.Top
FrmRight = RectFrm.Right
FrmLeft = RectFrm.Left
FrmBottom = RectFrm.Bottom
Workbooks(Filename).Activate
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 1) = title
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 2) = hwndapp
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 3) = FrmTop
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 4) = FrmRight
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 5) = FrmLeft
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 6) = FrmBottom
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 7) = WinFrm.MaxPosition.X
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 8) = WinFrm.MaxPosition.Y
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 9) = WinFrm.MinPosition.X
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 10) = WinFrm.MinPosition.Y
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 11) = WinFrm.showCmd
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 12) = WinFrm.flags
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 13) = WinFrm.Length
RowCount = RowCount + 1
End If
End If
hwndmax = GetWindow(hwndmax, gw_hwndnext)
Loop
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 1) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 2) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 3) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 4) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 5) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 6) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 7) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 8) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 9) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 10) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 11) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 12) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 13) = ""
Unload PleaseWait
End Sub
Public Function findthiswindow(ByVal hwndtopmost As Long) As Long
Dim hwndtmp As Long
Dim nret As Long
Dim titletmp As String
'Get the first window
hwndtmp = hwndtopmost
If GetParent(hwndtmp) = 0 Then
'Set its visibility
If IsWindowVisible(hwndtmp) Then
Visible = True
Else
Visible = False
End If
'Get its title
titletmp = Space(256)
nret = GetWindowText(hwndtmp, titletmp, Len(titletmp))
If nret Then
findthiswindow = hwndtmp
End If
End If
If Visible Then
title = titletmp & " - Visible"
Else
title = titletmp & " - Invisible"
End If
title = titletmp
If titletmp <> "" Then
'If title = "SETTINGS" Then
HasNoOWner = Not (GetWindow(hwndtmp, 4))
n = 1
'End If
If (UCase(Left(title, 15)) = "PROGRAM MANAGER" Or UCase(title) = "SETTINGS") Then
n = 1
title = ""
findthiswindow = 0
End If
End If
End Function
Sub RestoreWindowsLocations()
Dim WinFrm As WINDOWPLACEMENT
Dim RectFrm As RECT
PleaseWait.Show vbModeless
DoEvents
Workbooks(Filename).Activate
RowCount = 1
Do Until Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 1) = ""
hwndapp = Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 2)
' rtn = GetWindowPlacement(hwndapp, WinFrm)
WinFrm.rcNormalPosition.Top = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 3))
WinFrm.rcNormalPosition.Right = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 4))
WinFrm.rcNormalPosition.Left = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 5))
WinFrm.rcNormalPosition.Bottom = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 6))
WinFrm.MaxPosition.X = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 7))
WinFrm.MaxPosition.Y = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 8))
WinFrm.MinPosition.X = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 9))
WinFrm.MinPosition.Y = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 10))
WinFrm.showCmd = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 11))
WinFrm.flags = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 12))
WinFrm.Length = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 13))
rtn = SetWindowPlacement(hwndapp, WinFrm)
rtn = SetWindowPlacement(hwndapp, WinFrm)
RowCount = RowCount + 1
Loop
Unload PleaseWait
End Sub
Please explain what this is supposed to do and clean up and format the entire code block properly as it's hard to read as-is.
– Pimp Juice IT
Aug 4 '17 at 4:42
And can you explain how to have VBS scripts that run the Excel macros? How can something similar be written into a compiled program?
– G-Man
Aug 4 '17 at 5:43
This is an interesting approach. Have you yourself uses it? I am sure a lot of people would benefit if you can create an end-to-end working sample
– Miserable Variable
Feb 1 at 16:43
add a comment |
Try this script, written for Excel. It stores the window positions in a sheet and restores them from there. You may have buttons on one of the sheets to run the store and restore macros, or shortcuts to VBS scripts that run the Excel macros, maybe with shortcut keys assigned. That way the Excel workbook can remain minimized. Of course something similar may be written in a compiled program.
Public Declare PtrSafe Function GetWindowPlacement Lib "user32" (ByVal hwnd As LongPtr, lpwndpl As WINDOWPLACEMENT) As Long
Public Declare PtrSafe Function SetWindowPlacement Lib "user32" (ByVal hwnd As LongPtr, lpwndpl As WINDOWPLACEMENT) As Long
Public Declare PtrSafe Function GetWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare PtrSafe Function IsWindowVisible Lib "user32.dll" (ByVal hwnd As Long) As Boolean
Public Declare PtrSafe Function GetParent Lib "user32.dll" (ByVal hwnd As Long) As Long
Public Declare PtrSafe Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As LongPtr, ByVal lpString As String, ByVal cch As LongPtr) As Long
Public Type POINTAPI
X As Long
Y As Long
End Type
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Type WINDOWPLACEMENT
Length As Long
flags As Long
showCmd As Long
MinPosition As POINTAPI
MaxPosition As POINTAPI
rcNormalPosition As RECT
End Type
Global Const gw_hwndnext = 2
Global Const fwp_startswith = 0
Global Const fwp_contains = 1
Global title As String
Global Visible As Boolean
Global RowCount
Public prog As String
Public Sub StoreActiveWindows()
Dim hwndapp As Long
Dim hwndmax As Long
Dim nret As Long
Dim WinFrm As WINDOWPLACEMENT
Dim RectFrm As RECT
PleaseWait.Show vbModeless
DoEvents
RowCount = 1
hwndmax = findwindow(0&, 0&)
Do Until hwndmax = 0
hwndapp = findthiswindow(hwndmax)
If hwndapp Then
If title <> "CURRENT WINDOWS OPEN" And Visible Then
rtn = GetWindowPlacement(hwndapp, WinFrm)
RectFrm = WinFrm.rcNormalPosition
FrmTop = RectFrm.Top
FrmRight = RectFrm.Right
FrmLeft = RectFrm.Left
FrmBottom = RectFrm.Bottom
Workbooks(Filename).Activate
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 1) = title
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 2) = hwndapp
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 3) = FrmTop
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 4) = FrmRight
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 5) = FrmLeft
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 6) = FrmBottom
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 7) = WinFrm.MaxPosition.X
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 8) = WinFrm.MaxPosition.Y
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 9) = WinFrm.MinPosition.X
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 10) = WinFrm.MinPosition.Y
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 11) = WinFrm.showCmd
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 12) = WinFrm.flags
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 13) = WinFrm.Length
RowCount = RowCount + 1
End If
End If
hwndmax = GetWindow(hwndmax, gw_hwndnext)
Loop
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 1) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 2) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 3) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 4) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 5) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 6) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 7) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 8) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 9) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 10) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 11) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 12) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 13) = ""
Unload PleaseWait
End Sub
Public Function findthiswindow(ByVal hwndtopmost As Long) As Long
Dim hwndtmp As Long
Dim nret As Long
Dim titletmp As String
'Get the first window
hwndtmp = hwndtopmost
If GetParent(hwndtmp) = 0 Then
'Set its visibility
If IsWindowVisible(hwndtmp) Then
Visible = True
Else
Visible = False
End If
'Get its title
titletmp = Space(256)
nret = GetWindowText(hwndtmp, titletmp, Len(titletmp))
If nret Then
findthiswindow = hwndtmp
End If
End If
If Visible Then
title = titletmp & " - Visible"
Else
title = titletmp & " - Invisible"
End If
title = titletmp
If titletmp <> "" Then
'If title = "SETTINGS" Then
HasNoOWner = Not (GetWindow(hwndtmp, 4))
n = 1
'End If
If (UCase(Left(title, 15)) = "PROGRAM MANAGER" Or UCase(title) = "SETTINGS") Then
n = 1
title = ""
findthiswindow = 0
End If
End If
End Function
Sub RestoreWindowsLocations()
Dim WinFrm As WINDOWPLACEMENT
Dim RectFrm As RECT
PleaseWait.Show vbModeless
DoEvents
Workbooks(Filename).Activate
RowCount = 1
Do Until Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 1) = ""
hwndapp = Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 2)
' rtn = GetWindowPlacement(hwndapp, WinFrm)
WinFrm.rcNormalPosition.Top = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 3))
WinFrm.rcNormalPosition.Right = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 4))
WinFrm.rcNormalPosition.Left = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 5))
WinFrm.rcNormalPosition.Bottom = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 6))
WinFrm.MaxPosition.X = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 7))
WinFrm.MaxPosition.Y = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 8))
WinFrm.MinPosition.X = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 9))
WinFrm.MinPosition.Y = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 10))
WinFrm.showCmd = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 11))
WinFrm.flags = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 12))
WinFrm.Length = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 13))
rtn = SetWindowPlacement(hwndapp, WinFrm)
rtn = SetWindowPlacement(hwndapp, WinFrm)
RowCount = RowCount + 1
Loop
Unload PleaseWait
End Sub
Please explain what this is supposed to do and clean up and format the entire code block properly as it's hard to read as-is.
– Pimp Juice IT
Aug 4 '17 at 4:42
And can you explain how to have VBS scripts that run the Excel macros? How can something similar be written into a compiled program?
– G-Man
Aug 4 '17 at 5:43
This is an interesting approach. Have you yourself uses it? I am sure a lot of people would benefit if you can create an end-to-end working sample
– Miserable Variable
Feb 1 at 16:43
add a comment |
Try this script, written for Excel. It stores the window positions in a sheet and restores them from there. You may have buttons on one of the sheets to run the store and restore macros, or shortcuts to VBS scripts that run the Excel macros, maybe with shortcut keys assigned. That way the Excel workbook can remain minimized. Of course something similar may be written in a compiled program.
Public Declare PtrSafe Function GetWindowPlacement Lib "user32" (ByVal hwnd As LongPtr, lpwndpl As WINDOWPLACEMENT) As Long
Public Declare PtrSafe Function SetWindowPlacement Lib "user32" (ByVal hwnd As LongPtr, lpwndpl As WINDOWPLACEMENT) As Long
Public Declare PtrSafe Function GetWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare PtrSafe Function IsWindowVisible Lib "user32.dll" (ByVal hwnd As Long) As Boolean
Public Declare PtrSafe Function GetParent Lib "user32.dll" (ByVal hwnd As Long) As Long
Public Declare PtrSafe Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As LongPtr, ByVal lpString As String, ByVal cch As LongPtr) As Long
Public Type POINTAPI
X As Long
Y As Long
End Type
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Type WINDOWPLACEMENT
Length As Long
flags As Long
showCmd As Long
MinPosition As POINTAPI
MaxPosition As POINTAPI
rcNormalPosition As RECT
End Type
Global Const gw_hwndnext = 2
Global Const fwp_startswith = 0
Global Const fwp_contains = 1
Global title As String
Global Visible As Boolean
Global RowCount
Public prog As String
Public Sub StoreActiveWindows()
Dim hwndapp As Long
Dim hwndmax As Long
Dim nret As Long
Dim WinFrm As WINDOWPLACEMENT
Dim RectFrm As RECT
PleaseWait.Show vbModeless
DoEvents
RowCount = 1
hwndmax = findwindow(0&, 0&)
Do Until hwndmax = 0
hwndapp = findthiswindow(hwndmax)
If hwndapp Then
If title <> "CURRENT WINDOWS OPEN" And Visible Then
rtn = GetWindowPlacement(hwndapp, WinFrm)
RectFrm = WinFrm.rcNormalPosition
FrmTop = RectFrm.Top
FrmRight = RectFrm.Right
FrmLeft = RectFrm.Left
FrmBottom = RectFrm.Bottom
Workbooks(Filename).Activate
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 1) = title
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 2) = hwndapp
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 3) = FrmTop
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 4) = FrmRight
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 5) = FrmLeft
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 6) = FrmBottom
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 7) = WinFrm.MaxPosition.X
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 8) = WinFrm.MaxPosition.Y
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 9) = WinFrm.MinPosition.X
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 10) = WinFrm.MinPosition.Y
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 11) = WinFrm.showCmd
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 12) = WinFrm.flags
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 13) = WinFrm.Length
RowCount = RowCount + 1
End If
End If
hwndmax = GetWindow(hwndmax, gw_hwndnext)
Loop
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 1) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 2) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 3) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 4) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 5) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 6) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 7) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 8) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 9) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 10) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 11) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 12) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 13) = ""
Unload PleaseWait
End Sub
Public Function findthiswindow(ByVal hwndtopmost As Long) As Long
Dim hwndtmp As Long
Dim nret As Long
Dim titletmp As String
'Get the first window
hwndtmp = hwndtopmost
If GetParent(hwndtmp) = 0 Then
'Set its visibility
If IsWindowVisible(hwndtmp) Then
Visible = True
Else
Visible = False
End If
'Get its title
titletmp = Space(256)
nret = GetWindowText(hwndtmp, titletmp, Len(titletmp))
If nret Then
findthiswindow = hwndtmp
End If
End If
If Visible Then
title = titletmp & " - Visible"
Else
title = titletmp & " - Invisible"
End If
title = titletmp
If titletmp <> "" Then
'If title = "SETTINGS" Then
HasNoOWner = Not (GetWindow(hwndtmp, 4))
n = 1
'End If
If (UCase(Left(title, 15)) = "PROGRAM MANAGER" Or UCase(title) = "SETTINGS") Then
n = 1
title = ""
findthiswindow = 0
End If
End If
End Function
Sub RestoreWindowsLocations()
Dim WinFrm As WINDOWPLACEMENT
Dim RectFrm As RECT
PleaseWait.Show vbModeless
DoEvents
Workbooks(Filename).Activate
RowCount = 1
Do Until Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 1) = ""
hwndapp = Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 2)
' rtn = GetWindowPlacement(hwndapp, WinFrm)
WinFrm.rcNormalPosition.Top = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 3))
WinFrm.rcNormalPosition.Right = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 4))
WinFrm.rcNormalPosition.Left = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 5))
WinFrm.rcNormalPosition.Bottom = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 6))
WinFrm.MaxPosition.X = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 7))
WinFrm.MaxPosition.Y = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 8))
WinFrm.MinPosition.X = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 9))
WinFrm.MinPosition.Y = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 10))
WinFrm.showCmd = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 11))
WinFrm.flags = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 12))
WinFrm.Length = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 13))
rtn = SetWindowPlacement(hwndapp, WinFrm)
rtn = SetWindowPlacement(hwndapp, WinFrm)
RowCount = RowCount + 1
Loop
Unload PleaseWait
End Sub
Try this script, written for Excel. It stores the window positions in a sheet and restores them from there. You may have buttons on one of the sheets to run the store and restore macros, or shortcuts to VBS scripts that run the Excel macros, maybe with shortcut keys assigned. That way the Excel workbook can remain minimized. Of course something similar may be written in a compiled program.
Public Declare PtrSafe Function GetWindowPlacement Lib "user32" (ByVal hwnd As LongPtr, lpwndpl As WINDOWPLACEMENT) As Long
Public Declare PtrSafe Function SetWindowPlacement Lib "user32" (ByVal hwnd As LongPtr, lpwndpl As WINDOWPLACEMENT) As Long
Public Declare PtrSafe Function GetWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare PtrSafe Function IsWindowVisible Lib "user32.dll" (ByVal hwnd As Long) As Boolean
Public Declare PtrSafe Function GetParent Lib "user32.dll" (ByVal hwnd As Long) As Long
Public Declare PtrSafe Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As LongPtr, ByVal lpString As String, ByVal cch As LongPtr) As Long
Public Type POINTAPI
X As Long
Y As Long
End Type
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Type WINDOWPLACEMENT
Length As Long
flags As Long
showCmd As Long
MinPosition As POINTAPI
MaxPosition As POINTAPI
rcNormalPosition As RECT
End Type
Global Const gw_hwndnext = 2
Global Const fwp_startswith = 0
Global Const fwp_contains = 1
Global title As String
Global Visible As Boolean
Global RowCount
Public prog As String
Public Sub StoreActiveWindows()
Dim hwndapp As Long
Dim hwndmax As Long
Dim nret As Long
Dim WinFrm As WINDOWPLACEMENT
Dim RectFrm As RECT
PleaseWait.Show vbModeless
DoEvents
RowCount = 1
hwndmax = findwindow(0&, 0&)
Do Until hwndmax = 0
hwndapp = findthiswindow(hwndmax)
If hwndapp Then
If title <> "CURRENT WINDOWS OPEN" And Visible Then
rtn = GetWindowPlacement(hwndapp, WinFrm)
RectFrm = WinFrm.rcNormalPosition
FrmTop = RectFrm.Top
FrmRight = RectFrm.Right
FrmLeft = RectFrm.Left
FrmBottom = RectFrm.Bottom
Workbooks(Filename).Activate
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 1) = title
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 2) = hwndapp
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 3) = FrmTop
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 4) = FrmRight
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 5) = FrmLeft
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 6) = FrmBottom
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 7) = WinFrm.MaxPosition.X
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 8) = WinFrm.MaxPosition.Y
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 9) = WinFrm.MinPosition.X
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 10) = WinFrm.MinPosition.Y
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 11) = WinFrm.showCmd
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 12) = WinFrm.flags
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 13) = WinFrm.Length
RowCount = RowCount + 1
End If
End If
hwndmax = GetWindow(hwndmax, gw_hwndnext)
Loop
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 1) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 2) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 3) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 4) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 5) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 6) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 7) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 8) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 9) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 10) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 11) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 12) = ""
Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 13) = ""
Unload PleaseWait
End Sub
Public Function findthiswindow(ByVal hwndtopmost As Long) As Long
Dim hwndtmp As Long
Dim nret As Long
Dim titletmp As String
'Get the first window
hwndtmp = hwndtopmost
If GetParent(hwndtmp) = 0 Then
'Set its visibility
If IsWindowVisible(hwndtmp) Then
Visible = True
Else
Visible = False
End If
'Get its title
titletmp = Space(256)
nret = GetWindowText(hwndtmp, titletmp, Len(titletmp))
If nret Then
findthiswindow = hwndtmp
End If
End If
If Visible Then
title = titletmp & " - Visible"
Else
title = titletmp & " - Invisible"
End If
title = titletmp
If titletmp <> "" Then
'If title = "SETTINGS" Then
HasNoOWner = Not (GetWindow(hwndtmp, 4))
n = 1
'End If
If (UCase(Left(title, 15)) = "PROGRAM MANAGER" Or UCase(title) = "SETTINGS") Then
n = 1
title = ""
findthiswindow = 0
End If
End If
End Function
Sub RestoreWindowsLocations()
Dim WinFrm As WINDOWPLACEMENT
Dim RectFrm As RECT
PleaseWait.Show vbModeless
DoEvents
Workbooks(Filename).Activate
RowCount = 1
Do Until Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 1) = ""
hwndapp = Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 2)
' rtn = GetWindowPlacement(hwndapp, WinFrm)
WinFrm.rcNormalPosition.Top = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 3))
WinFrm.rcNormalPosition.Right = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 4))
WinFrm.rcNormalPosition.Left = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 5))
WinFrm.rcNormalPosition.Bottom = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 6))
WinFrm.MaxPosition.X = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 7))
WinFrm.MaxPosition.Y = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 8))
WinFrm.MinPosition.X = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 9))
WinFrm.MinPosition.Y = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 10))
WinFrm.showCmd = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 11))
WinFrm.flags = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 12))
WinFrm.Length = CLng(Workbooks(Filename).Sheets("Active Windows").Cells(RowCount, 13))
rtn = SetWindowPlacement(hwndapp, WinFrm)
rtn = SetWindowPlacement(hwndapp, WinFrm)
RowCount = RowCount + 1
Loop
Unload PleaseWait
End Sub
edited Aug 4 '17 at 15:28
Ben N
29.1k1396143
29.1k1396143
answered Aug 4 '17 at 2:59
Max
211
211
Please explain what this is supposed to do and clean up and format the entire code block properly as it's hard to read as-is.
– Pimp Juice IT
Aug 4 '17 at 4:42
And can you explain how to have VBS scripts that run the Excel macros? How can something similar be written into a compiled program?
– G-Man
Aug 4 '17 at 5:43
This is an interesting approach. Have you yourself uses it? I am sure a lot of people would benefit if you can create an end-to-end working sample
– Miserable Variable
Feb 1 at 16:43
add a comment |
Please explain what this is supposed to do and clean up and format the entire code block properly as it's hard to read as-is.
– Pimp Juice IT
Aug 4 '17 at 4:42
And can you explain how to have VBS scripts that run the Excel macros? How can something similar be written into a compiled program?
– G-Man
Aug 4 '17 at 5:43
This is an interesting approach. Have you yourself uses it? I am sure a lot of people would benefit if you can create an end-to-end working sample
– Miserable Variable
Feb 1 at 16:43
Please explain what this is supposed to do and clean up and format the entire code block properly as it's hard to read as-is.
– Pimp Juice IT
Aug 4 '17 at 4:42
Please explain what this is supposed to do and clean up and format the entire code block properly as it's hard to read as-is.
– Pimp Juice IT
Aug 4 '17 at 4:42
And can you explain how to have VBS scripts that run the Excel macros? How can something similar be written into a compiled program?
– G-Man
Aug 4 '17 at 5:43
And can you explain how to have VBS scripts that run the Excel macros? How can something similar be written into a compiled program?
– G-Man
Aug 4 '17 at 5:43
This is an interesting approach. Have you yourself uses it? I am sure a lot of people would benefit if you can create an end-to-end working sample
– Miserable Variable
Feb 1 at 16:43
This is an interesting approach. Have you yourself uses it? I am sure a lot of people would benefit if you can create an end-to-end working sample
– Miserable Variable
Feb 1 at 16:43
add a comment |
DISCLAIMER: I'm the creator of this tool.
I've created a little tool to rearrange windows on a traybar icon click.
You may compile it from source or ask to have a (portable) binary through the issues link.
It is hosted at Github: https://github.com/manutalcual/winredock
I would be glad to hear from you if you have suggestions.
EDIT: 2018/11/22
It is fully automated now.
This looks nice but I am looking for something more automatic.
– Mr Universe
Oct 30 at 1:24
1
I've added the automation feature due to user requests.
– Manuel
Nov 22 at 15:35
add a comment |
DISCLAIMER: I'm the creator of this tool.
I've created a little tool to rearrange windows on a traybar icon click.
You may compile it from source or ask to have a (portable) binary through the issues link.
It is hosted at Github: https://github.com/manutalcual/winredock
I would be glad to hear from you if you have suggestions.
EDIT: 2018/11/22
It is fully automated now.
This looks nice but I am looking for something more automatic.
– Mr Universe
Oct 30 at 1:24
1
I've added the automation feature due to user requests.
– Manuel
Nov 22 at 15:35
add a comment |
DISCLAIMER: I'm the creator of this tool.
I've created a little tool to rearrange windows on a traybar icon click.
You may compile it from source or ask to have a (portable) binary through the issues link.
It is hosted at Github: https://github.com/manutalcual/winredock
I would be glad to hear from you if you have suggestions.
EDIT: 2018/11/22
It is fully automated now.
DISCLAIMER: I'm the creator of this tool.
I've created a little tool to rearrange windows on a traybar icon click.
You may compile it from source or ask to have a (portable) binary through the issues link.
It is hosted at Github: https://github.com/manutalcual/winredock
I would be glad to hear from you if you have suggestions.
EDIT: 2018/11/22
It is fully automated now.
edited Nov 22 at 15:34
answered Oct 5 at 13:15
Manuel
313
313
This looks nice but I am looking for something more automatic.
– Mr Universe
Oct 30 at 1:24
1
I've added the automation feature due to user requests.
– Manuel
Nov 22 at 15:35
add a comment |
This looks nice but I am looking for something more automatic.
– Mr Universe
Oct 30 at 1:24
1
I've added the automation feature due to user requests.
– Manuel
Nov 22 at 15:35
This looks nice but I am looking for something more automatic.
– Mr Universe
Oct 30 at 1:24
This looks nice but I am looking for something more automatic.
– Mr Universe
Oct 30 at 1:24
1
1
I've added the automation feature due to user requests.
– Manuel
Nov 22 at 15:35
I've added the automation feature due to user requests.
– Manuel
Nov 22 at 15:35
add a comment |
I've used Stardock’s Fences before in a similar scenario:
Fences helps you organize your PC by automatically placing your
shortcuts and icons into resizable shaded areas on your desktop called
fences. Its many customization features are what make Fences the
world's most popular Windows desktop enhancement.
7
That arranges icons. Not windows. My issue is that I have 8 programs open across three screens. When I close the laptop, and re-open it with the three screens all my application windows are open on one screen, not arranged how I had them.
– CaffGeek
May 10 '13 at 13:17
add a comment |
I've used Stardock’s Fences before in a similar scenario:
Fences helps you organize your PC by automatically placing your
shortcuts and icons into resizable shaded areas on your desktop called
fences. Its many customization features are what make Fences the
world's most popular Windows desktop enhancement.
7
That arranges icons. Not windows. My issue is that I have 8 programs open across three screens. When I close the laptop, and re-open it with the three screens all my application windows are open on one screen, not arranged how I had them.
– CaffGeek
May 10 '13 at 13:17
add a comment |
I've used Stardock’s Fences before in a similar scenario:
Fences helps you organize your PC by automatically placing your
shortcuts and icons into resizable shaded areas on your desktop called
fences. Its many customization features are what make Fences the
world's most popular Windows desktop enhancement.
I've used Stardock’s Fences before in a similar scenario:
Fences helps you organize your PC by automatically placing your
shortcuts and icons into resizable shaded areas on your desktop called
fences. Its many customization features are what make Fences the
world's most popular Windows desktop enhancement.
edited Oct 6 '14 at 19:11
JakeGould
31k1093137
31k1093137
answered May 9 '13 at 23:29
Pete Q
1424
1424
7
That arranges icons. Not windows. My issue is that I have 8 programs open across three screens. When I close the laptop, and re-open it with the three screens all my application windows are open on one screen, not arranged how I had them.
– CaffGeek
May 10 '13 at 13:17
add a comment |
7
That arranges icons. Not windows. My issue is that I have 8 programs open across three screens. When I close the laptop, and re-open it with the three screens all my application windows are open on one screen, not arranged how I had them.
– CaffGeek
May 10 '13 at 13:17
7
7
That arranges icons. Not windows. My issue is that I have 8 programs open across three screens. When I close the laptop, and re-open it with the three screens all my application windows are open on one screen, not arranged how I had them.
– CaffGeek
May 10 '13 at 13:17
That arranges icons. Not windows. My issue is that I have 8 programs open across three screens. When I close the laptop, and re-open it with the three screens all my application windows are open on one screen, not arranged how I had them.
– CaffGeek
May 10 '13 at 13:17
add a comment |
Alot of windows users had this issue, an application was developed and shared within the windows 7 forums as shown here:
http://www.sevenforums.com/free-developer-programs-projects/40916-shellfolderfix-manage-folder-window-positions-size.html#post396744
There are instructions on the site which help and it should fix your issue.
The forum says "This is an app to make Windows 7 explorer folder windows remember their size and position" and " It does NOT manage window size/positions of regular applications, if you want that, other apps like Window Manager do it". What is meant by Window Manager? Is that the Microsoft Windows Manager service or the product from DeskSoft link
– MADCookie
Oct 7 '14 at 19:26
yes it is the product from DeskSoft
– DarkEvE
Oct 7 '14 at 19:50
add a comment |
Alot of windows users had this issue, an application was developed and shared within the windows 7 forums as shown here:
http://www.sevenforums.com/free-developer-programs-projects/40916-shellfolderfix-manage-folder-window-positions-size.html#post396744
There are instructions on the site which help and it should fix your issue.
The forum says "This is an app to make Windows 7 explorer folder windows remember their size and position" and " It does NOT manage window size/positions of regular applications, if you want that, other apps like Window Manager do it". What is meant by Window Manager? Is that the Microsoft Windows Manager service or the product from DeskSoft link
– MADCookie
Oct 7 '14 at 19:26
yes it is the product from DeskSoft
– DarkEvE
Oct 7 '14 at 19:50
add a comment |
Alot of windows users had this issue, an application was developed and shared within the windows 7 forums as shown here:
http://www.sevenforums.com/free-developer-programs-projects/40916-shellfolderfix-manage-folder-window-positions-size.html#post396744
There are instructions on the site which help and it should fix your issue.
Alot of windows users had this issue, an application was developed and shared within the windows 7 forums as shown here:
http://www.sevenforums.com/free-developer-programs-projects/40916-shellfolderfix-manage-folder-window-positions-size.html#post396744
There are instructions on the site which help and it should fix your issue.
edited Oct 7 '14 at 10:08
answered Oct 7 '14 at 9:47
DarkEvE
377110
377110
The forum says "This is an app to make Windows 7 explorer folder windows remember their size and position" and " It does NOT manage window size/positions of regular applications, if you want that, other apps like Window Manager do it". What is meant by Window Manager? Is that the Microsoft Windows Manager service or the product from DeskSoft link
– MADCookie
Oct 7 '14 at 19:26
yes it is the product from DeskSoft
– DarkEvE
Oct 7 '14 at 19:50
add a comment |
The forum says "This is an app to make Windows 7 explorer folder windows remember their size and position" and " It does NOT manage window size/positions of regular applications, if you want that, other apps like Window Manager do it". What is meant by Window Manager? Is that the Microsoft Windows Manager service or the product from DeskSoft link
– MADCookie
Oct 7 '14 at 19:26
yes it is the product from DeskSoft
– DarkEvE
Oct 7 '14 at 19:50
The forum says "This is an app to make Windows 7 explorer folder windows remember their size and position" and " It does NOT manage window size/positions of regular applications, if you want that, other apps like Window Manager do it". What is meant by Window Manager? Is that the Microsoft Windows Manager service or the product from DeskSoft link
– MADCookie
Oct 7 '14 at 19:26
The forum says "This is an app to make Windows 7 explorer folder windows remember their size and position" and " It does NOT manage window size/positions of regular applications, if you want that, other apps like Window Manager do it". What is meant by Window Manager? Is that the Microsoft Windows Manager service or the product from DeskSoft link
– MADCookie
Oct 7 '14 at 19:26
yes it is the product from DeskSoft
– DarkEvE
Oct 7 '14 at 19:50
yes it is the product from DeskSoft
– DarkEvE
Oct 7 '14 at 19:50
add a comment |
This one was looking promising: https://github.com/adamsmith/WindowsLayoutSnapshot
Unfortunately in my case, when saving the layout on 3x 24" 1920x1200 monitors, changing to one laptop 1920x1080, and then going back to three and trying to restore layout, windows didn't really move to other monitors. But maybe for someone else on other setup it will work.
Looks promising, but that won't run on my PC (Windows 8.1)
– Dunc
Jan 5 '17 at 12:09
Discontinued unfortunately, and it loses all the config when the program is closed or the PC is restarted, which the author doesn't plan to fix.
– this.lau_
Jun 24 '17 at 21:04
add a comment |
This one was looking promising: https://github.com/adamsmith/WindowsLayoutSnapshot
Unfortunately in my case, when saving the layout on 3x 24" 1920x1200 monitors, changing to one laptop 1920x1080, and then going back to three and trying to restore layout, windows didn't really move to other monitors. But maybe for someone else on other setup it will work.
Looks promising, but that won't run on my PC (Windows 8.1)
– Dunc
Jan 5 '17 at 12:09
Discontinued unfortunately, and it loses all the config when the program is closed or the PC is restarted, which the author doesn't plan to fix.
– this.lau_
Jun 24 '17 at 21:04
add a comment |
This one was looking promising: https://github.com/adamsmith/WindowsLayoutSnapshot
Unfortunately in my case, when saving the layout on 3x 24" 1920x1200 monitors, changing to one laptop 1920x1080, and then going back to three and trying to restore layout, windows didn't really move to other monitors. But maybe for someone else on other setup it will work.
This one was looking promising: https://github.com/adamsmith/WindowsLayoutSnapshot
Unfortunately in my case, when saving the layout on 3x 24" 1920x1200 monitors, changing to one laptop 1920x1080, and then going back to three and trying to restore layout, windows didn't really move to other monitors. But maybe for someone else on other setup it will work.
answered Apr 2 '15 at 16:43
Koshmaar
693
693
Looks promising, but that won't run on my PC (Windows 8.1)
– Dunc
Jan 5 '17 at 12:09
Discontinued unfortunately, and it loses all the config when the program is closed or the PC is restarted, which the author doesn't plan to fix.
– this.lau_
Jun 24 '17 at 21:04
add a comment |
Looks promising, but that won't run on my PC (Windows 8.1)
– Dunc
Jan 5 '17 at 12:09
Discontinued unfortunately, and it loses all the config when the program is closed or the PC is restarted, which the author doesn't plan to fix.
– this.lau_
Jun 24 '17 at 21:04
Looks promising, but that won't run on my PC (Windows 8.1)
– Dunc
Jan 5 '17 at 12:09
Looks promising, but that won't run on my PC (Windows 8.1)
– Dunc
Jan 5 '17 at 12:09
Discontinued unfortunately, and it loses all the config when the program is closed or the PC is restarted, which the author doesn't plan to fix.
– this.lau_
Jun 24 '17 at 21:04
Discontinued unfortunately, and it loses all the config when the program is closed or the PC is restarted, which the author doesn't plan to fix.
– this.lau_
Jun 24 '17 at 21:04
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f593701%2fremember-window-locations-when-docked-and-undocked%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I run into the same issue but my complaint is when I open the laptop later and the application window is still off-screen (end up using the arrow keys to move it back onscreen). I don't think there is a built-in solution to this.
– Brad Patton
May 10 '13 at 0:38