Private Sub Form_Resize() WindowState = 0 End Sub
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long 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 Const GWL_WNDPROC = -4 Private Const WM_NCLBUTTONDOWN = &HA1 Private Const HTMINBUTTON = 8 Private Const HTMAXBUTTON = 9 Private OldWndProc As Long Public Sub StartSubClass(ByVal hWnd As Long) OldWndProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc) End Sub Public Sub ExitSubClass(ByVal hWnd As Long) Call SetWindowLong(hWnd, GWL_WNDPROC, OldWndProc) End Sub Private Function WindowProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Select Case Msg Case WM_NCLBUTTONDOWN '只禁用两个按钮,系统菜单可用 If wParam = HTMINBUTTON Or wParam = HTMAXBUTTON Then WindowProc = True Exit Function End If End Select WindowProc = CallWindowProc(OldWndProc, hWnd, Msg, wParam, lParam) End Function
Private Sub Form_Load() Call StartSubClass(Me.hWnd) End Sub Private Sub Form_Unload(Cancel As Integer) Call ExitSubClass(Me.hWnd) End Sub
Private Const WM_SYSCOMMAND = &H112 Private Const SC_MINIMIZE = &HF020& Private Const SC_MAXIMIZE = &HF030& Private Function WindowProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Select Case Msg Case WM_SYSCOMMAND '禁用两个按钮,包含系统菜单 If wParam = SC_MINIMIZE Or wParam = SC_MAXIMIZE Then WindowProc = True Exit Function End If End Select WindowProc = CallWindowProc(OldWndProc, hWnd, Msg, wParam, lParam) End Function
[此贴子已经被作者于2022-7-13 22:15编辑过]