Archived

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

Strings and windows

This topic is 6587 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

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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;
}

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites