Detecting WIN32 button press.

Hey,

I have this code;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int TEST; // only way i could assign this to the messagebox.

void createbox_QUIT()
{
	 TEST = MessageBox(NULL, "Are you sure you want to quit?", " ", MB_ICONQUESTION | MB_YESNO);
	 switch(TEST)
	 {
	     case 1:
			  createbox_COPYRIGHT(); // I used this box just as a test
		      break;
	     case 2:
			  createbox_VERSION(); // same as above, for a test.
		      break;
	 }
}


How can i detect if the person presses the yes or presses the no button?

Thanks!
MessageBox returns "IDYES" if the users presses Yes, and "IDNO" if they press No.
Source: http://msdn.microsoft.com/en-us/library/ms645505%28VS.85%29.aspx
Windows deals with Messageboxes internally - it simply returns the value of the button pressed.

The way you have done it is the general way to do it (using either a switch or if/else) - but windows standard defines for these buttons and you should use these instead of hard coded values.

For example, in your code the message box will either return IDYES or IDNO.

1
2
3
4
5
6
7
8
9
10
11
	 
TEST = MessageBox(NULL, "Are you sure you want to quit?", " ", MB_ICONQUESTION | MB_YESNO);
	 switch(TEST)
	 {
	     case IDYES:
			  createbox_COPYRIGHT(); // I used this box just as a test
		      break;
	     case IDNO:
			  createbox_VERSION(); // same as above, for a test.
		      break;
	 }
Last edited on
Sorry i posted in Windows aswell, i thought i put it in the wrong cat.

Thanks both of you!
Topic archived. No new replies allowed.