Option Explicit
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type MINMAXINFO
ptReserved As POINTAPI
ptMaxSize As POINTAPI
ptMaxPosition As POINTAPI
ptMinTrackSize As POINTAPI
ptMaxTrackSize As POINTAPI
End Type
Private Declare Function SystemParametersInfo _
Lib "user32" Alias "SystemParametersInfoA" _
(ByVal uAction As Long, _
ByVal uParam As Long, _
lpvParam As Any, _
ByVal fuWinIni As Long) As Long
Private Const SPI_GETDRAGFULLWINDOWS = 38
Private Const SPI_SETDRAGFULLWINDOWS = 37
Private Const SPIF_SENDWININICHANGE = &H2
Private bInitialFullWindowDragSettig As Boolean
Private Declare Function GetWindowRect Lib "user32" _
(ByVal hwnd As Long, lpRect As RECT) As Long
Private lCurAppWidth As Long
Private lCurAppHeight As Long
Private lCurAppLeft As Long
Private lCurAppTop As Long
Private lPrevAppWidth As Long
Private lPrevAppHeight As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private lXLhwnd As Long
Private Declare Function GetSystemMetrics Lib _
"user32" (ByVal nIndex As Long) As Long
Const SM_CXSCREEN = 0 'X Size of screen
Const SM_CYSCREEN = 1 'Y Size of Screen
Private Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Declare Function CallWindowProc Lib "user32" _
Alias "CallWindowProcA" _
(ByVal lpPrevWndFunc As Long, _
ByVal hwnd As Long, _
ByVal uMsg As Long, _
ByVal wParam As Long, _
lParam As MINMAXINFO) As Long
Private Const GWL_WNDPROC = (-4)
Private ldefWindowProc As Long
Private Const WM_GETMINMAXINFO = &H24
Private Const WM_SYSCOMMAND = &H112
Private Const SC_MAXIMIZE = &HF030&
Private Const SC_RESTORE = &HF120&
Private Const WM_EXITSIZEMOVE As Long = &H232&
Private Const WM_ENABLE = &HA
Private bXLAppDisabled As Boolean
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTTOP = 12
Private Const HTBOTTOM = 15
Private Const HTLEFT = 10
Private Const HTRIGHT = 11
Private Const HTTOPLEFT = 13
Private Const HTTOPRIGHT = 14
Private Const HTBOTTOMLEFT = 16
Private Const HTBOTTOMRIGHT = 17
Private b_LEFT_Edge_Sizing As Boolean
Private b_RIGHT_Edge_Sizing As Boolean
Private b_TOP_Edge_Sizing As Boolean
Private b_BOTTOM_Edge_Sizing As Boolean
Sub InstalXLSubClass()
Call Show_Windows_Contents_While_Dragging
lXLhwnd = FindWindow("XLMAIN", Application.Caption)
'assign our own window message
'procedure (WindowProc)
On Error Resume Next
If ldefWindowProc = 0 Then
ldefWindowProc = SetWindowLong(lXLhwnd, _
GWL_WNDPROC, _
AddressOf WindowProc)
End If
End Sub
Sub RemoveXLSubClass()
Call ResetInitialFullWindowDragSetting
If ldefWindowProc Then
SetWindowLong lXLhwnd, GWL_WNDPROC, ldefWindowProc
ldefWindowProc = 0
End If
End Sub
Private Function WindowProc(ByVal hwnd As Long, _
ByVal uMsg As Long, _
ByVal wParam As Long, _
lParam As MINMAXINFO) As Long
Dim Cancel_WnSZ_Height As Boolean
Dim Cancel_WnSZ_Width As Boolean
Dim tRect As RECT
On Error Resume Next
GetWindowRect hwnd, tRect
With tRect
lCurAppLeft = .Left
lCurAppTop = .Top
lCurAppWidth = .Right - .Left
lCurAppHeight = .Bottom - .Top
End With
Select Case uMsg
Case Is = WM_ENABLE
If Not wParam Then
bXLAppDisabled = True
End If
Case Is = WM_EXITSIZEMOVE
bXLAppDisabled = False
Case WM_SYSCOMMAND
Select Case wParam And &HFFF0
Case Is = SC_MAXIMIZE
Exit Function
End Select
Case Is = WM_NCLBUTTONDOWN
Select Case wParam
Case Is = HTTOP
b_TOP_Edge_Sizing = True
b_LEFT_Edge_Sizing = False
b_RIGHT_Edge_Sizing = False
Case Is = HTBOTTOM
b_BOTTOM_Edge_Sizing = True
b_LEFT_Edge_Sizing = False
b_RIGHT_Edge_Sizing = False
Case Is = HTLEFT
b_LEFT_Edge_Sizing = True
b_TOP_Edge_Sizing = False
b_BOTTOM_Edge_Sizing = False
Case Is = HTRIGHT
b_RIGHT_Edge_Sizing = True
b_TOP_Edge_Sizing = False
b_BOTTOM_Edge_Sizing = False
Case Is = HTTOPLEFT, HTTOPRIGHT, _
HTBOTTOMLEFT, HTBOTTOMRIGHT
Exit Function
End Select
Case WM_GETMINMAXINFO
With lParam
If bXLAppDisabled Then
.ptMinTrackSize.y = lCurAppHeight
.ptMaxTrackSize.y = lCurAppHeight
.ptMinTrackSize.x = lCurAppWidth
.ptMaxTrackSize.x = lCurAppWidth
Exit Function
End If
If (b_TOP_Edge_Sizing Or b_BOTTOM_Edge_Sizing) Then
Call Application_WindowResizeVer(Cancel_WnSZ_Height)
If Cancel_WnSZ_Height Then
If lPrevAppHeight < lCurAppHeight And _
lPrevAppHeight <> 0 Then
.ptMinTrackSize.y = 0
If bXLAppDisabled Then
.ptMaxTrackSize.y = lCurAppHeight - 10
Else
.ptMaxTrackSize.y = lCurAppHeight
End If
Exit Function
ElseIf lPrevAppHeight > lCurAppHeight Then
If bXLAppDisabled Then
.ptMinTrackSize.y = lCurAppHeight + 10
Else
.ptMinTrackSize.y = lCurAppHeight
End If
.ptMaxTrackSize.y = GetSystemMetrics(SM_CYSCREEN)
Exit Function
End If
End If
lPrevAppHeight = lCurAppHeight
End If
If (b_LEFT_Edge_Sizing Or b_RIGHT_Edge_Sizing) Then
Call Application_WindowResizeHor(Cancel_WnSZ_Width)
If Cancel_WnSZ_Width Then
If lPrevAppWidth < lCurAppWidth And _
lPrevAppWidth <> 0 Then
.ptMinTrackSize.x = 0
If bXLAppDisabled Then
.ptMaxTrackSize.x = lCurAppWidth - 10
Else
.ptMaxTrackSize.x = lCurAppWidth
End If
Exit Function
ElseIf lPrevAppWidth > lCurAppWidth Then
If bXLAppDisabled Then
.ptMinTrackSize.x = lCurAppWidth + 10
Else
.ptMinTrackSize.x = lCurAppWidth
End If
.ptMaxTrackSize.x = GetSystemMetrics(SM_CXSCREEN)
Exit Function
End If
End If
lPrevAppWidth = lCurAppWidth
End If
End With
End Select
WindowProc = CallWindowProc(ldefWindowProc, _
hwnd, _
uMsg, _
wParam, _
lParam)
End Function
Private Function IsFullWindowDragOn() As Boolean
Dim lresult As Long
'Call API and check for successful call.
If SystemParametersInfo(SPI_GETDRAGFULLWINDOWS, 0&, lresult, 0&) _
<> 0 Then
'Feature supported now check value of result.
If lresult = 0 Then
IsFullWindowDragOn = False
Else
IsFullWindowDragOn = True
End If
'Call failed, feature not supported.
Else
IsFullWindowDragOn = False
End If
End Function
Private Sub Show_Windows_Contents_While_Dragging()
Dim lresult As Long
bInitialFullWindowDragSettig = True
If Not IsFullWindowDragOn Then
lresult = SystemParametersInfo(SPI_SETDRAGFULLWINDOWS, 1&, _
ByVal vbNullString, SPIF_SENDWININICHANGE)
bInitialFullWindowDragSettig = Not bInitialFullWindowDragSettig
End If
End Sub
Private Sub ResetInitialFullWindowDragSetting()
Dim lresult As Long
If Not bInitialFullWindowDragSettig Then
lresult = SystemParametersInfo(SPI_SETDRAGFULLWINDOWS, 0&, _
ByVal vbNullString, SPIF_SENDWININICHANGE)
End If
End Sub