Click here to Skip to main content
Rate this: bad
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
Niklas Lindquist at 6-May-11 2:34am
Is this MFC or plain Win32?
Gokulnath007 at 6-May-11 2:39am
Rate this: bad
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.
SAKryukov at 6-May-11 7:18am
Sure it wouldn't close. A 5.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

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
You can do as bellow.
First you create button named IDCANCEL.
and from IDCANCEL, define OnCancel()function.
Rate this: bad
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.
Rate this: bad
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.
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.

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

  Print Answers RSS
0 Zoltán Zörgő 320
1 CHill60 185
2 /\jmot 160
3 Peter Leow 160
4 Pikoh 125
0 Sergey Alexandrovich Kryukov 9,423
1 OriginalGriff 6,891
2 Peter Leow 4,637
3 Zoltán Zörgő 4,304
4 CHill60 2,932

Advertise | Privacy | Mobile
Web01 | 2.8.150129.1 | Last Updated 11 Dec 2012
Copyright © CodeProject, 1999-2015
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