CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 1999
    Location
    California
    Posts
    264

    How can I disable the close button of a form??

    How can I disable the close button of a form? And How can I disable the close item in system menu?

    Thank you for your help!

    Best Regards,

    Kevin Shen
    Best Regards,

    Kevin Shen

  2. #2
    Join Date
    Jul 2001
    Location
    maharashtra,india
    Posts
    181

    Re: How can I disable the close button of a form??

    'Cancel.Txt
    'Disables the Cancel icon from you VB window

    'Declarations Section
    Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, ByVal bRevert As Long) As Long
    Private Declare Function ModifyMenu Lib "user32" Alias "ModifyMenuA" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpString As Any) As Long
    Private Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long

    Const MF_BYPOSITION = &H400&
    Const MF_GRAYED = &H1&
    Const MF_BYCOMMAND = &H0&

    Private Sub Form_Load()
    ' Disable the Close button on load
    Dim hwndParent As Long
    hwndParent = Me.hWnd
    DisableItem hwndParent, "&Close", 6
    'Disable button before Showing form so that form displays with button already disabled
    Me.Show
    End Sub

    Sub DisableItem(hWnd As Long, sMenuCaption As String, iMenuPos As Integer)
    'User-defined function to disable the Close button on the
    'MDI Child Form toolbar.
    Dim hMenu As Long
    Dim hItem As Long

    hMenu = GetSystemMenu(hWnd, 0)
    hItem = GetMenuItemID(hMenu, iMenuPos)
    ModifyMenu hMenu, hItem, MF_BYCOMMAND Or MF_GRAYED, -9, sMenuCaption
    End Sub



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured