Const WM_WINDOWPOSCHANGING =&H46
Сообщение WM_WINDOWPOSCHANGING посылается окну, чьи размеры, позиция и z-порядок меняются при вызове функции SetWindowPos или ей подобной. Окно получает сообщение через функцию обратного вызова WindowProc
Сообщение WM_WINDOWPOSCHANGING всегда возвращает 0
' Используем данное сообщение, ' для сохранения пропорций окна ' при изменений ее размеров ' Поместите код в модуль, ' т.к. используется функция обратного вызова Public OldWindowProc As Long Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _ (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, _ ByVal msg As Long, ByVal wParam As Long, _ ByVal lParam As Long) As Long Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _ (ByVal hwnd As Long, ByVal nIndex As Long, _ ByVal dwNewLong As Long) As Long Public Const GWL_WNDPROC = (-4) Type WINDOWPOS hwnd As Long hWndInsertAfter As Long x As Long y As Long cx As Long cy As Long flags As Long End Type Public Const WM_WINDOWPOSCHANGING = &H46 Public Function WindowProc(ByVal hwnd As Long, _ ByVal msg As Long, ByVal wParam As Long, _ ByVal lParam As Long) As Long Static done_before As Boolean Static aspect As Single Dim new_aspect As Single ' Keep the aspect ratio. If msg = WM_WINDOWPOSCHANGING Then If lParam.cy > 0 Then ' Save the aspect ratio the first. If Not done_before Then aspect = lParam.cx / lParam.cy done_before = True End If new_aspect = lParam.cx / lParam.cy If new_aspect > aspect Then ' Too short/wide. Make it taller. lParam.cy = lParam.cx / aspect Else ' Too tall/thin. Make it wider. lParam.cx = aspect * lParam.cy End If End If End If WindowProc = CallWindowProc( _ OldWindowProc, hwnd, msg, wParam, _ lParam) End Function ' Поместите код в событие Form_Load OldWindowProc = SetWindowLong( _ hwnd, GWL_WNDPROC, _ AddressOf WindowProc)