程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> Visual Basic語言 >> VB綜合教程 >> 限制Form Resize的最大值

限制Form Resize的最大值

編輯:VB綜合教程

  當Form的Position更動或大小改變時,會Send WM_GETMINMAXINFO的訊息,當我們取得這個訊息時,可以更動該訊息內定Windows Resize的值,不過本人目前只有測出如何限定其最大的Size,而最小的Size目前沒有測出來,知道可者告訴我

  

Option Explicit
'以下程式在module1.bas
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
 (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
 (ByVal hwnd As Long, ByVal nIndex As Long) 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 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 = &H24
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
Public preWinProc As Long
Public Function wndproc(ByVal hwnd As Long, ByVal Msg As Long, _
             ByVal wParam As Long, ByVal lParam As Long) As Long
Dim lwd As Long, hwd As Long
If 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 Procedure
wndproc = CallWindowProc(preWinProc, hwnd, Msg, wParam, lParam)
End Function


'以下在Form
Sub Form_Load()
Dim ret As Long
'記錄原本的Window Procedure的位址
preWinProc = GetWindowLong(Me.hwnd, GWL_WNDPROC)
ret = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf wndproc)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim ret As Long
'取消Message的截取,而使之又只送往原來的Window Procedure
ret = SetWindowLong(Me.hwnd, GWL_WNDPROC, preWinProc)
End Sub

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved