我想让程序窗口不能让用户调整大小.但又要保留标题栏和最小化,关闭按扭.
怎么实现,大家帮帮忙
见PK赛 连加的例程,有限制窗体最小size的API使用,只要把最大也限制为那个size。
Type POINTAPI
x As Long
y As Long
End Type
Type MINMAXINFO
ptReserved As POINTAPI
ptMaxSize As POINTAPI
ptMaxPosition As POINTAPI
ptMinTrackSize As POINTAPI
ptMaxTrackSize As POINTAPI
End Type
Private 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
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal ByteLen As Long)
Public Const GWL_WNDPROC = (-4)
Public Const WM_GETMINMAXINFO = &H24
Dim OldProc&
Dim mhWnd&
'==================================================
'回调
Function WinProc&(ByVal hWnd&, ByVal wMsg&, _
ByVal wParam&, ByVal lParam&)
Select Case wMsg&
Case WM_GETMINMAXINFO
Dim MinMax As MINMAXINFO
CopyMemory MinMax, ByVal lParam, Len(MinMax)
MinMax.ptMinTrackSize.x = 567
MinMax.ptMinTrackSize.y = 250
' MinMax.ptMaxTrackSize.x = 808
' MinMax.ptMaxTrackSize.y = 250
' 注意这里 把x统一了 y统一了 去除注释
CopyMemory ByVal lParam, MinMax, Len(MinMax)
WinProc& = 1
Exit Function
End Select
WinProc& = CallWindowProc(OldProc, hWnd, wMsg, wParam, lParam)
End Function
'==================================================
'==================================================
'挂钩
Sub Hook(ByVal nhWnd&)
If OldProc <> 0 Then Exit Sub
mhWnd& = nhWnd&
OldProc = SetWindowLong(nhWnd&, GWL_WNDPROC, AddressOf WinProc)
End Sub
'==================================================
'==================================================
'脱钩
Sub UnHook()
If OldProc = 0 Then Exit Sub
SetWindowLong mhWnd, GWL_WNDPROC, OldProc
OldProc = 0
End Sub
'==================================================