Thread: Variables in win32

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    57

    Variables in win32

    In a tetris game, I am just preparing it. I made an unsigned int for the score. I want to know how I would display the amount of "score" into a message box or Dialog. Preferably Message. Thanks.
    Language: C++
    Compiler: Visual C++ 6.0
    Currently Working On: Simple OpenGL aspects

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    Perhaps you could do something like this:

    unsigned int value;
    char string [80];

    // Create a string
    sprintf (string "Value is %d\n", value);

    // Print the string
    AfxMessageBox (string);

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    57
    Hmm... I am doing it in C++. That looks like C... I tried doing it like this:

    Code:
     MessageBox (NULL, " #1: "<<score<<"", "Scores", MB_OK);
    But it didn't work..
    Language: C++
    Compiler: Visual C++ 6.0
    Currently Working On: Simple OpenGL aspects

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    You cannot utilize this functionality "<<" in your MessageBox. This is a stream class overload type thingy, and so you must use traditional C syntax. No worries, though. C++ IS C!
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    57
    Ok, then im not good with C. How would i display the score in my Message Box then? Here is what i have so far for it:

    (note: just snippets)
    Code:
    unsigned int score = 0;
    char string [80];
    
    //and below....
    
    case IDC_BUTTON4:
    MessageBox(NULL, " #1 - \n #2 - \n #3 -", "Hi-Scores", MB_OK);
    break;
    Language: C++
    Compiler: Visual C++ 6.0
    Currently Working On: Simple OpenGL aspects

  6. #6
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    You might do:

    sprintf(buff, " The High Score Is %i", score);

    Then MessageBox buff...
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  7. #7
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Clarification:

    You don't use the sprintf() to print out the result on the screen, just converting the int into a string.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  8. #8
    "The Oldest Member Here" Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,039
    Just create one string and output it.

  9. #9
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    CString sScore;

    sScore.Format("High Score: %d", m_highScore);
    AfxMessageBox(sScore);

  10. #10
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    Or for those of us who detest MFC:

    Code:
    char messageBuffer[WHATEVER_SIZE];
    snprintf(messageBuffer, sizeof(messageBuffer), "High Score: %d", m_highScore);
    MessageBox(hWnd, messageBuffer, "Score", MB_OK);
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Remotely Creating Variables
    By Rajin in forum C++ Programming
    Replies: 1
    Last Post: 04-26-2005, 11:20 PM
  2. Declaring an variable number of variables
    By Decrypt in forum C++ Programming
    Replies: 8
    Last Post: 02-27-2005, 04:46 PM
  3. hwnd and variables in them
    By underthesun in forum Windows Programming
    Replies: 6
    Last Post: 01-16-2005, 06:39 PM
  4. OLE Clipboard :: Win32 API vs. MFC
    By kuphryn in forum Windows Programming
    Replies: 3
    Last Post: 08-11-2002, 05:57 PM
  5. Thread Synchronization :: Win32 API vs. MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 08-09-2002, 09:09 AM