-
decision based on answer
this is the code i use to open a simple message box with yes no buttons :
Code:
MessageBox (NULL, "Could not save file do you wann try again?" , "ERROR ", 0 + MB_YESNO + MB_SYSTEMMODAL);
is it possible to store what button the user clicked into a variable so that i can use a swicth/case command or an if/esle if comand to make the program do difrent things depending on what button was clicked :confused:
-
Yes, read MSDN or your local Win32 API manual.
The button pushed is returned by MessageBox(), as one of several ID* #defines.
EDIT: Usually one ors flags together as opposed to addition. (And the 0 + is unneeded, of course.) So, MB_ICONERROR | MB_YESNO as opposed to MB_ICONERROR + MB_YESNO. This is just the way I've always seen it, and I believe both methods equate to the same value. A more senior member might be able to provide a clue as to why | is used over +.
-
its ok i used the following code to work out the values which are returned after each button is clicked
Code:
#include <windows.h>
#include <iostream.h>
using namespace std;
int STDCALL
WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
{
int x =10;
x = MessageBox (NULL, "Could not save file do you wann try again?" , "ERROR ", 0 + MB_YESNO + MB_SYSTEMMODAL);
cout<< x ;
cin.get();
return 0;
}
then i used a switch/case command and the returned values so that the program could do difrent things based on what the user had clicked
-
I hope then you're not doing something like:
Code:
x = MessageBox(HWND_DESKTOP, "Am I cool?", "Hey you!", MB_YESNO);
if(x == 6) printf("Thanks!\n");
// etc.
Don't use numerical values for whatever MessageBox() returns: use the #define'd constants. Instead of if(x == 6), use if(x == IDYES). It'll make your code portable if those values ever change, and (the big reason) your code will be readable. == IDYES holds a lot more meaning than == 6.
-
Code:
if(MessageBox(HWND_DESKTOP, "Am I cool?", "Hey you!", MB_YESNO)==IDYES){
MessageBox(HWND_DESKTOP,"Thanks!,"Thanks!", MB_OK);
}
else{
MessageBox(HWND_DESKTOP,"You are WRONG!,"Arrgh!", MB_OK);
}