message box class

This is a discussion on message box class within the Windows Programming forums, part of the Platform Specific Boards category; I am working on a class that is supposed to make it easier to put stuff into message boxes. I ...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    17

    message box class

    I am working on a class that is supposed to make it easier to put stuff into message boxes. I want it to work like std::cout so I can do something like this:

    Messagebox<<somevariable<<"blah blah blah"<<4654;

    But I can't figure out how to do that without having to call a function at the end to display the message box, i.e., I have to do this:

    Messagebox<<somevariable<<"blah blah blah"<<4654;
    Messagebox.Display();

    Does anyone know how to do this without having to call some display function? Here's what I have so far:

    Code:
    class MsgBox
    {
    public:
    	std::ostringstream & operator << (signed char & param){stream<<param;return stream;}
    	std::ostringstream & operator << (unsigned char & param){stream<<param;return stream;}
    	std::ostringstream & operator << (char & param){stream<<param;return stream;}
    	std::ostringstream & operator << (short & param){stream<<param;return stream;}
    	std::ostringstream & operator << (unsigned short & param){stream<<param;return stream;}
    	std::ostringstream & operator << (int & param){stream<<param;return stream;}
    	std::ostringstream & operator << (unsigned int & param){stream<<param;return stream;}
    	std::ostringstream & operator << (long & param){stream<<param;return stream;}
    	std::ostringstream & operator << (unsigned long & param){stream<<param;return stream;}
    	std::ostringstream & operator << (float & param){stream<<param;return stream;}
    	std::ostringstream & operator << (double & param){stream<<param;return stream;}
    	std::ostringstream & operator << (long double & param){stream<<param;return stream;}
    	void Display() {::MessageBox(NULL,stream.str().c_str(),"caption",MB_OK);}
    protected:
    	std::ostringstream stream;
    };

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    CCreate your own version of std::endl to put at the end of the line when you want it to be outputted

    Messagebox<<somevariable<<"blah blah blah"<<4654 << ToScreen;

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    17
    Thank you for your input. Actually my idea was to set it up so you wouldn't have to write anything else. std::cout will still work even if you don't write anything at the end. I might implement your suggestion if I can't figure out how to do it the other way.

  4. #4
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>std:stringstream
    You might want to make that a Messagebox instead... just a thought. But the reason cout works, as I understand it, is because each << outputs its part on the screen automatically; I can't think of any way to emulate that with a messagebox though, unless you manually create a window that looks like a standard messagebox and then modify the text within it.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem in message handling VC++
    By 02mca31 in forum Windows Programming
    Replies: 5
    Last Post: 01-16-2009, 08:22 PM
  2. My class doesn't create an edit box.
    By sethjackson in forum Windows Programming
    Replies: 15
    Last Post: 09-02-2005, 03:44 PM
  3. No data showing in combo box
    By PJYelton in forum Windows Programming
    Replies: 6
    Last Post: 04-29-2005, 07:20 PM
  4. Inheritance with pointers:Overloading?
    By katie in forum C++ Programming
    Replies: 3
    Last Post: 04-13-2004, 01:26 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21