943,724 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 601
  • C++ RSS
May 13th, 2009
0

getting decission from message box?

Expand Post »
hi guys, new to c++ here. So we have a school project due tomorrow, a hangman game of sort and i just wanted to go a bit above the required so i thought i would put in a message box. Now i got the working and all but the thing is, i would like to figure out that if the user clicks NO then the program exits? how can i do this?

C++ Syntax (Toggle Plain Text)
  1. LPCTSTR Cap = L"HOW TO PLAY HANGMAN";
  2. MessageBox(NULL, L"sample",Cap, MB_YESNOCANCEL );

as you can see, my msg box has 3 click able buttons, YES NO and CANCLE. How can i make my program do something is say NO is pressed?

like
if NO is pressed
exit


thank you!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cruisx is offline Offline
19 posts
since Dec 2007
May 13th, 2009
0

Re: getting decission from message box?

It's in the return value. Read the MSDN page.
Reputation Points: 888
Solved Threads: 114
Nearly a Posting Virtuoso
MosaicFuneral is offline Offline
1,270 posts
since Nov 2008
May 14th, 2009
0

Re: getting decission from message box?

It's the same as for AfxMessageBox: http://msdn.microsoft.com/en-us/libr...cb(VS.71).aspx
Reputation Points: 395
Solved Threads: 71
Posting Whiz
jencas is offline Offline
362 posts
since Dec 2007
May 14th, 2009
-1

Re: getting decission from message box?

C++ Syntax (Toggle Plain Text)
  1. int DisplayMessageBox()
  2. {
  3. int msgboxID = MessageBox(
  4. NULL,
  5. (LPCWSTR)L"Sample",
  6. Cap,
  7. MB_YESNOCANCEL
  8. );
  9.  
  10. switch (msgboxID)
  11. {
  12. case IDCANCEL:
  13. // TODO: add code
  14. break;
  15. case IDYES:
  16. // TODO: add code
  17. break;
  18. case IDNO:
  19. // TODO: add code
  20. break;
  21. }
  22.  
  23. return msgboxID;
  24. }
Last edited by Narue; May 14th, 2009 at 3:54 pm. Reason: added code tags
Reputation Points: 39
Solved Threads: 24
Junior Poster
dubeyprateek is offline Offline
176 posts
since Mar 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: changing fonts?
Next Thread in C++ Forum Timeline: Can a method have have internal linkage?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC