?
Solved

How do You disable the close button (x) on a VB6 Form?

Posted on 2003-03-01
11
Medium Priority
?
2,317 Views
Last Modified: 2008-02-01
How do You disable the close button (x) on a VB Form?

I need to have the control box on the VB6 Form, but I need to get simple code to disable the x on the top right hand side of the form (the close button)...

What is the easiest way to do disable the button?  I don't need to get rid of it, just disabled.

Thank You in Advance...

:)
0
Comment
Question by:FirstBorn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 6

Expert Comment

by:PlanetCpp
ID: 8049880
either
a:
set the ControlBox property of the form to false
you'll see that on the properties, you know where.
or..
go into the queryUnload event of the form and write
cancel = 1

you wont be able to close the program that way, you can click the x and itll loook enabled but you'll be canceling it each time
0
 
LVL 1

Author Comment

by:FirstBorn
ID: 8049894
Hi PlanetCpp,

Nope, I've found the code for this, but it was to actually disable the button (greys out the button) so that a user cannot click on it...

I'll have to have this question deleted...

Thanks again...

:)

Reference:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_10308322.html?query=disable+close+button+on+vb6+form&searchType=all
0
 
LVL 1

Expert Comment

by:Computer101
ID: 8049991
A request for deletion has been made.  If no response or you feel this is in error, comment.  If no objection, I will delete in three days.

Computer101
E-E Admin
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:FirstBorn
ID: 8050016
Hi Computer101,

No Error, No Objection to deleting this question... I found the code I was looking for using the Premium Search.  Therefore, this question can be deleted... :)

I apologize for confusion...

Thanks.

:)
0
 
LVL 4

Expert Comment

by:JRCSystems
ID: 8052882
Here is the best way:

Inside Form_QueryUnload ()

Put the following single line of code:

    Cancel = (Unloadmode = vbFormControlMenu)

Done!
0
 
LVL 1

Expert Comment

by:lucho_nd
ID: 8060931
Hi!!:

- If you only want the close button doesn't show, set ControlBox property to False.
- If you want the user can't close the window, set the Cancel parameter to 1 (in the events Unload o QueryUnload of the form)

good luck

lucho_nd
0
 
LVL 6

Expert Comment

by:PlanetCpp
ID: 8060948
lol noone reads past posts, 10 people repeated the same post and noone saw that this is marked for deletion, he already has the answer, he got it himself.
0
 

Expert Comment

by:originalrobby
ID: 8061566
lol
0
 

Expert Comment

by:BlueSky007
ID: 8063319
Try this code (is a very good code!!! I used before). Is disable the close button (X) and Close Menu from system menu!!! The form is imposible to close!


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

Private Sub Command1_Click()
Form1.Refresh
End Sub

Private Sub Form_Load()
DisableCloseButton Form1
End Sub

Create a form and issert this code and RUN IT! Don't try to compile and run without a Command Butoon with a End command! the single way to close the program si with CTRL-ALT-DEL and End Task! Go for it!
0
 
LVL 1

Expert Comment

by:aamironline
ID: 8080084
yes this one is the one that i also wanted to specify

cheers
m aamir maniar
0
 

Accepted Solution

by:
WesLennon earned 0 total points
ID: 8139687
As the question author noted he found his onw problem through PAQ's, the points will be refunded and placed in PAQ.

Wes Lennon
DoCS
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question