Archived

This topic is now archived and is closed to further replies.

getting my variable on my MsgBox

This topic is 5150 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

quote:
Original post by firecast
A little newbie question...

how do i convert a number (int or DWORD), so i can see it on a MessageBox without getting a conversion-type error??

thanks in advance


Declare a buffer, and use wsprintf.

char buffer[1024];
wsprintf(buffer, "%d", MyValue);
MessageBox(window, buffer, "...", MB_OK

Share this post


Link to post
Share on other sites
or you could try string stream

#include "strstream"
using namespace std;
strstream sstr;
int i, n;
sstr << i << "string" << n << ends;
MessageBox... sstr.str()


string stream will convert all compatible types you stream to it into a single string.

Share this post


Link to post
Share on other sites
strstream is deprecated, use stringstream instead. The syntax is exactly the same as with strstream, except you should include sstream instead of strstream.

- neophyte

Share this post


Link to post
Share on other sites
You can also use a switch statement.


switch(MessageBox(NULL, "text", "title", MB_YESNO))
{
case ID_YES:
//do yes command stuff here

break;

case ID_NO:
//do no command stuff here

break;
}

Share this post


Link to post
Share on other sites