disable "X" (close button) in ControlBox 
Author Message
 disable "X" (close button) in ControlBox

I am interested in removing the functionality of the close button in the
ControlBox and the "X" in the upper right corner of forms.  Anyone know how?
I still want to be able to maximize & minimize the windows.

Thanks in advance,

Mike




Sat, 14 Jul 2001 03:00:00 GMT  
 disable "X" (close button) in ControlBox

look at:

http://www.mvps.org/vbnet/code/system/killclose.htm

Matthew Cromer



Sun, 15 Jul 2001 03:00:00 GMT  
 disable "X" (close button) in ControlBox

Quote:

>I am interested in removing the functionality of the close button in the
>ControlBox and the "X" in the upper right corner of forms.  Anyone know how?
>I still want to be able to maximize & minimize the windows.

Disable the system menu.  This will remove the icon in the upper left
corner, as well.  Note: you can only disable the X box, you can't remove
it.

Don't know how to do it at design time or without the API.
The API solution (look up the Declare's and Const's):

Dim style As Long

style = GetWindowLong(form.hwnd, GWL_STYLE)
style = style Xor WS_SYSMENU
SetWindowLong form.hwnd, GWL_STYLE, style
' The following will force an immediate "frame" update
RedrawWindow form.hwnd, 0&, 0&, RDW_FRAME Or _
        RDW_INVALIDATE Or RDW_UPDATENOW

=====

Haven't yet tried the CS_NOCLOSE approach with Get/SetClassLong and
GCL_STYLE.  This approach may alter all forms.

Henry S. Takeuchi

Seattle, Washington (USA)



Mon, 16 Jul 2001 03:00:00 GMT  
 disable "X" (close button) in ControlBox
you might try this:
****************************
Declare Function GetSystemMenu Lib "user32" Alias "GetSystemMenu" (ByVal
hwnd As Long, ByVal bRevert As Long) As Long
Declare Function GetMenuItemCount Lib "user32" Alias "GetMenuItemCount"
(ByVal hMenu As Long) As Long
Declare Function RemoveMenu Lib "user32" Alias "RemoveMenu" (ByVal hMenu As
Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Declare Function DrawMenuBar Lib "user32" Alias "DrawMenuBar" (ByVal hwnd As
Long) As Long

Public Const MF_BYPOSITION = &H400&
Public Const MF_REMOVE = &H1000&

******************

'Add this subroutine:
Public Sub DisableX(frm As Form)

Dim hMenu As Long
Dim nCount As Long
hMenu = GetSystemMenu(frm.hWnd, 0)
nCount = GetMenuItemCount(hMenu)

'Get rid of the Close menu and its separator
Call RemoveMenu(hMenu, nCount - 1, MF_REMOVE Or MF_BYPOSITION)
Call RemoveMenu(hMenu, nCount - 2, MF_REMOVE Or MF_BYPOSITION)

'Make sure the screen updates the change
DrawMenuBar frm.hWnd

End Sub



Mon, 16 Jul 2001 03:00:00 GMT  
 disable "X" (close button) in ControlBox
I dont know if this is really relative, but how do you add/remove stuff from the
System Menu??

Peter Dey
Nemesis

Quote:

> you might try this:
> ****************************
> Declare Function GetSystemMenu Lib "user32" Alias "GetSystemMenu" (ByVal
> hwnd As Long, ByVal bRevert As Long) As Long
> Declare Function GetMenuItemCount Lib "user32" Alias "GetMenuItemCount"
> (ByVal hMenu As Long) As Long
> Declare Function RemoveMenu Lib "user32" Alias "RemoveMenu" (ByVal hMenu As
> Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
> Declare Function DrawMenuBar Lib "user32" Alias "DrawMenuBar" (ByVal hwnd As
> Long) As Long

> Public Const MF_BYPOSITION = &H400&
> Public Const MF_REMOVE = &H1000&

> ******************

> 'Add this subroutine:
> Public Sub DisableX(frm As Form)

> Dim hMenu As Long
> Dim nCount As Long
> hMenu = GetSystemMenu(frm.hWnd, 0)
> nCount = GetMenuItemCount(hMenu)

> 'Get rid of the Close menu and its separator
> Call RemoveMenu(hMenu, nCount - 1, MF_REMOVE Or MF_BYPOSITION)
> Call RemoveMenu(hMenu, nCount - 2, MF_REMOVE Or MF_BYPOSITION)

> 'Make sure the screen updates the change
> DrawMenuBar frm.hWnd

> End Sub



Wed, 18 Jul 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. How to disable the "close" button

2. Disabling "close button" in a form

3. Disabling "BACK"/"FORWARD" buttons

4. Disabling "BACK"/"FORWARD" buttons

5. Disable Application Quit ("X") Button

6. Disable "Add button" from toolbar

7. Disable the "Insert" Button

8. How to disable "PrintScreen" button

9. Disable "Back" Button

10. How to disable the "Back" button

11. how do I disable controlbox exit button "X" and keep the min max buttons

12. Prevent Close ("X") Button under 95

 

 
Powered by phpBB® Forum Software