[RESOLVED] close button-VBForums
Results 1 to 5 of 5

Thread: [RESOLVED] close button

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2011
    Posts
    214

    Resolved [RESOLVED] close button

    Hi friends

    I have a question about these 3 buttons(min,max,close) on the top corner of form; how can I have only min button available without close button.
    (the exit button that I ve on my form is not only ,unload me, or ,end , it does some other things before exit so I cant use X button)

    thank you in advance

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,082

    Re: close button

    Try this:

    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. Private Sub Form_Load()
    14. DisableCloseButton Me
    15. End Sub
    16. Public Function DisableCloseButton(frm As Form) As Boolean
    17.  
    18. 'PURPOSE: Removes X button from a form
    19. 'EXAMPLE: DisableCloseButton Me
    20. 'RETURNS: True if successful, false otherwise
    21. 'NOTES:   Also removes Exit Item from
    22. '         Control Box Menu
    23.  
    24.  
    25.     Dim lHndSysMenu As Long
    26.     Dim lAns1 As Long, lAns2 As Long
    27.    
    28.    
    29.     lHndSysMenu = GetSystemMenu(frm.hwnd, 0)
    30.  
    31.     'remove close button
    32.     lAns1 = RemoveMenu(lHndSysMenu, 6, MF_BYPOSITION)
    33.  
    34.    'Remove seperator bar
    35.     lAns2 = RemoveMenu(lHndSysMenu, 5, MF_BYPOSITION)
    36.    
    37.     'Return True if both calls were successful
    38.     DisableCloseButton = (lAns1 <> 0 And lAns2 <> 0)
    39.  
    40. End Function
    Last edited by Nightwalker83; Apr 15th, 2012 at 02:49 AM.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    Please consider giving me some rep points if I help you a lot.
    Links to my code examples can now be found on my website: My websites
    Please rate my post if you find it helpful!
    Technology is a dangerous thing in the hands of an idiot! I am that idiot.

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    11,409

    Re: close button

    It might be much cleaner to just move this blob of logic to Form_Unload and change your button event to Unload Me.

    This should solve the problem without the need for any foreign UI hacking that just adds confusion for users.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jul 2011
    Posts
    214

    Re: close button

    thank u for help,solved now

  5. #5
    New Member
    Join Date
    Apr 2012
    Posts
    10

    Re: [RESOLVED] close button

    I know this thread is marked as [Solved] but here's another thing you could have done/can do:
    Put everything you need to be done before the program ends into

    vb Code:
    1. Private Sub Form_QueryUnload()
    2.  
    3.     ' Your Code Here! :]
    4.  
    5. 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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.