home *** CD-ROM | disk | FTP | other *** search
/ PC Direkt 1995 March / PCD_395.iso / starview / pm2csci / german / client.cx_ / CLIENT.CXX
Encoding:
C/C++ Source or Header  |  1994-01-21  |  3.7 KB  |  136 lines

  1. /*******************************************************************
  2. *  CLIENT.CXX
  3. *  (c) 1992-1994 STAR DIVISION
  4. *******************************************************************/
  5.  
  6. #include <sv.hxx>
  7. #include "svdde.hxx"
  8.  
  9. // --- class ClientWindow ------------------------------------------
  10.  
  11. class ClientWindow : public WorkWindow
  12. {
  13.     FixedText aText;
  14.     String aDate;
  15.     String aTime;
  16.  
  17. public:
  18.     DdeConnection*  pTime;
  19.  
  20.                     ClientWindow();
  21.  
  22.     void            Resize();
  23.     void            Paint( const Rectangle& );
  24.  
  25.     void            NotifyTime();
  26.     void            SetDate( const DdeData* );
  27.     void            SetTime( const DdeData* );
  28. };
  29.  
  30. // --- class ClientApp ---------------------------------------------
  31.  
  32. class ClientApp : public Application
  33. {
  34. public:
  35.     void Main( int, char* [] );
  36. };
  37.  
  38. // --- Instance of Class Application -------------------------------
  39.  
  40. ClientApp aMyApp;
  41.  
  42. // --- ClientApp::Main() -------------------------------------------
  43.  
  44. void ClientApp::Main( int, char* [] )
  45. {
  46.     ClientWindow aWin;
  47.     aWin.SetText( String( "DDE-Client: Time" ) );
  48.     aWin.ChangeSizePixel( Size( 300, 70 ) );
  49.     aWin.Show();
  50.  
  51.     // Establish DDE connections
  52.     DdeConnection aTime( String( "TIMES" ), String( "TIME" ) );
  53.     DdeConnection aDate( String( "TIMES" ), String( "DATE" ) );
  54.     if ( aTime.GetError() || aDate.GetError() )
  55.     {
  56.         MessBox( &aWin, WinBits( WB_OK ), aWin.GetText(),
  57.                  String( "Server TIMES not responding !" ) ).Execute();
  58.     }
  59.     else
  60.     {
  61.         aWin.pTime = &aTime;
  62.         // connection established; prepare transactions
  63.         DdeWarmLink aTimeLink( aTime, String( "NOW" ) );
  64.         aTimeLink.ChangeNotifyHdl( LINK( &aWin, ClientWindow, NotifyTime ) );
  65.         DdeHotLink aDateLink( aDate, String( "NOW" ) );
  66.         aDateLink.ChangeDataHdl( LINK( &aWin, ClientWindow, SetDate ) );
  67.         aDateLink.Execute();
  68.         aTimeLink.Execute();
  69.         if ( aTime.GetError() || aDate.GetError() )
  70.         {
  71.             MessBox( &aWin, WinBits( WB_OK ), aWin.GetText(),
  72.                      String( "Link NOW not accepted !" ) ).Execute();
  73.         }
  74.         else
  75.             Execute();
  76.     }
  77. }
  78.  
  79. // --- ClientWindow::ClientWindow() --------------------------------
  80.  
  81. ClientWindow::ClientWindow()
  82.               : WorkWindow( NULL, WinBits( WB_APP | WB_STDWORK ) ),
  83.                 aText( this, WinBits( WB_CENTER ) )
  84. {
  85.     aText.Show();
  86. }
  87.  
  88. // --- ClientWindow::Resize() --------------------------------------
  89.  
  90. void ClientWindow::Resize()
  91. {
  92.     aText.ChangeOutputSizePixel( GetOutputSizePixel() );
  93. }
  94.  
  95. // --- ClientWindow::Paint() ---------------------------------------
  96.  
  97. void ClientWindow::Paint( const Rectangle& )
  98. {
  99.     String s( aDate );
  100.     s += "\r\n";
  101.     s += aTime;
  102.     aText.SetText( s );
  103. }
  104.  
  105. // --- ClientWindow::NotifyTime() ----------------------------------
  106.  
  107. void ClientWindow::NotifyTime()
  108. {
  109.     // request actual time, request timeout is 0.5 sec
  110.     DdeRequest aRequest( *pTime, String( "NOW" ), 500L );
  111.     // set data event handler
  112.     aRequest.ChangeDataHdl( LINK( this, ClientWindow, SetTime ) );
  113.     aRequest.Execute();
  114.     Invalidate();
  115. }
  116.  
  117. // --- ClientWindow::SetDate() -------------------------------------
  118.  
  119. void ClientWindow::SetDate( const DdeData* pData )
  120. {
  121.     aDate = (char*) (const char*) *pData;
  122.     USHORT n = aDate.Search( "\r\n" );
  123.     if( n != STRING_NOTFOUND )
  124.         aDate.Cut( n );
  125. }
  126.  
  127. // --- ClientWindow::SetTime() -------------------------------------
  128.  
  129. void ClientWindow::SetTime( const DdeData* pData )
  130. {
  131.     aTime = (char*) (const char*) *pData;
  132.     USHORT n = aTime.Search( "\r\n" );
  133.     if ( n != STRING_NOTFOUND )
  134.         aTime.Cut( n );
  135. }
  136.