我觉得这实在令人沮丧。
我在工作时笔记本电脑上有两个额外的屏幕。我带着笔记本电脑回家,没有连接任何额外的屏幕。我回来后,将笔记本电脑对接上,然后需要重新排列窗口。
有没有办法让窗口(或实用程序)跟踪整体屏幕配置(#,大小,分辨率),并记住窗口的位置,因此当屏幕配置再次匹配时,它会将应用程序放回到原来的位置?
答案1
免责声明:我是该工具的创建者。
我创建了一个小工具,用于在单击托盘栏图标时重新排列窗口。您可以从源代码编译它,也可以通过问题链接请求获取(可移植的)二进制文件。
它托管在 Github 上:https://github.com/manutalcual/winredock
如果您有任何建议,我将非常高兴收到您的来信。
编辑:2018/11/22
现在它已完全自动化。
答案2
我目前使用 DisplayFusion Pro 进行窗口定位(不止于此)。我不知道断开和连接显示器时它是如何工作的 - 我一直有三个显示器。
我认为,您必须关闭并重新打开您的应用程序才能重新排列。
编辑:此功能仅在专业版中可用。 - 来自评论的信息。
主页显示融合
答案3
这是一个控制台应用程序保存和恢复 Windows 桌面上的窗口位置和状态。要保存窗口位置,请运行:
winLayout save
要恢复窗口位置,请运行:
winLayout restore
将这些命令放入桌面快捷方式并固定到任务栏以方便使用。
免责声明:我编写了此实用程序,因为此页面上的其他工具对我来说不起作用。
警告:它适用于应用程序,但不适用于资源管理器窗口(目前)
答案4
尝试一下这个为 Excel 编写的脚本。它将窗口位置存储在工作表中并从那里恢复它们。您可能在其中一个工作表上有按钮来运行存储和恢复宏,或者有运行 Excel 宏的 VBS 脚本的快捷方式,可能分配了快捷键。这样 Excel 工作簿就可以保持最小化。当然,在编译的程序中也可以编写类似的内容。
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