|
原帖由 qifenghome 于 2009-5-22 21:30 发表
这个代码屏蔽的是所有按钮 但我想保留最大 最下化按钮啊
下面的代码添加最大、最小化按钮,并且让关闭按钮不可用(在窗口上双击左键关闭)
- Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
- Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
- Private Declare Function EnableMenuItem Lib "user32" (ByVal hMenu As Long, ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long
- Private Const MF_BYPOSITION = &H400&
- Private Const MF_DISABLED = &H2&
- Private Const MF_GRAYED = &H1&
- Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex 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 Const GWL_STYLE = (-16)
- Private Const WS_MAXIMIZEBOX = &H10000
- Private Const WS_MINIMIZEBOX = &H20000
- Private Sub UserForm_Initialize()
- Dim hwnd As Long
- Dim hMenu As Long
- Dim lStyle As Long
- hwnd = FindWindow(vbNullString, Me.Caption)
- lStyle = GetWindowLong(hwnd, GWL_STYLE)
- lStyle = lStyle Or WS_MAXIMIZEBOX Or WS_MINIMIZEBOX
- SetWindowLong hwnd, GWL_STYLE, lStyle
- hMenu = GetSystemMenu(hwnd, 0)
- EnableMenuItem hMenu, 6, MF_BYPOSITION Or MF_DISABLED Or MF_GRAYED
- End Sub
- Private Sub UserForm_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
- Unload Me
- End Sub
复制代码 |
|