How to check user selection(yes/no) on a Message Box

Hey,
I have a question. How can you tell what button(yes/no) on a message box is clicked? Below is what I have right now but I am getting errors.
1
2
3
if (MessageBox(NULL,"The Message", "The Title", MB_YESNO) == IDYES){
do somthing
}


Any help will be greatly appreciated.

Tiffanie
Aside from the mismatching tchar business, that code looks right to me. What errors are you getting?
Disch,
It says that I have too many inputs for MessageBox(). What way would you write code to achieve this?
Are you sure you posted the actual code that's giving you the error? Because that code works fine for me (after fixing the tchar thing, but that's likely not your problem) and does what you'd expect.

To clarify... this code works just fine:

1
2
3
4
5
6
7
8
    if (MessageBoxA(NULL,"The Message", "The Title", MB_YESNO) == IDYES)
    {
        MessageBoxA(NULL,"YES pressed","",MB_OK);
    }
    else
    {
        MessageBoxA(NULL,"NO pressed","",MB_OK);
    }
Last edited on
Disch,
I am still having problems with checking to see if user can clicked yes or no on a message box. Below is exact code.
1
2
3
4
5
6
7
8
MessageBox("Confirm Zeroize?", "Zeroize", MB_YESNO);

if(MessageBox(NULL, "Confirm Zeroize?", "Zeroize", MB_YESNO ) == IDYES)
{
   //ACTION GOES HERE

}

The error that I am getting states that I have to many arguments in function call. Any help will be greatly appreciated!!!
You do realize the first MessageBox there (why are you trying to create two identical ones?) is missing an argument and that is likely what your compiler is complaining about.
Ok. I thought you check to see what the user selected. If the user select yes, I want to do something. What do I need to change to do this
MessageBoxA is the function you want (Read: not MessageBox -- you are not using TCHARs, so you don't want the TCHAR function)

When you call MessageBoxA, it will display the message box. Also, the return value of that function will be the result of the option the user selected.

Therefore:

1
2
3
4
if(MessageBoxA(NULL, "Confirm Zeroize?", "Zeroize", MB_YESNO) == IDYES)
{
  // Action goes here
}
Topic archived. No new replies allowed.