Wypróbuj ten skrypt napisany dla programu Excel. Przechowuje pozycje okna w arkuszu i przywraca je stamtąd. Na jednym z arkuszy mogą znajdować się przyciski do uruchamiania sklepu i przywracania makr lub skróty do skryptów VBS, które uruchamiają makra Excel, być może z przypisanymi klawiszami skrótów. W ten sposób skoroszyt programu Excel może pozostać zminimalizowany. Oczywiście coś podobnego można napisać w skompilowanym programie.
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