Skip to main content
GameDev.net gamedev.net
🔒 Locked

Message Boxes

Started by David91999 May 27, 2002 at 1:26 AM 2 replies 700+ views
Original Post
David91999
David91999
How can I get the function MessageBox to print the value of a variable?
Norge
Norge
Depends. If your variable is a string, you can use
MessageBox(NULL,sVariable,"MessageBoxTitle",MB_OK);

Elseway, you have to convert your variable into a string.
diddly-yo
diddly-yo
I'll post some code that is similar to what I use in my logs.


    
#include <stdio.h>
#include <stdarg.h>

// sample usage: MBox("value of temp = %i", temp);

// %i corresponds to ineger value

// %f corresponds to floating point value

bool MBox(char* string, ...)
{
va_list ap;
char text[256];
if (string == NULL)
return false;

va_start(ap, string);
vsprintf(text, string, ap);
va_end(ap);
// text[] now contains whatever text you supplied plus the numeric values


MessageBox(hWnd, text, "popup message", MB_OK); // where hWnd is your window's handle or NULL


return true;


edit: I wanted to add that this code is taken basically from NeHe's font tutorials. It's the same principle.

I hope this helps.

diddly



[edited by - diddly-yo on May 28, 2002 11:37:13 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.