Disable Close button on form

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Mar 2008
Posts: 173
Reputation: Lukezzz is an unknown quantity at this point 
Solved Threads: 1
Lukezzz Lukezzz is offline Offline
Junior Poster

Disable Close button on form

 
0
  #1
May 12th, 2009
How would it be possible to disable the closebutton(X) in the upper right corner of the form.
I dont want to use this property because it takes the minimize and maximize button away also.
  1. ControlBox = false;

The only thing I will need on the form is the minimizebutton.
I can find separate properties for the minimizebutton and maximizebutton but not for the (X) button.
Last edited by Lukezzz; May 12th, 2009 at 10:09 pm.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,568
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 196
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: Disable Close button on form

 
0
  #2
May 12th, 2009
[Warning: This is coming from a Java programmer with no C++ experience]

Assuming that clicking 'X' generates an event, and C++ has method overriding - override the method that closes the window when the user clicks 'X', and do nothing in that method. That way, nothing will happen when the 'X' is clicked.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 173
Reputation: Lukezzz is an unknown quantity at this point 
Solved Threads: 1
Lukezzz Lukezzz is offline Offline
Junior Poster

Re: Disable Close button on form

 
0
  #3
May 13th, 2009
The problem is that I have put "Exit" in the File menu that will be used to close the window and the application like:
  1. this->Close();

So I cant if that is possible to not close the form in that event.

I still need to disable or remove the close(X) from the form in somehow.


Originally Posted by BestJewSinceJC View Post
[Warning: This is coming from a Java programmer with no C++ experience]

Assuming that clicking 'X' generates an event, and C++ has method overriding - override the method that closes the window when the user clicks 'X', and do nothing in that method. That way, nothing will happen when the 'X' is clicked.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 360
Reputation: jencas is just really nice jencas is just really nice jencas is just really nice jencas is just really nice jencas is just really nice 
Solved Threads: 69
jencas jencas is offline Offline
Posting Whiz

Re: Disable Close button on form

 
0
  #4
May 13th, 2009
Give us a little chance and tell us what GUI you are using?
If you are forced to reinvent the wheel at least try to invent a better one!

Please use code tags - Please mark solved threads as solved
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 173
Reputation: Lukezzz is an unknown quantity at this point 
Solved Threads: 1
Lukezzz Lukezzz is offline Offline
Junior Poster

Re: Disable Close button on form

 
0
  #5
May 13th, 2009
Yes ofcourse, I forgot to tell this.

I use Visual C++ 2008 Express Edition. I am googling around but I have problem to find a direct solution for this.


Originally Posted by jencas View Post
Give us a little chance and tell us what GUI you are using?
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 320
Reputation: cikara21 is an unknown quantity at this point 
Solved Threads: 63
cikara21's Avatar
cikara21 cikara21 is offline Offline
Posting Whiz

Re: Disable Close button on form

 
0
  #6
May 13th, 2009
  1.  
  2. // extra variable
  3. Boolean can_exit;
  4.  
  5. // form closing
  6. if(!can_exit)
  7. e->Cancel::set(true);
  8.  
  9. // button exit click
  10. can_exit = true;
  11.  
  12. this->Close();
  13.  
  14. // form load
  15. can_exit = false;
hope that helps..
Last edited by cikara21; May 13th, 2009 at 12:46 pm.
.:-cikara21-:.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 173
Reputation: Lukezzz is an unknown quantity at this point 
Solved Threads: 1
Lukezzz Lukezzz is offline Offline
Junior Poster

Re: Disable Close button on form

 
0
  #7
May 13th, 2009
It seems to work almost, I have to ask here.
I have succeded to put this as a global variable:
bool can_exit;
In the closing event of the form, I have put this code:
if(!can_exit)
   e->Cancel::set(true);
In the Load event of the form, I have put this code:
can_exit = false;

But I dont understand where to put this code:
// button exit click
can_exit = true;

I have never found an event for the close(x) button but perheps there is one ? I wonder if that code will be put in that event in that case.

However if I put the other code in place, nothing happens when I click the close(X) button wich is perfect.
However when I press a button on the form that tries to close the form(below code), nothing happens but perheps that has to do with the code that I wonder where to put:
  1. this->Close();

this->Close();
Originally Posted by cikara21 View Post
  1.  
  2. // extra variable
  3. Boolean can_exit;
  4.  
  5. // form closing
  6. if(!can_exit)
  7. e->Cancel::set(true);
  8.  
  9. // button exit click
  10. can_exit = true;
  11.  
  12. this->Close();
  13.  
  14. // form load
  15. can_exit = false;
hope that helps..
Last edited by Lukezzz; May 13th, 2009 at 3:31 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 173
Reputation: Lukezzz is an unknown quantity at this point 
Solved Threads: 1
Lukezzz Lukezzz is offline Offline
Junior Poster

Re: Disable Close button on form

 
0
  #8
May 13th, 2009
I just understood that I will put that code in the event for the button that will close the form:

Many thanks for this help...

  1. // button exit click
  2. can_exit = true;
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC