Writing to a window
I have written a function to do this easily from within my program, but i have a few questions. First, how can i do text wrapping? That is, if i pass the function a string longer than the window width, move to the next line (and preferably to do that by word, not letter)
second, and more importantly (to me), how would I pass a variable amount of variables in the same fashion as a function like printf? Like, i want to be able to call something like WriteToWindow("string %s and %i", s, i) etc. how is this done?
For your text wrapping, you might check out the DrawText API function. It has flags for autowrapping text if given a rectangle to clip to.
For variable arguments you will need to check out:
va_start
va_end
vsprintf
here is a sample function that prints messages to cout using a variable argument format:
//: wrapper for logging messages to output device
//:
bool debugout(const char *msg, ...) {
va_list argList;
char buffer[512] = { 0 };
va_start(argList, msg);
vsprintf(buffer, msg, argList);
va_end(argList);
cout << buffer << endl;
return (false);
}
For variable arguments you will need to check out:
va_start
va_end
vsprintf
here is a sample function that prints messages to cout using a variable argument format:
//: wrapper for logging messages to output device
//:
bool debugout(const char *msg, ...) {
va_list argList;
char buffer[512] = { 0 };
va_start(argList, msg);
vsprintf(buffer, msg, argList);
va_end(argList);
cout << buffer << endl;
return (false);
}
__________________________________________
Yeah, sure... we are laughing WITH you ...
Yeah, sure... we are laughing WITH you ...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement