home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************
- * CLIENT.CXX
- * (c) 1992-1994 STAR DIVISION
- *******************************************************************/
-
- #include <sv.hxx>
- #include "svdde.hxx"
-
- // --- class ClientWindow ------------------------------------------
-
- class ClientWindow : public WorkWindow
- {
- FixedText aText;
- String aDate;
- String aTime;
-
- public:
- DdeConnection* pTime;
-
- ClientWindow();
-
- void Resize();
- void Paint( const Rectangle& );
-
- void NotifyTime();
- void SetDate( const DdeData* );
- void SetTime( const DdeData* );
- };
-
- // --- class ClientApp ---------------------------------------------
-
- class ClientApp : public Application
- {
- public:
- void Main( int, char* [] );
- };
-
- // --- Instance of Class Application -------------------------------
-
- ClientApp aMyApp;
-
- // --- ClientApp::Main() -------------------------------------------
-
- void ClientApp::Main( int, char* [] )
- {
- ClientWindow aWin;
- aWin.SetText( String( "DDE-Client: Time" ) );
- aWin.ChangeSizePixel( Size( 300, 70 ) );
- aWin.Show();
-
- // Establish DDE connections
- DdeConnection aTime( String( "TIMES" ), String( "TIME" ) );
- DdeConnection aDate( String( "TIMES" ), String( "DATE" ) );
- if ( aTime.GetError() || aDate.GetError() )
- {
- MessBox( &aWin, WinBits( WB_OK ), aWin.GetText(),
- String( "Server TIMES not responding !" ) ).Execute();
- }
- else
- {
- aWin.pTime = &aTime;
- // connection established; prepare transactions
- DdeWarmLink aTimeLink( aTime, String( "NOW" ) );
- aTimeLink.ChangeNotifyHdl( LINK( &aWin, ClientWindow, NotifyTime ) );
- DdeHotLink aDateLink( aDate, String( "NOW" ) );
- aDateLink.ChangeDataHdl( LINK( &aWin, ClientWindow, SetDate ) );
- aDateLink.Execute();
- aTimeLink.Execute();
- if ( aTime.GetError() || aDate.GetError() )
- {
- MessBox( &aWin, WinBits( WB_OK ), aWin.GetText(),
- String( "Link NOW not accepted !" ) ).Execute();
- }
- else
- Execute();
- }
- }
-
- // --- ClientWindow::ClientWindow() --------------------------------
-
- ClientWindow::ClientWindow()
- : WorkWindow( NULL, WinBits( WB_APP | WB_STDWORK ) ),
- aText( this, WinBits( WB_CENTER ) )
- {
- aText.Show();
- }
-
- // --- ClientWindow::Resize() --------------------------------------
-
- void ClientWindow::Resize()
- {
- aText.ChangeOutputSizePixel( GetOutputSizePixel() );
- }
-
- // --- ClientWindow::Paint() ---------------------------------------
-
- void ClientWindow::Paint( const Rectangle& )
- {
- String s( aDate );
- s += "\r\n";
- s += aTime;
- aText.SetText( s );
- }
-
- // --- ClientWindow::NotifyTime() ----------------------------------
-
- void ClientWindow::NotifyTime()
- {
- // request actual time, request timeout is 0.5 sec
- DdeRequest aRequest( *pTime, String( "NOW" ), 500L );
- // set data event handler
- aRequest.ChangeDataHdl( LINK( this, ClientWindow, SetTime ) );
- aRequest.Execute();
- Invalidate();
- }
-
- // --- ClientWindow::SetDate() -------------------------------------
-
- void ClientWindow::SetDate( const DdeData* pData )
- {
- aDate = (char*) (const char*) *pData;
- USHORT n = aDate.Search( "\r\n" );
- if( n != STRING_NOTFOUND )
- aDate.Cut( n );
- }
-
- // --- ClientWindow::SetTime() -------------------------------------
-
- void ClientWindow::SetTime( const DdeData* pData )
- {
- aTime = (char*) (const char*) *pData;
- USHORT n = aTime.Search( "\r\n" );
- if ( n != STRING_NOTFOUND )
- aTime.Cut( n );
- }
-