GetSystemMenu
和DeleteMenu一起使用

解决方案 »

  1.   

    Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
    Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
    Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
    Const MF_BYPOSITION = &H400&
    Const MF_REMOVE = &H1000&
    Private Sub Form_Load()
        Dim hSysMenu As Long, nCnt As Long
        ' Get handle to our form's system menu
        ' (Restore, Maximize, Move, close etc.)
        hSysMenu = GetSystemMenu(Me.hwnd, False)    If hSysMenu Then
            ' Get System menu's menu count
            nCnt = GetMenuItemCount(hSysMenu)
            If nCnt Then
                ' Menu count is based on 0 (0, 1, 2, 3...)
                RemoveMenu hSysMenu, nCnt - 1, MF_BYPOSITION Or MF_REMOVE
                RemoveMenu hSysMenu, nCnt - 2, MF_BYPOSITION Or MF_REMOVE ' Remove the seperator
                DrawMenuBar Me.hwnd
                ' Force caption bar's refresh. Disabling X button
                Me.Caption = "Try to close me!"
            End If
        End If
    End Sub
      

  2.   

    如何防止 Form 被移动?有些应用程序,我们希望固定 Form 的位置,不希望使用者移动它,在 VB5 以上的版本,我们可以直接在属性表中设定 Form 的 Moveable 属性为 False 即可。但是 VB4 以下的版本却没有这个功能,这时就得借助 API 的功能了!而我们实际要做的,就是移除系统功能表 ( ControlBox ) 中的【移动】的功能,您可以检查一下您现在使用的浏览器左上方的系统功能表,【移动】的位置是第二个,所以 Index = 1 ( index 由 0 算起 )。'请在表单的声明区中加入以下声明Private Declare Function GetSystemMenu Lib "User" (ByVal hWnd As Integer, ByVal bRevert As Integer) As Integer
    Private Declare Function RemoveMenu Lib "User" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As IntegerConst MF_BYPOSITION = &H400'在 Form_Load 事件中加入以下程序码Private Sub Form_Load()
    SystemMenu% = GetSystemMenu(hWnd, 0)
    Res% = RemoveMenu(SystemMenu%, 1, MF_BYPOSITION) <--- 第二个参数是 Index
    End Sub