एक्सेल के लिए लिखी गई इस स्क्रिप्ट को आज़माएं। यह एक शीट में खिड़की की स्थिति को संग्रहीत करता है और उन्हें वहां से पुनर्स्थापित करता है। आपके पास स्टोर चलाने और मैक्रोज़ को पुनर्स्थापित करने के लिए शीट में से किसी एक पर बटन हो सकते हैं, या वीबीएस स्क्रिप्ट के लिए शॉर्टकट जो एक्सेल मैक्रोज़ को चला सकते हैं, शायद शॉर्टकट कुंजियों के साथ। इस तरह से एक्सेल वर्कबुक को छोटा किया जा सकता है। बेशक एक संकलित कार्यक्रम में ऐसा ही कुछ लिखा जा सकता है।
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