Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC8.0
Close(X) button is not working in the dialog? When pressing the X button in the dialog, it is not closing the dialog and also added command button in the dialog, added codes for cancel, still the dialog is not getting closed.
Posted 5-May-11 21:25pm
Edited 5-May-11 22:09pm
Comments
Niklas Lindquist at 6-May-11 2:34am
   
Is this MFC or plain Win32?
Gokulnath007 at 6-May-11 2:39am
   
MFC
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Do you have a handler for WM_CLOSE? If you don't call CDialog::OnClose() this will prevent it from closing.
  Permalink  
Comments
SAKryukov at 6-May-11 7:18am
   
Sure it wouldn't close. A 5.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hello.
You don't need to handle WM_CLOSE,
Did you overload a OnCancel()fuction?
If there isn't, you have to overload OnCancel() function and add this code
 
CDialog::OnCancel();
 
You can do as bellow.
First you create button named IDCANCEL.
and from IDCANCEL, define OnCancel()function.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Above mentioned solutions are answers to your question, i am just adding to it..
 
Whenever you start with a MFC Dialog based application.
You are given a dialog with two buttons OK & CANCEL.
Clicking either of them when your program is executed will exit the application.
Many times we don't need them & so we delete them, then the problem would be that your application will exit even on clicking a ENTER or ESC key from keyboard.
 
So you can do the following
1. Double click both the OK & CANCEL button, you will have two function created for ID_OK & ID_CANCEL (assumed to be Ids of your OK & CANCEL button).
2. Commenting OnOK() in the function created for ID_OK will prevent your application from exiting when an ENTER key is hit when your application is running.
3. In the function created for ID_CANCEL you can call a message box asking user whether to exit the application or not & based on the input act accordingly.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

It always close the window unless you have artificially overridden this behavior or simply screwed up. I have no information to tell you how.
 
—SA
  Permalink  
Comments
Niklas Lindquist at 6-May-11 4:08am
   
Nothing wrong with this answer, and it's perfectly valid. Fixing the score.
SAKryukov at 6-May-11 7:15am
   
Thank you, Niklas.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 475
1 Maciej Los 349
2 Richard MacCutchan 220
3 BillWoodruff 219
4 Mathew Soji 160
0 OriginalGriff 8,759
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,269
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411028.1 | Last Updated 11 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100