CodeItBetter Programming Another VB Programming Blog

How to Enable/Disable Close Button in a form

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
'Forms - How to Enable/Disable Close Button in a form
Option Explicit
 
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, _
    ByVal bRevert As Long) As Long
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, _
    ByVal nPosition As Long, ByVal wFlags As Long) As Long
Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
 
Private Const MF_BYCOMMAND = &H0&
Private Const SC_CLOSE = &HF060&
 
Public Sub SetXState(frm As Form, blnState As Boolean)
    Dim hMenu As Long
    hMenu = GetSystemMenu(frm.hwnd, blnState)
    Call RemoveMenu(hMenu, SC_CLOSE, MF_BYCOMMAND)
    Call DrawMenuBar(frm.hwnd)
End Sub
 
Private Sub Command1_Click()
    'To Disable X button in a form
    Call SetXState(Me, False)
 
    'To Enable X button in a form
    Call SetXState(Me, True)
End Sub

Related posts:

  1. How to Enable And Disable The Ctrl+Alt+Del
  2. How to restrict the user not to move the Form
  3. How to add a minimize Button to Form that has fixed Border
  4. How to Enable/Disable Mouse trails
  5. How to Enable/Disable all Controls in a frame
  6. How to Enable/Disable Task Manager
  7. How to add Bitmaps to Menu
  8. How to enable/disable the frame if checkbox is selected/deselected
  9. How to enable or disable the Cut, Copy and Paste menus in Edit menu if the text selected or not in a control.
  10. How to enable/disable submenus of Edit menu (Copy, Cut, Clear, Undo, and so on) based on text selection

Filed under: Forms Leave a comment
Comments (1) Trackbacks (0)
  1. thank you very much, it works


Leave a comment


No trackbacks yet.