Visual C++ Problem
Hi I am taking a course with confederation collage and am writing a program to draw free hand. I am done exept for the exit code. In thew assignment outline it states
"When the user clicks on the exit button a message appers that says ''Are you sure you want to exit? y/n''. Whent he user clicks no a message appers that says ''Thank you for not exiting...''when the user clicks on yes the program termanates.''
I have everything exept for the exit function. it says that the OnOK(); function i usually use is not part of the program. does anyyone have an alternative to the OnOK(); funstion??
Here is the exit code I have so far:
int iResult;
iResult = MessageBox("Are you sure you want to exit? y/n", NULL, MB_ICONQUESTION + MB_YESNO);
if(iResult == IDYES)
OnOK();
else
MessageBox("Thank you for not exiting...");
-----------------------------
-------Mitch Mulholland------
----A.K.A.= TwisteR----------
-----------------------------
------------------------------------Mitch Mulholland----------A.K.A.= TwisteR---------------------------------------
If this is a dialog:
CDialog::OnOK();
If this is a doc/view:
CWnd::OnClose();
Theoretically you should be overloading the WM_CLOSE message where you are... are you?
I put in the MFC version because you''re using the MFC version of MessageBox, so I assume you''re using MFC.
-fel
CDialog::OnOK();
If this is a doc/view:
CWnd::OnClose();
Theoretically you should be overloading the WM_CLOSE message where you are... are you?
I put in the MFC version because you''re using the MFC version of MessageBox, so I assume you''re using MFC.
-fel
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
Hi,
There is another way to exit (I hope it could be of help)
You can include either "stdlib.h" or "stdio.h" (I''m not sure, just change when it throws up an error). Then simply use the exit() function. Remember to enter a parameter too as an int. 1 = it exited with an error, 0 = without error.
Well I hop this might help.
----------=Last Attacker=----------
ICQ: 120585863
E-mail: laextr@icqmail.com
There is another way to exit (I hope it could be of help)
You can include either "stdlib.h" or "stdio.h" (I''m not sure, just change when it throws up an error). Then simply use the exit() function. Remember to enter a parameter too as an int. 1 = it exited with an error, 0 = without error.
Well I hop this might help.
----------=Last Attacker=----------
ICQ: 120585863
E-mail: laextr@icqmail.com
"Take delight in the Lord and He will give you your heart's desires" - Psalm 37:4My Blog
quote:
Original post by Last Attacker
Hi,
There is another way to exit (I hope it could be of help)
You can include either "stdlib.h" or "stdio.h" (I''m not sure, just change when it throws up an error). Then simply use the exit() function. Remember to enter a parameter too as an int. 1 = it exited with an error, 0 = without error.
Well I hop this might help.
It doesn''t help at all! Using the DOS exit() function will probably leave you with all sorts of undestroyed window structures and inaccessible memory.
As felisandria has pointed out, the OnOK() function is a part of the MFC framework and must be called through MFC objects or static methods. The best solution is not to use a MessageBox but rather to derive your own CDialog-based dialog class. I presume you''re using MSVC and MFC; modify the instructions as appropriate if you aren''t.
Use Resource Editor to create a new Dialog box. Place all the labels and buttons you want on it, then open ClassWizard (while your dialog is still open). It should prompt you to create a class for the new dialog resource. Agree and name the class, then add variables as necessary - I would add a CString variable to be mapped to a label on the dialog. Upon initialization of the form (in the dialog class'' constructor), the string would be set to "Are you sure you want to exit?". If the user hit OK, your OnOK() function would be called while if the use hit Cancel, your OnCancel() would be called.
Your OnOK() would need to terminate the application, performing whatever cleanup/shutdown code (such as saving or prompting to save) before optionally calling CDialog::OnOK().
Your OnCancel() is more interesting. I would change the contents of the CString member and redraw the dialog - without the other controls (this involves a knowledge of dynamic control creation/manipulation) - and use the system timer to wait a specified number of seconds before closing (CDialog::OnCancel()).
Of course, this solution might be overkill. If you''d like a fuller explanation or a sample implementation, mail me.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement