Thread: decision based on answer

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    3

    Question 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

  2. #2
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    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 +.
    Last edited by Cactus_Hugger; 06-21-2006 at 02:55 PM.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  3. #3
    Registered User
    Join Date
    Jun 2006
    Posts
    3
    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

  4. #4
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    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.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  5. #5
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    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);
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how would you answer this question?
    By smoking81 in forum Linux Programming
    Replies: 3
    Last Post: 09-08-2008, 03:53 AM
  2. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  3. Spam Filters. ISP based email is dying.
    By Mario F. in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 03-05-2008, 12:05 PM
  4. Replies: 4
    Last Post: 10-29-2003, 01:18 PM
  5. getting weird answer when not using ".h"
    By CobraCC in forum C++ Programming
    Replies: 10
    Last Post: 05-07-2003, 06:21 AM