 |

02-24-2003, 11:55 PM
|
 |
Centurion
|
|
Join Date: Feb 2003
Location: Philippines
Posts: 169
|
|
Disable Exit Button???
|
|
Hi,
can someone post a sample code on how to disable the EXIT button @ the upper right corner of the form, i know that by using API, the EXIT button will disable, but i dont know how coz im a newbie in vb6.thanks in advance
the minimize and maximize button is enable, only the EXIT button is the one i want to disable.
|
__________________
"Let the programmers be many and the managers few - then all will be productive."
Tao of Programming
|

02-25-2003, 01:29 AM
|
 |
Junior Contributor
|
|
Join Date: Feb 2003
Location: Ljubljana, Slovenia
Posts: 324
|
|
I don't know about disabling the button, but you can use QueryUnload event of the form to cancel the unloading.
|
__________________
Slovenia - the green treasure of Europe
|

02-25-2003, 03:09 AM
|
 |
Lost Soul
Preferred language: Super Moderator * Guru *
|
|
Join Date: May 2001
Location: Vorlon
Posts: 17,572
|
|
|
|
Put this in a module:
Code:
Option Explicit
Private Const SC_CLOSE As Long = &HF060&
Private Const MIIM_STATE As Long = &H1&
Private Const MIIM_ID As Long = &H2&
Private Const MFS_GRAYED As Long = &H3&
Private Const WM_NCACTIVATE As Long = &H86
Private Type MENUITEMINFO
cbSize As Long
fMask As Long
fType As Long
fState As Long
wID As Long
hSubMenu As Long
hbmpChecked As Long
hbmpUnchecked As Long
dwItemData As Long
dwTypeData As String
cch As Long
End Type
Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, ByVal bRevert As Long) As Long
Private Declare Function GetMenuItemInfo Lib "user32" Alias "GetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, ByVal b As Boolean, lpMenuItemInfo As MENUITEMINFO) As Long
Private Declare Function SetMenuItemInfo Lib "user32" Alias "SetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, ByVal bool As Boolean, lpcMenuItemInfo As MENUITEMINFO) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function IsWindow Lib "user32" (ByVal hWnd As Long) As Long
Public Function EnableCloseButton(ByVal hWnd As Long, Enable As Boolean) As Integer
Const xSC_CLOSE As Long = -10
Dim hMenu As Long
Dim MII As MENUITEMINFO
Dim lngMenuID As Long
' Check that the window handle passed is valid
EnableCloseButton = -1
If IsWindow(hWnd) = 0 Then Exit Function
' Retrieve a handle to the window's system menu
hMenu = GetSystemMenu(hWnd, 0)
' Retrieve the menu item information for the close menu item/button
MII.cbSize = Len(MII)
MII.dwTypeData = String(80, 0)
MII.cch = Len(MII.dwTypeData)
MII.fMask = MIIM_STATE
If Enable Then
MII.wID = xSC_CLOSE
Else
MII.wID = SC_CLOSE
End If
EnableCloseButton = -0
If GetMenuItemInfo(hMenu, MII.wID, False, MII) = 0 Then Exit Function
' Switch the ID of the menu item so that VB can not undo the action itself
lngMenuID = MII.wID
If Enable Then
MII.wID = SC_CLOSE
Else
MII.wID = xSC_CLOSE
End If
MII.fMask = MIIM_ID
EnableCloseButton = -2
If SetMenuItemInfo(hMenu, lngMenuID, False, MII) = 0 Then Exit Function
' Set the enabled / disabled state of the menu item
If Enable Then
MII.fState = (MII.fState Or MFS_GRAYED)
MII.fState = MII.fState - MFS_GRAYED
Else
MII.fState = (MII.fState Or MFS_GRAYED)
End If
MII.fMask = MIIM_STATE
EnableCloseButton = -3
If SetMenuItemInfo(hMenu, MII.wID, False, MII) = 0 Then Exit Function
' Activate the non-client area of the window to update the titlebar, and
' draw the close button in its new state.
SendMessage hWnd, WM_NCACTIVATE, True, 0
EnableCloseButton = 0
End Function
|
__________________
Ego quoque nescio quid hic scriptum est
|

02-25-2003, 03:32 AM
|
 |
Centurion
|
|
Join Date: Feb 2003
Location: Philippines
Posts: 169
|
|
Thanks for the reply...
I'll try to test the code, and post the result.
do u have any other code that is simplier than the code that you post?all i need is a code that will disable the exit button only.
thanks again...
|
__________________
"Let the programmers be many and the managers few - then all will be productive."
Tao of Programming
|

02-25-2003, 05:21 AM
|
 |
Down...
Preferred language: Retired Moderator * Expert *
|
|
Join Date: Dec 2002
Location: Belgium.
Posts: 6,729
|
|
Disable X
Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If UnloadMode = 0 Then
Cancel = True
End If
End Sub
italkid.
|
|

02-25-2003, 08:23 AM
|
 |
Lost Soul
Preferred language: Super Moderator * Guru *
|
|
Join Date: May 2001
Location: Vorlon
Posts: 17,572
|
|
Quote:
|
do u have any other code that is simplier than the code that you post?all i need is a code that will disable the exit button only.
|
Argh...
Changing window forms styles on the fly is just not simple.
And you only have to cut and paste, how more simple do you want it?
|
__________________
Ego quoque nescio quid hic scriptum est
|

02-25-2003, 06:59 PM
|
 |
Centurion
|
|
Join Date: Feb 2003
Location: Philippines
Posts: 169
|
|
ooops... sorry flyguy, i thought there's simplier than the code you post, anyway, the code you post is running ang works fine in my projects, thanks again, im very sorry....
|
__________________
"Let the programmers be many and the managers few - then all will be productive."
Tao of Programming
|

03-04-2003, 06:35 PM
|
|
|
If you want some simple code to disable the X close button, simply add these declarations to the form and add the code below to the Form Load event of the form that you want to disable the button on:
Private Const SC_CLOSE As Long = &HF060&
Private Const MF_BYCOMMAND = &H0&
Private Declare Function DeleteMenu Lib "user32.dll" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Private Declare Function GetSystemMenu Lib "user32.dll" (ByVal hWnd As Long, ByVal bRevert As Long) As Long
Private Sub Form_Load()
DeleteMenu GetSystemMenu(Me.hWnd, False), SC_CLOSE, MF_BYCOMMAND
End Sub
|
|

03-04-2003, 07:19 PM
|
 |
Centurion
|
|
Join Date: Feb 2003
Location: Philippines
Posts: 169
|
|
thanks Goredskin, it works fine too.thanks for the help
|
__________________
"Let the programmers be many and the managers few - then all will be productive."
Tao of Programming
|

03-10-2004, 08:11 AM
|
|
Newcomer
|
|
Join Date: Nov 2003
Location: Kalmar, Sweden
Posts: 6
|
|
Or just:
Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Cancel = 1
End Sub
|
__________________
Må din bingolott fatta eld och brinna i all evighet !
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
| |
|