有一种朋友不在生活里,却在生命力;有一种陪伴不在身边,却在心间。图老师即在大家的生活中又在身边。这么贴心的服务你感受到了吗?话不多说下面就和大家分享限制Form Resize的最大值吧。
【 tulaoshi.com - 编程语言 】
当Form的Position更动或大小改变时,会Send WM_GETMINMAXINFO的讯息,当我们取得这个讯息时,可以更动该讯息内定Windows Resize的值,不过本人目前只有测出如何限定其最大的Size,而最小的Size目前没有测出来,知道可者告诉我
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)
Option Explicit'以下程式在module1.basDeclare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _ (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongDeclare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _ (ByVal hwnd As Long, ByVal nIndex As Long) As LongDeclare 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 LongDeclare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" ( _ lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)Public Const GWL_WNDPROC = (-4)Public Const WM_GETMINMAXINFO = &H24Type POINTAPI x As Long y As LongEnd TypeType MINMAXINFO ptReserved As POINTAPI ptMaxSize As POINTAPI ptMaxPosition As POINTAPI ptMinTrackSize As POINTAPI ptMaxTrackSize As POINTAPIEnd TypePublic preWinProc As LongPublic Function wndproc(ByVal hwnd As Long, ByVal Msg As Long, _ ByVal wParam As Long, ByVal lParam As Long) As LongDim lwd As Long, hwd As LongIf Msg = WM_GETMINMAXINFO Then Dim maxmin As MINMAXINFO CopyMemory maxmin, ByVal lParam, Len(maxmin) maxmin.ptMaxTrackSize.x = 500 '设定最大Resize的宽度 maxmin.ptMaxTrackSize.y = 400 '设定最大Resize的高度 'maxmin.ptMinTrackSize.x = 300 '设定最大小Resize的宽度 'maxmin.ptMinTrackSize.y = 300 '设定最大小Resize的高度 CopyMemory ByVal lParam, maxmin, Len(maxmin)End If'将之送往原来的Window Procedurewndproc = CallWindowProc(preWinProc, hwnd, Msg, wParam, lParam)End Function'以下在FormSub Form_Load()Dim ret As Long'记录原本的Window Procedure的位址preWinProc = GetWindowLong(Me.hwnd, GWL_WNDPROC)ret = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf wndproc)End SubPrivate Sub Form_Unload(Cancel As Integer)Dim ret As Long'取消Message的截取,而使之又只送往原来的Window Procedureret = SetWindowLong(Me.hwnd, GWL_WNDPROC, preWinProc)End Sub(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)
来源:http://www.tulaoshi.com/n/20160219/1613337.html
看过《限制Form Resize的最大值》的人还看了以下文章 更多>>