fs/_tests/fsConWin/main.cpp

Go to the documentation of this file.
00001 
00002 //---------------------------------------------------------------------------
00003 #include <fs/rap/fsConWin.h>
00004 
00005 #include <cassert>
00006 #include <string>
00007 #include <windows.h>
00008 //---------------------------------------------------------------------------
00009 namespace test {
00010 //---------------------------------------------------------------------------
00012 class TxtRcvr_t : public fs::rap::ConWin_t::TxtRcvr_i
00013 {
00014  public:
00015  
00016     explicit TxtRcvr_t(fs::rap::ConWin_t *pTgt) : m_pTgt(pTgt)
00017      { assert(m_pTgt); }
00018 
00019     virtual void Receive(const char *pszText, bool bCmd)
00020     {
00021         assert(pszText);
00022     
00023         if(!bCmd) // process only command-line inputs
00024             return;
00025             
00026         if(::strcmp(pszText, "exit") == 0) // quit the application
00027             ::PostQuitMessage(0);
00028         else
00029         {
00030             // send typed text to the target console
00031             const std::string strText("RECEIVED: " + std::string(pszText));
00032             m_pTgt->Push(strText.c_str());
00033         }
00034     }
00035             
00036  private:
00037  
00038     TxtRcvr_t();
00039     fs::rap::ConWin_t *m_pTgt;
00040 };
00041 //---------------------------------------------------------------------------
00042 } // namespace test
00043 //---------------------------------------------------------------------------
00044 int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
00045 {
00046     // create two consoles
00047     fs::rap::ConWin_t Con1("Console 1");
00048     assert(Con1.IsValid());
00049     
00050     fs::rap::ConWin_t Con2("Console 2");
00051     assert(Con2.IsValid());
00052     
00053     // register text receivers (cross input <=> output)
00054     test::TxtRcvr_t Rcvr1(&Con2);
00055     Con1.RegTxtRcvr(&Rcvr1);
00056     
00057     test::TxtRcvr_t Rcvr2(&Con1);
00058     Con2.RegTxtRcvr(&Rcvr2);
00059     
00060     // set positions and dimensions of the consoles
00061     Con1.SetPos(20, 20,  750, 260);
00062     Con2.SetPos(20, 300, 750, 260);
00063     
00064     // show the consoles
00065     Con1.Show();
00066     Con2.Show();
00067     
00068     // send a sample message to the output of each of the consoles
00069     Con1.Push("Sample message 1. Type 'exit' to quit the application.");
00070     Con2.Push("Sample message 2. Type 'exit' to quit the application.");
00071             
00072     //--- MESSAGE PUMP ---
00073         
00074     // usually the underlying application has such a pump...
00075     MSG msg;
00076     while(::GetMessage(&msg, 0, 0, 0))
00077     {
00078         ::TranslateMessage(&msg);
00079         ::DispatchMessage(&msg);
00080     }
00081 
00082     return static_cast<int>(msg.wParam);
00083 }
00084 //---------------------------------------------------------------------------

FipS' Code (Thu Feb 15 22:43:35 2007) - (c) Filip STOKLAS (FipS) - [ www ] [ Guest Book ]