From: Lin X. <ris...@ho...> - 2003-03-23 20:56:28
|
If you define the console stream in global scope, it will try to instaniate the console before main. :) What do you think will happen? I'm actually suprised it even runs.. actually, the console should work. How do you mean the colors are wrong? Are there no colors? Are the colors the wrong colors? >From: "Matthew Mitchell" <cp...@uf...> >Reply-To: lib...@li... >To: <lib...@li...> >Subject: [Libgdn-discuss] Wierd Behavior with ConsoleStream >Date: Sun, 23 Mar 2003 01:15:54 -0500 > >Having some weird things with console stream, check this out: > >This is from the windowing test file > > >using namespace GDN::Application; >using namespace std; >using namespace GDN::IO::Formatting; > >class MyHandler; > >//Win specific keydown event >struct KeyDownEvent { > enum {OSID = WM_KEYDOWN}; > //you MUST RESPECT THIS INTERFACEC!@ > //note, it's MyHandler& not EVentHandler& > static LRESULT Dispatch(MyHandler& handler,HWND >hwnd,LPARAM,WPARAM); >}; > >class MyHandler : public GDN::Application::EventHandler { >private: > ConsoleStream console; >public: > MyHandler() : GDN::Application::EventHandler() { > console << SetStyle(FontStyle() << FontBold); > } > > //use a typedef to define the new events > typedef AddEvents<MyHandler,EventHandler,KeyDownEvent> >EventMap; > > virtual void OnCreate() { > console << SetForeColor(ConsoleColors::Red) << >"onCreate called!" << endl; > } > virtual void OnDestroy() { > console << SetForeColor(ConsoleColors::Red) << >"onDestroy called!" << endl; > } > virtual void OnMove(int newx,int newy) { > console << SetForeColor(ConsoleColors::Blue) << >"onMove called: ("<<newx << " " <<newy << ")!"<<endl; > } > virtual void OnResize(int sizex,int sizey) { > console << SetForeColor(ConsoleColors::Blue) << >"onResize called: ("<<sizex << " " <<sizey << ")!"<<endl; > } > virtual void OnActivate() { > console << SetForeColor(ConsoleColors::Green) ><< "onActivate called"<<endl; > } > virtual void OnAppActivate() { > console << SetForeColor(ConsoleColors::Green) ><< "onAppActivate called"<<endl; > } > virtual void OnKeyDown() { > MessageHandler::Quit(); //quit the application > } >}; > >LRESULT KeyDownEvent::Dispatch(MyHandler& handler,HWND >hwnd,LPARAM,WPARAM) { > handler.OnKeyDown(); > return 0;//handleed event >} > >void IdleFunc() { >} > >//play with copying DisplayDevicees... >DisplayDevice TestCopy(DisplayDevice SomethignWierd) { > SomethignWierd.Move(100,100); > return SomethignWierd; >} > >//wow, main is gone! we just have GDNMain now :) >bool GDNMain(const char* commandline) { > try { > MyHandler Handler; > DisplayDevice Window(Handler,"Testing OS Indie Window >system",false,0,0,1024,768); > Window.Create(); > TestCopy(Window); > MessageHandler MessagePump; > MessagePump.Run(IdleFunc); > return true; > } > catch(std::runtime_error& err) { > //awwwh, not fun! OS dep right now... > MessageBox(NULL,err.what(),"GDN Test",MB_OK); > return false; > } >} > > >Works correctly.notice that ConsoleStream console; is declared inside >message handler. > >Now, if I move the declaration outside the there, into global scope, > >ConsoleStream console; > >class MyHandler : public GDN::Application::EventHandler { >private: > >. > >}; > >None of the coloration works properly > _________________________________________________________________ Add photos to your e-mail with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail |