Jump to content

  • Log In with Google      Sign In   
  • Create Account

Strings and windows


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 acw83   Members   -  Reputation: 174

Like
Likes
Like

Posted 01 December 1999 - 01:02 PM

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.


Sponsor:

#2 Zer   Members   -  Reputation: 122

Like
Likes
Like

Posted 30 November 1999 - 12:00 PM

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.


#3 logistix   Members   -  Reputation: 122

Like
Likes
Like

Posted 30 November 1999 - 01:27 PM

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.


#4 Josh Neta   Members   -  Reputation: 122

Like
Likes
Like

Posted 30 November 1999 - 01:40 PM

never use a sleep to see your output. use

while(!kbhit()){}

kbhit is in conio.h

Josh


#5 acw83   Members   -  Reputation: 174

Like
Likes
Like

Posted 30 November 1999 - 03:14 PM

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;
}


#6 logistix   Members   -  Reputation: 122

Like
Likes
Like

Posted 30 November 1999 - 05:44 PM

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.


#7 Keebler   Members   -  Reputation: 126

Like
Likes
Like

Posted 30 November 1999 - 06:02 PM

%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


#8 logistix   Members   -  Reputation: 122

Like
Likes
Like

Posted 01 December 1999 - 01:02 PM

DOH!

I gotta stop smokin' that crack.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS