MessageBox with OK and CancelButton

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Feb 2008
Posts: 517
Reputation: Jennifer84 is an unknown quantity at this point 
Solved Threads: 1
Jennifer84 Jennifer84 is offline Offline
Posting Pro

MessageBox with OK and CancelButton

 
0
  #1
Mar 4th, 2008
I am trying to create a DialogBox in C++ .NET with both an "OK" button and a "Cancel" Button.

I know how to just show a MessageBox with an "OK" button like this:
  1. MessageBox::Show(this, "Message");
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 517
Reputation: Jennifer84 is an unknown quantity at this point 
Solved Threads: 1
Jennifer84 Jennifer84 is offline Offline
Posting Pro

Re: MessageBox with OK and CancelButton

 
0
  #2
Mar 4th, 2008
Originally Posted by Jennifer84 View Post
I am trying to create a DialogBox in C++ .NET with both an "OK" button and a "Cancel" Button.

I know how to just show a MessageBox with an "OK" button like this:
  1. MessageBox::Show(this, "Message");
I have tried with this but the compiler says that MB_OKCANCEL is undeclared identifier:
  1. MessageBox::Show(this, "Message", MB_OKCANCEL);
Last edited by Jennifer84; Mar 4th, 2008 at 5:42 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 980
Reputation: mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice 
Solved Threads: 210
mitrmkar mitrmkar is offline Offline
Posting Shark

Re: MessageBox with OK and CancelButton

 
0
  #3
Mar 4th, 2008
Something like this ...
  1. MessageBox::Show(this, "OK to proceed?", "A caption here ...", MessageBoxButtons::OKCancel, MessageBoxIcon::Question);
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 517
Reputation: Jennifer84 is an unknown quantity at this point 
Solved Threads: 1
Jennifer84 Jennifer84 is offline Offline
Posting Pro

Re: MessageBox with OK and CancelButton

 
0
  #4
Mar 4th, 2008
Thank you. That worked well.
As it is my first time I use an OKCANCEL dialogbox, I might wonder how it will
be possible to tell if the user ex. pressed the OK button or the CANCEL button.

Ex:
  1. if (OK is pressed) //What will be written on this line for OK or CANCEL
  2. {
  3. Action Here;
  4. }

Thank you...

Originally Posted by mitrmkar View Post
Something like this ...
  1. MessageBox::Show(this, "OK to proceed?", "A caption here ...", MessageBoxButtons::OKCancel, MessageBoxIcon::Question);
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 980
Reputation: mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice 
Solved Threads: 210
mitrmkar mitrmkar is offline Offline
Posting Shark

Re: MessageBox with OK and CancelButton

 
0
  #5
Mar 4th, 2008
  1. System::Windows::Forms::DialogResult result = MessageBox::Show(this, "OK to proceed?", "A caption here ...", MessageBoxButtons::OKCancel, MessageBoxIcon::Question);
  2.  
  3. if(System::Windows::Forms::DialogResult::OK == result)
  4. {
  5. // OK button
  6. }
  7. else
  8. {
  9. // System::Windows::Forms::DialogResult::Cancel == result
  10. // Cancel button
  11. }
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 517
Reputation: Jennifer84 is an unknown quantity at this point 
Solved Threads: 1
Jennifer84 Jennifer84 is offline Offline
Posting Pro

Re: MessageBox with OK and CancelButton

 
0
  #6
Mar 4th, 2008
Thank you very much, that did work very well.

jennifer
Reply With Quote Quick reply to this message  
Reply

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



Other Threads in the C++ Forum


Views: 1937 | Replies: 5
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC