954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

MessageBox issue

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?

jan1024188
Posting Whiz in Training
254 posts since Aug 2006
Reputation Points: 27
Solved Threads: 2
 

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);
Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 
ostringstream stm ;
stm << "Total points " << points ;
MessageBox(hwnd, "You have bla bla", stm.str().c_str(), MB_OK);
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287
 

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

jan1024188
Posting Whiz in Training
254 posts since Aug 2006
Reputation Points: 27
Solved Threads: 2
 

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.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

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.

Beaten..

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

and also..I dont think sprintf would help here

jan1024188
Posting Whiz in Training
254 posts since Aug 2006
Reputation Points: 27
Solved Threads: 2
 

What should I do?

jan1024188
Posting Whiz in Training
254 posts since Aug 2006
Reputation Points: 27
Solved Threads: 2
 

Use the options suggested in posts 2 and 3.

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

>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.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

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....!!!

kxh29
Junior Poster in Training
56 posts since Apr 2007
Reputation Points: 10
Solved Threads: 1
 

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.

Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You