Results 1 to 1 of 1

Thread: VB - Disable the "X" of your form

  1. #1

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    VB - Disable the "X" of your form

    This will disable the "X" of the window.

    VB Code:
    1. 'in a module
    2. Public Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
    3.  
    4. Public Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
    5.  
    6. Public Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
    7.  
    8. Public Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
    9.  
    10. Public Const MF_REMOVE = &H1000&
    11. Public Const MF_INSERT = &H0&
    12. Public Const MF_ENABLED = &H0&
    13. Public Const MF_BYPOSITION = &H400&
    14.  
    15. Public Sub DisableX(frm As Form, blnDisabled As Boolean)
    16.     Dim hMenu As Long
    17.     Dim nCount As Long
    18.    
    19.     If blnDisabled = True Then
    20.         hMenu = GetSystemMenu(frm.hwnd, 0)
    21.         nCount = GetMenuItemCount(hMenu)
    22.         Call RemoveMenu(hMenu, nCount - 1, MF_REMOVE Or MF_BYPOSITION)
    23.         Call RemoveMenu(hMenu, nCount - 2, MF_REMOVE Or MF_BYPOSITION)
    24.         DrawMenuBar frm.hwnd
    25.     Else
    26.         hMenu = GetSystemMenu(frm.hwnd, True)
    27.         DrawMenuBar frm.hwnd
    28.     End If
    29. End Sub
    30.  
    31. Private Sub Form_Load()
    32. ' this goes in the form_load or a command button or something
    33. Call DisableX(Me, True)
    34. End Sub
    Last edited by manavo11; Aug 2nd, 2005 at 07:35 PM. Reason: Found better code


    Has someone helped you? Then you can Rate their helpful post.

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