谢谢,已解决:
控件也按照比例缩放
======窗口代码======
Option Explicit
Private Sub Form_Load()
FormOldWidth = Me.ScaleWidth
FormOldHeight = Me.ScaleHeight
Dim Obj As Control 'Control是一个对象,表示所有 Visual Basic 内部控件的类名
For Each Obj In Me
'Tag返回或设置一个表达式用来存储程序中需要的额外数据。
Obj.Tag = Obj.Left & " " & Obj.Top & " " & Obj.Width & " " & Obj.Height & " "
Next Obj
dSize = 300 '单位 Me.ScaleMode
Hook Me.hWnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnHook Me.hWnd
End Sub
Private Sub Form_Resize()
Dim Pos
Dim Obj As Control
Dim ScaleX As Double
Dim ScaleY As Double
ScaleX = Me.ScaleWidth / FormOldWidth
ScaleY = Me.ScaleHeight / FormOldHeight
For Each Obj In Me
Pos = Split(Obj.Tag, " ")
If IsArray(Pos) Then _
Obj.Move Pos(0) * ScaleX, Pos(1) * ScaleY, Pos(2) * ScaleX, Pos(3) * ScaleY
Next Obj
End Sub
=======模块代码========
Option Explicit
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
Declare Function SystemParametersInfo _
Lib "USER32" Alias "SystemParametersInfoA" _
(ByVal uAction As Long, _
ByVal uParam As Long, _
lpvParam As Any, _
ByVal fuWinIni As Long) As Long
Public Const GWL_WNDPROC = -4
Public Const WM_MOUSEWHEEL = &H20A
Global lpPrevWndProc As Long
Global FormOldWidth As Long
Global FormOldHeight As Long
Global dSize As Long
Public Sub Hook(ByVal hWnd As Long)
lpPrevWndProc = SetWindowLong(hWnd, GWL_WNDPROC, _
AddressOf WindowProc)
End Sub
Public Sub UnHook(ByVal hWnd As Long)
Dim lngReturnValue As Long
lngReturnValue = SetWindowLong(hWnd, GWL_WNDPROC, lpPrevWndProc)
End Sub
Function WindowProc(ByVal hw As Long, _
ByVal uMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Select Case uMsg
Case WM_MOUSEWHEEL
Dim wzDelta As Integer, wKeys As Integer
wzDelta = HiWord(wParam)
wKeys = LoWord(wParam)
If wParam < 0 Then
Form1.Width = Form1.Width + dSize
Form1.Height = Form1.Height + dSize * FormOldHeight / FormOldWidth
Else
Form1.Width = Form1.Width - dSize
Form1.Height = Form1.Height - dSize * FormOldHeight / FormOldWidth
End If
Case Else
WindowProc = CallWindowProc(lpPrevWndProc, hw, _
uMsg, wParam, lParam)
End Select
End Function
Public Function HiWord(LongIn As Long) As Integer
HiWord = (LongIn And &HFFFF0000) \ &H10000
End Function
Public Function LoWord(LongIn As Long) As Integer
LoWord = LongIn And &HFFFF&
End Function