iNET Interactive - Online Advertising Agency
          
Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Interface and Graphics > Disable Exit Button???


Reply
 
Thread Tools Display Modes
  #1  
Old 02-24-2003, 11:55 PM
eilrach's Avatar
eilrach eilrach is offline
Centurion
 
Join Date: Feb 2003
Location: Philippines
Posts: 169
Question 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
Reply With Quote
  #2  
Old 02-25-2003, 01:29 AM
BostjanK's Avatar
BostjanK BostjanK is offline
Junior Contributor
 
Join Date: Feb 2003
Location: Ljubljana, Slovenia
Posts: 324
Default

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
Reply With Quote
  #3  
Old 02-25-2003, 03:09 AM
Flyguy's Avatar
Flyguy Flyguy is offline
Lost Soul

Preferred language:
Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 17,572
Default

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
Reply With Quote
  #4  
Old 02-25-2003, 03:32 AM
eilrach's Avatar
eilrach eilrach is offline
Centurion
 
Join Date: Feb 2003
Location: Philippines
Posts: 169
Default 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
Reply With Quote
  #5  
Old 02-25-2003, 05:21 AM
italkid's Avatar
italkid italkid is offline
Down...

Preferred language:
Retired Moderator
* Expert *
 
Join Date: Dec 2002
Location: Belgium.
Posts: 6,729
Default Disable X

Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) If UnloadMode = 0 Then Cancel = True End If End Sub

italkid.
Reply With Quote
  #6  
Old 02-25-2003, 08:23 AM
Flyguy's Avatar
Flyguy Flyguy is offline
Lost Soul

Preferred language:
Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 17,572
Default

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
Reply With Quote
  #7  
Old 02-25-2003, 06:59 PM
eilrach's Avatar
eilrach eilrach is offline
Centurion
 
Join Date: Feb 2003
Location: Philippines
Posts: 169
Default

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
Reply With Quote
  #8  
Old 03-04-2003, 06:35 PM
GoRedskins11_2
Guest
 
Posts: n/a
Wink

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
Reply With Quote
  #9  
Old 03-04-2003, 07:19 PM
eilrach's Avatar
eilrach eilrach is offline
Centurion
 
Join Date: Feb 2003
Location: Philippines
Posts: 169
Default

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
Reply With Quote
  #10  
Old 03-10-2004, 08:11 AM
InteL InteL is offline
Newcomer
 
Join Date: Nov 2003
Location: Kalmar, Sweden
Posts: 6
Default

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 !
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement: