Hello,

I want to make a message box which would show me how many points have I earned.

So I have:

unsigned int points;
//code
points++;

MessageBox(hwnd, "You have bla bla", "Total points /*HERE I WANT TO DISPLAY CONTENTS OF points VARIABLE*/, MB_OK);

Is possible to do that?

Recommended Answers

All 11 Replies

Yes, assuming this is C you would use sprintf or something equivalent to format the points into your string:

char buffer[100];

sprintf ( buffer, "Total points: %u", points );
MessageBox(hwnd, "You have bla bla", buffer, MB_OK);
ostringstream stm ;
stm << "Total points " << points ;
MessageBox(hwnd, "You have bla bla", stm.str().c_str(), MB_OK);

Well, I know for sprintf. I just wanna know if I can use a variable in MessageBox on other way.

No. MessageBox takes a string. If you want to use a variable, it has to be contained in a string. That should be a pretty obvious restriction given the documentation on MessageBox.

I guess no:

int MessageBox(
HWND hWnd,
LPCTSTR lpText,
LPCTSTR lpCaption,
UINT uType
);

lpText [in] Pointer to a null-terminated string that contains the message to be displayed.

lpCaption [in] Pointer to a null-terminated string that contains the dialog box title. If this parameter is NULL, the default title Error is used.

<edit>Beaten..</edit>

and also..I dont think sprintf would help here

What should I do?

Use the options suggested in posts 2 and 3.

>and also..I dont think sprintf would help here
Why not? It does exactly what you want. You can also use stringstream like what's-his-name suggested if you're writing C++ code. Or you can do any number of things to format a number into a string, but they're all fundamentally the same operation.

Yes, assuming this is C you would use sprintf or something equivalent to format the points into your string:

char buffer[100];

sprintf ( buffer, "Total points: %u", points );
MessageBox(hwnd, "You have bla bla", buffer, MB_OK);

Hello Team:

I would like to create a "message box" to print out multiple lines of information on the screen from one of our applications.

My question is what is the "hwnd" operand and how do I define or initialize it? I believe the MB_OK relates to the generation of the message box itself.

Where else can I find out about the creation and use of message boxes using C?

Thanks in Advance....!!!

According to MS, hwnd is a Handle to the owner window of the message box to be created. If this parameter is NULL, the message box has no owner window.

This thread is getting a little old by now. You'll get better result if you post in a new thread of your own.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.