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

Strings and windows

Started by acw83 Dec 1, 1999 at 7:02 PM 6 replies 800+ views
Original Post
acw83
acw83
I have two questions:

1) I have a double variable called fps. How can I display it as a string in the MessageBox function?

2) How do I keep a console app from closing immediately after it is over, I can't see my final output because the app closes. Thanks.

Zer
Zer
Create a variable called tmp. Like char tmp[256]; for instance. Correct me if I'm wrong, but I think it's:

_ltoa(tmp, fps, 10);

That will place fps as a string in tmp. You could always use sprintf if you need extra info in there.

For the output, try a Sleep(15000); or something.

logistix
logistix
The wsprintf() function works like printf() but copies text into a string buffer instead of sending it to default output. Then you can use all the standard printf() formatting.

TCHAR szTempString[50];

wsprintf(szTempString, " %i frames per second", fps)
MessageBox(hwnd, szTempString, NULL, NULL);


the wsprintf() function is also unicode friendly if you're bracing for Windows 2000.

-the logistical one-http://members.bellatlantic.net/~olsongt
Josh Neta
Josh Neta
never use a sleep to see your output. use

while(!kbhit()){}

kbhit is in conio.h

Josh

acw83
acw83
It compilse and runs fine, but teh number showed is nowhere NEAR the actual fps...


int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{


double fps;
double testnum;

unsigned long framecounter = 0;

double totaltime = 0;
long curtime = 0;

MessageBox(NULL, "To start click OK and wait 10 seconds.", "Windows Benchmark",MB_OK);

long starttime = GetTickCount();

while(curtime < 10000)
{
for(int res = 0; res < 65536; res++)
{
testnum = sqrt(2);
}

curtime = GetTickCount() - starttime;
framecounter++;
}

totaltime = (GetTickCount() - starttime)/1000;
fps = framecounter/totaltime;

TCHAR szTempString[50];

wsprintf(szTempString, " %i", fps);
MessageBox(NULL, szTempString, "Windows Benchmark, FPS:",MB_OK);

return 0;
}

logistix
logistix
The %i indicates that an interger follows. In true C style, they don't care what the acual data type is, you can either cast

(int) fps

or use %d instead of %i to indicate a double precision fp number.

If you do a google or altavista search on printf() you should be able to get a good list of how to format everything.

-the logistical one-http://members.bellatlantic.net/~olsongt
Keebler
Keebler
%d is for decimal integer

%f is typically used for double and floating-point.

"%04.1f" is one example that gives you 1 decimal point to the right of the decimal

Keeb

logistix
logistix
DOH!

I gotta stop smokin' that crack.

-the logistical one-http://members.bellatlantic.net/~olsongt

Topic Locked

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

Sign in to reply to this topic.