Results 1 to 6 of 6

Thread: disabling close button

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Location
    Italy
    Posts
    90

    disabling close button

    Hi everyone,
    do you know how to disable the close button on a window?
    (think this one is really a FAQ).

  2. #2
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177
    Don't remember where I found this so I can't give anyone the credit. Don't think I have ever even used it. I hope it works for you.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetSystemMenu Lib "user32" _
    4.     (ByVal hwnd As Long, _
    5.      ByVal bRevert As Long) As Long
    6.  
    7. Private Declare Function RemoveMenu Lib "user32" _
    8.     (ByVal hMenu As Long, _
    9.      ByVal nPosition As Long, _
    10.      ByVal wFlags As Long) As Long
    11.      
    12. Private Const MF_BYPOSITION = &H400&
    13.  
    14. Public Function DisableCloseButton(frm As Form) As Boolean
    15.  
    16. 'PURPOSE: Removes X button from a form
    17. 'EXAMPLE: DisableCloseButton Me
    18. 'RETURNS: True if successful, false otherwise
    19. 'NOTES:   Also removes Exit Item from
    20. '         Control Box Menu
    21.  
    22.  
    23.     Dim lHndSysMenu As Long
    24.     Dim lAns1 As Long, lAns2 As Long
    25.    
    26.    
    27.     lHndSysMenu = GetSystemMenu(frm.hwnd, 0)
    28.  
    29.     'remove close button
    30.     lAns1 = RemoveMenu(lHndSysMenu, 6, MF_BYPOSITION)
    31.  
    32.    'Remove seperator bar
    33.     lAns2 = RemoveMenu(lHndSysMenu, 5, MF_BYPOSITION)
    34.    
    35.     'Return True if both calls were successful
    36.     DisableCloseButton = (lAns1 <> 0 And lAns2 <> 0)
    37.  
    38. End Function

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Location
    Italy
    Posts
    90

    but AL+F4?

    It works, but ALT+F4 still works... Any Idea on how to disable this?

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Location
    Italy
    Posts
    90

    found...

    It is just enought to set
    Cancel = True
    in the Form Query_unload function.

    Thanks.

  5. #5
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177
    I thought about that, but you specifically asked about the Close button.

    What exactly do you want to do? Will you be testing for specific values in UnloadMode?

  6. #6
    Member
    Join Date
    Mar 2002
    Posts
    38

    It is eeeeeeasy!

    $$$$$$
    Last edited by phool312; Jan 29th, 2013 at 08:13 PM.

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