有个vb6程序,现在想控制Form上的右上角关闭按钮
想让这个按钮根据需要,在程序运行过程中显示或者非显示
我试了一下,在窗体的属性栏里改Form.ControlBox的True/False值可以使Form起来后关闭按钮显示或非显示
但把Form.ControlBox=True或Form.ControlBox=False放在程序中写,编译就有问题。
我看了msdn了,上面就是直接给Form.ControlBox赋值的,不知道为什么编译过不去。我想要控制该怎么控制啊,大家有什么办法,谢谢!

解决方案 »

  1.   

    http://topic.csdn.net/t/20020516/10/726315.html
      

  2.   

    ControlBox只能在设计时修改,运行时是只读的。
      

  3.   

    我看了csdn了,ControlBox是只读的
    不过vb,net写的是可以赋值的,vb6居然不行,郁闷了Visual Basic (使用方式)
    Dim instance As Form
    Dim value As Booleanvalue = instance.ControlBox
    instance.ControlBox = value
      

  4.   

    先谢谢楼上两位,这个问题我解决了
    调用的API实现的,我把代码贴出来,结贴了
    还得说一句,这段代码是转载,也许大家会碰到类似问题,参考一下吧
    再次感谢楼上两位
    以下是调用API实现控制表单控件菜单上的关闭选项的代码:Option Explicit      'Menu item constants.
          Private Const SC_CLOSE       As Long = &HF060&      'SetMenuItemInfo fMask constants.
          Private Const MIIM_STATE     As Long = &H1&
          Private Const MIIM_ID        As Long = &H2&      'SetMenuItemInfo fState constants.
          Private Const MFS_GRAYED     As Long = &H3&
          Private Const MFS_CHECKED    As Long = &H8&      'SendMessage constants.
          Private Const WM_NCACTIVATE  As Long = &H86      'User-defined Types.
          Private Type MENUITEMINFO
              cbSize        As Long
              fMask         As Long
              fType         As Long
              fState        As Long
              wID           As Long
              hSubMenu      As Long
              hbmpChecked   As Long
              hbmpUnchecked As Long
              dwItemData    As Long
              dwTypeData    As String
              cch           As Long
          End Type      'Declarations.
          Private Declare Function GetSystemMenu Lib "user32" ( _
              ByVal hwnd As Long, ByVal bRevert As Long) As Long      Private Declare Function GetMenuItemInfo Lib "user32" Alias _
              "GetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, _
              ByVal b As Boolean, lpMenuItemInfo As MENUITEMINFO) As Long      Private Declare Function SetMenuItemInfo Lib "user32" Alias _
              "SetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, _
              ByVal bool As Boolean, lpcMenuItemInfo As MENUITEMINFO) As Long      Private Declare Function SendMessage Lib "user32" Alias _
              "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
              ByVal wParam As Long, lParam As Any) As Long      'Application-specific constants and variables.
          Private Const xSC_CLOSE  As Long = -10
          Private Const SwapID     As Long = 1
          Private Const ResetID    As Long = 2      Private hMenu  As Long
          Private MII    As MENUITEMINFO      Private Sub Command1_Click()
              Dim Ret As Long          Ret = SetId(SwapID)
              If Ret <> 0 Then              If MII.fState = (MII.fState Or MFS_GRAYED) Then
                      MII.fState = MII.fState - MFS_GRAYED
                  Else
                      MII.fState = (MII.fState Or MFS_GRAYED)
                  End If              MII.fMask = MIIM_STATE
                  Ret = SetMenuItemInfo(hMenu, MII.wID, False, MII)
                  If Ret = 0 Then
                      Ret = SetId(ResetID)
                  End If              Ret = SendMessage(Me.hwnd, WM_NCACTIVATE, True, 0)
                  SetButtons
              End If
          End Sub      Private Sub Command2_Click()
              Dim Ret As Long          If MII.fState = (MII.fState Or MFS_CHECKED) Then
                  MII.fState = MII.fState - MFS_CHECKED
              Else
                  MII.fState = (MII.fState Or MFS_CHECKED)
              End If          MII.fMask = MIIM_STATE
              Ret = SetMenuItemInfo(hMenu, MII.wID, False, MII)
              SetButtons
          End Sub      Private Sub Command3_Click()
              Unload Me
          End Sub      Private Function SetId(Action As Long) As Long
              Dim MenuID As Long
              Dim Ret As Long          MenuID = MII.wID
              If MII.fState = (MII.fState Or MFS_GRAYED) Then
                  If Action = SwapID Then
                      MII.wID = SC_CLOSE
                  Else
                      MII.wID = xSC_CLOSE
                  End If
              Else
                  If Action = SwapID Then
                      MII.wID = xSC_CLOSE
                  Else
                      MII.wID = SC_CLOSE
                  End If
              End If          MII.fMask = MIIM_ID
              Ret = SetMenuItemInfo(hMenu, MenuID, False, MII)
              If Ret = 0 Then
                  MII.wID = MenuID
              End If
              SetId = Ret
          End Function      Private Sub SetButtons()
              If MII.fState = (MII.fState Or MFS_GRAYED) Then
                  Command1.Caption = "Enable"
              Else
                  Command1.Caption = "Disable"
              End If
              If MII.fState = (MII.fState Or MFS_CHECKED) Then
                  Command2.Caption = "Uncheck"
              Else
                  Command2.Caption = "Check"
              End If
          End Sub      Private Sub Form_Load()
              Dim Ret As Long          hMenu = GetSystemMenu(Me.hwnd, 0)
              MII.cbSize = Len(MII)
              MII.dwTypeData = String(80, 0)
              MII.cch = Len(MII.dwTypeData)
              MII.fMask = MIIM_STATE
              MII.wID = SC_CLOSE
              Ret = GetMenuItemInfo(hMenu, MII.wID, False, MII)
              SetButtons
              Command3.Caption = "Exit"
          End Sub