if (!CreateGLWindow("state is now: " #+ variable-in-here-#
,640,480,16,fullscreen));
How can i concatenate a string to the caption? -it would do if the variable could be drawn on the screen too -because this is only for debug purpose so the drop in fps (if any) could be neglegted.
extending the window caption
unfourtunately the forum search is disabled? This is definately something that has been ask/answered many times I would like to display an in-program variable (boolean) in the window caption eg:
regards a.
Why not use sprintf? Like so:
Greetz,
Illco
char pBuffer[512];sprintf( pBuffer, "Caption %d", variable );-- use it in title call
Greetz,
Illco
Best way would be to change the window caption every frame. You can do that by:
or, to make sure the C++ guys dont bite my head off...
float variable = 3.1415fchar buffer[256];sprintf(buffer, "state is now: %f", &variable);SetWindowText(hWnd, buffer);
or, to make sure the C++ guys dont bite my head off...
float variable = 3.1415fstd::string title;title << "state is now: " << variable;SetWindowText(hWnd, title.c_str());
sprintf(buf,"The state is %d", number);
if (!CreateGLWindow(buf ,640,480,16,fullscreen));
if (!CreateGLWindow(buf ,640,480,16,fullscreen));
thank you for the fast replys
however
@PlayfulPuppy: writes 0.00000 nomather value
the cpp snippet std::string title; error string not member of std
@traiger: invalid constant char* to int
further: the sugestion would not be a concat to the orr. caption in the gl window
eg
if (!CreateGLWindow("NeHe's Tutorial -state is now: " #+ variable-in-here-#
,640,480,16,fullscreen));
the sentence/String 'state is now' is ..simply added the program variable should then be string converted and as a string concatenated to the title String
-in- the gl window
perhaps not so simple after all..
however
@PlayfulPuppy: writes 0.00000 nomather value
the cpp snippet std::string title; error string not member of std
@traiger: invalid constant char* to int
further: the sugestion would not be a concat to the orr. caption in the gl window
eg
if (!CreateGLWindow("NeHe's Tutorial -state is now: " #+ variable-in-here-#
,640,480,16,fullscreen));
the sentence/String 'state is now' is ..simply added the program variable should then be string converted and as a string concatenated to the title String
-in- the gl window
perhaps not so simple after all..
regards a.
Quote:
Original post by bearS
thank you for the fast replys
however
@PlayfulPuppy: writes 0.00000 nomather value
the cpp snippet std::string title; error string not member of std
1) Whoops, that should probably be:
sprintf(buffer, "state is now: %f", variable);
.. I think. I haven't used sprintf in quite a while now.
2) Dont forget to add
#include <string>
Also, dont forget that if the variable changes and you want the window title to reflect this, you'll have to set the caption again with SetWindowCaption.
Quote:
perhaps not so simple after all..
Nah, it's simple. Just a couple of minor errors is all.
make sure buf is an array of char of adequate length.
but it is sprintf you need to use.
but it is sprintf you need to use.
A C++ ostringstream will perform the same thing as sprintf, but without the concern of experiencing a buffer overflow.
#define DEFAULT_WINDOW_TITLE "My Application"#include <sstream>using std::ostringstream;#include <ios>using std::boolalpha;...ostringstream title;// remove the call to boolalpha to format the bool as 1 or 0 instead of "true" or "false"title << DEFAULT_WINDOW_TITLE << " state is now: " << boolalpha << boolean_var;if(!CreateGLWindow(title.str().c_str(), 640, 480, 16, fullscreen)){ ...}...
..almost there
-but
Why is a boolean var ignored?
i can use a float and it is shown....?
..btw for those who want to know
i used the edited codesnip from PlayfulPuppy and inserted it in the
int DrawGLScene(GLvoid) -method
(because the draw-opps is updated every tick)
ofcause the buffer needs to be outside.. :) as does the initialization of the var
eg:
where fi is my 'boolean' for the state un the appl.
only that 'bool' needs to be a ....float
so not %f what then ...%b .. no ;)
-but
Why is a boolean var ignored?
i can use a float and it is shown....?
..btw for those who want to know
i used the edited codesnip from PlayfulPuppy and inserted it in the
int DrawGLScene(GLvoid) -method
(because the draw-opps is updated every tick)
ofcause the buffer needs to be outside.. :) as does the initialization of the var
eg:
sprintf(buffer, "state is now: %f", fi);SetWindowText(hWnd, buffer); return TRUE;
where fi is my 'boolean' for the state un the appl.
only that 'bool' needs to be a ....float
so not %f what then ...%b .. no ;)
regards a.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement