Private Const SPI_GETNONCLIENTMETRICS As Long = 41
Private Const LF_FACESIZE As Long = 32
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type LOGFONT
lfHeight As Long
lfWidth As Long
lfEscapement As Long
lfOrientation As Long
lfWeight As Long
lfItalic As Byte
lfUnderline As Byte
lfStrikeOut As Byte
lfCharSet As Byte
lfOutPrecision As Byte
lfClipPrecision As Byte
lfQuality As Byte
lfPitchAndFamily As Byte
lfFaceName(1 To LF_FACESIZE) As Byte
End Type
Private Type NONCLIENTMETRICS
cbSize As Long
iBorderWidth As Long
iScrollWidth As Long
iScrollHeight As Long
iCaptionWidth As Long
iCaptionHeight As Long
lfCaptionFont As LOGFONT
iSMCaptionWidth As Long
iSMCaptionHeight As Long
lfSMCaptionFont As LOGFONT
iMenuWidth As Long
iMenuHeight As Long
lfMenuFont As LOGFONT
lfStatusFont As LOGFONT
lfMessageFont As LOGFONT
End Type
Private Declare Function GetClientRect Lib "user32.dll" (ByVal hwnd As Long, ByRef lpRect As RECT) As Long
Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, ByRef lpRect As RECT) As Long
Private Declare Function SetRect Lib "user32.dll" (ByRef lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function GetProp Lib "user32.dll" Alias "GetPropA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Private Declare Function SetProp Lib "user32.dll" Alias "SetPropA" (ByVal hwnd As Long, ByVal lpString As String, ByVal hData As Long) As Long
Private Declare Function RemoveProp Lib "user32.dll" Alias "RemovePropA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Private Declare Function SetWindowPos Lib "user32.dll" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function SystemParametersInfo Lib "user32.dll" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long
Private Declare Function GetParent Lib "user32.dll" (ByVal hwnd As Long) As Long
Dim mColCtls As Collection
Dim AttachedHwnd As Long
Public Enum eAnchorTypes
eLeft = 1
eTop = 2
eRight = 4
eBottom = 8
eAll = 15
eNone = 0
End Enum
Private Sub Class_Initialize()
'-- Initialise the collection
Set mColCtls = New Collection
End Sub
Private Sub Class_Terminate()
'-- Make sure we unsubclass
DetachWind
'-- Destroy the collection
Set mColCtls = Nothing
End Sub
Private Function ISubclass_WndProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long, bHandled As Boolean) As Long
Select Case uMsg
Case WM_WINDOWPOSCHANGED
'-- The window position has changed
If mColCtls.Count > 0 Then
'-- Make sure we don't bother to loop if there's nothing to loop through
Dim i As Long
Dim relRect As RECT
Dim WndRect As RECT
Dim CtlRect As RECT
Dim AnchorType As eAnchorTypes
Dim Left As Long, Top As Long, width As Long, height As Long
GetClientRect hwnd, WndRect
For i = 1 To mColCtls.Count
'-- Retrieve the control's anchor type
AnchorType = GetProp(mColCtls(i), "AnchorType")
'-- Get its original rect relative to the parent
relRect = GetRectFromWndProperties(mColCtls(i))
'-- Get its new rect
GetWindowRect mColCtls(i), CtlRect
'-- Initialise our vars
Left = relRect.Left
Top = relRect.Top
width = CtlRect.Right - CtlRect.Left
height = CtlRect.Bottom - CtlRect.Top
'-- If it's anchored right
If (AnchorType And eAnchorTypes.eRight) = eAnchorTypes.eRight Then
'-- If it's also anchored left
If (AnchorType And eAnchorTypes.eLeft) = eAnchorTypes.eLeft Then