CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Dec 2007
    Location
    Australia
    Posts
    151

    Determine if message box button YES or NO was clicked (MB_YESNO)

    I want to know how I can determine if YES or NO was clicked on my message box, my message box is called when you click 'Shutdown' in my application menu,

    Code:
    (at the top of my code) #define CAPTION_CONFIRM TEXT("Confirm")

    MessageBox(hWnd, TEXT("Shutdown, yes or no?"), CAPTION_CONFIRM, MB_YESNO)

    How do I determine if yes or no was clicked..

    Can you help me with this?

    Thanks

  2. #2
    Join Date
    Oct 2007
    Posts
    178

    Re: Determine if message box button YES or NO was clicked (MB_YESNO)

    MessageBox will return zero if it fails, or one of:
    IDABORT Abort button was selected.
    IDCANCEL Cancel button was selected.
    IDCONTINUE Continue button was selected.
    IDIGNORE Ignore button was selected.
    IDNO No button was selected.
    IDOK OK button was selected.
    IDRETRY Retry button was selected.
    IDTRYAGAIN Try Again button was selected.
    IDYES Yes button was selected.

    http://msdn2.microsoft.com/en-us/lib...05(VS.85).aspx

  3. #3
    Join Date
    May 2007
    Posts
    680

    Re: Determine if message box button YES or NO was clicked (MB_YESNO)

    Code example -

    Code:
    ...
    if(MessageBox(WindowHandleHere, MessageHere, TitleHere, StylesHere) == IDYES) // or IDNO, depending
    {
    
      // If the user clicks yes...
    
    }
    ...
    Just sayin' but I'm 14(I'm telling you this so you know what sort of language to use).
    Advice received by a user.

  4. #4
    Join Date
    Dec 2007
    Location
    Australia
    Posts
    151

    Re: Determine if message box button YES or NO was clicked (MB_YESNO)

    Thanks to both of you, I was looking for MB_YES or MB_NO :P

    Cheers

  5. #5
    Join Date
    Oct 2007
    Posts
    178

    Re: Determine if message box button YES or NO was clicked (MB_YESNO)

    Quote Originally Posted by Icyculyr
    Thanks to both of you, I was looking for MB_YES or MB_NO :P

    Cheers
    you mean IDYES or IDNO :P

  6. #6
    Join Date
    Dec 2007
    Location
    Australia
    Posts
    151

    Re: Determine if message box button YES or NO was clicked (MB_YESNO)

    No :P, I meant I was previously looking for MB_YES and MB_NO, but now I know it is IDYES IDNO etc..

    Ty

  7. #7
    Join Date
    Feb 2012
    Posts
    1

    Smile Re: Determine if message box button YES or NO was clicked (MB_YESNO)

    DialogResult result = MessageBox.Show("Message", Choose", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Asterisk);
    if (result.Equals(DialogResult.Abort))
    labelmsg.Text = "Abort is pressed";
    if (result.Equals(DialogResult.Retry))
    labelmsg.Text = "Retry is pressed";
    if (result.Equals(DialogResult.Ignore))
    labelmsg.Text = "Ignore is pressed";

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Determine if message box button YES or NO was clicked (MB_YESNO)

    Dear shikha_kumari!
    Please note that:
    1. This thread is exactly four years old and the problem was resolved exactly four years ago.
    2. Your code has nothing to do with the C++, so I'd recommend you just to delete your post as an inappropriate on this Forum.
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured