Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close Button in VB6 Forms

Status
Not open for further replies.

ysommer

Programmer
Feb 26, 2001
45
Hi!

How do I remove the close button in the control box of a vb6 Form?

Tnx,
Yoel
 

Paste the code below into your project and call:
DisableCloseButton Me

Note that the program will still close by pressing Alt+F4.

Sunaj


------------------------------------------------------------
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 Const MF_BYPOSITION = &H400&

Public Function DisableCloseButton(frm As Form) As Boolean

'PURPOSE: Removes X button from a form
'EXAMPLE: DisableCloseButton Me
'RETURNS: True if successful, false otherwise
'NOTES: Also removes Exit Item from
' Control Box Menu


Dim lHndSysMenu As Long
Dim lAns1 As Long, lAns2 As Long


lHndSysMenu = GetSystemMenu(frm.hwnd, 0)

'remove close button
lAns1 = RemoveMenu(lHndSysMenu, 6, MF_BYPOSITION)

'Remove seperator bar
lAns2 = RemoveMenu(lHndSysMenu, 5, MF_BYPOSITION)

'Return True if both calls were successful
DisableCloseButton = (lAns1 <> 0 And lAns2 <> 0)

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top