home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool.zip / OOL / samples / sample8 / server.cpp < prev    next >
Text File  |  1996-12-14  |  3KB  |  120 lines

  1. #include "server.h"
  2.  
  3. #include XColor_i
  4. #include XMessageBox_i
  5. #include XMenuBar_i
  6. #include XString_i
  7. #include XDDE_i
  8. #include XControlEvent_i
  9.  
  10. #include <stdlib.h>
  11.  
  12. SHORT volume = 50;
  13.  
  14. class MyDDE: public XDDE
  15. {  
  16.    public:      
  17.       MyDDE( XWindow * w):XDDE(w, "Sample8", "SampleTopic", TRUE){clients=NULL;clientCount = 0;}
  18.       void Connected( OOL_WINDOWHANDLE client );
  19.       void AdviseRequested(char * itemName, SHORT format, OOL_WINDOWHANDLE client);
  20.       void DisConnected();
  21.       void UnAdviseRequested( OOL_WINDOWHANDLE c);
  22.       SHORT clientCount;
  23.       OOL_WINDOWHANDLE * clients;
  24. };
  25.  
  26.  
  27. void MyDDE :: UnAdviseRequested( OOL_WINDOWHANDLE c)
  28. {
  29.    int i;
  30.    for(i=0; i < clientCount; i++)
  31.       {
  32.          if( clients[i] == c)
  33.             clients[i] = 0;
  34.       }
  35. }
  36.  
  37.  
  38. void MyDDE :: AdviseRequested(char * itemName, SHORT format, OOL_WINDOWHANDLE c)
  39. {
  40.    clientCount += 1;
  41.    clients = (OOL_WINDOWHANDLE *) realloc( clients, clientCount * sizeof(OOL_WINDOWHANDLE));
  42.    clients[clientCount -1] = c;
  43. }
  44.  
  45.  
  46. void MyDDE :: Connected( OOL_WINDOWHANDLE c )
  47. {
  48.    GetOwner()->SetText("DDEServer - connected");
  49. }
  50.  
  51.  
  52. void MyDDE :: DisConnected( )
  53. {
  54.    GetOwner()->SetText("DDEServer - not connected");
  55. }
  56.  
  57.  
  58. MyAppWindow :: MyAppWindow( XApplication * app, XResource * r ): XFrameWindow( r, "Sample8 - DDEServer", XFrameWindow::defaultDialogStyle | FRM_TASKLIST | FRM_CENTER, NULL, NULL, TRUE)
  59. {
  60.    Show();
  61.  
  62.    dde = new MyDDE(this );
  63.    Activate();
  64. }
  65.  
  66.  
  67. MyAppWindow :: ~MyAppWindow()
  68. {
  69.    delete dde;
  70. }
  71.  
  72.  
  73. void MyAppWindow :: DoControl( XControlEvent * event)
  74. {
  75.    if( event->GetEventID() == WIN_KILLFOCUS)
  76.       {
  77.          char * item = NULL;
  78.          switch( event->GetWindowID() )
  79.             {
  80.                case ENTRY_ONE:
  81.                   item = "FIELD1";
  82.                   break;
  83.                case ENTRY_TWO:
  84.                   item = "FIELD2";
  85.                   break;
  86.                case ENTRY_THREE:
  87.                   item = "FIELD3";
  88.                   break;
  89.                case ENTRY_FOUR:
  90.                   item = "FIELD4";
  91.                   break;
  92.             }
  93.          if( item) //dde->IsConnected() && 
  94.             {
  95.                XString data;
  96.                event->GetWindow()->GetText( &data );
  97.                SHORT i;
  98.                for(i=0; i < dde->clientCount; i++)
  99.                   {                    
  100.                      if( dde->clients[i] != 0)
  101.                         dde->SendData( dde->clients[i], item, (char*) data, data.GetLength() + 1, 0);
  102.                   }
  103.             }
  104.       }
  105. }
  106.  
  107.  
  108. MyApp :: MyApp(): XApplication()
  109. {
  110.    XResource r( IDM_MAIN, GetResourceLibrary());
  111.    window = new MyAppWindow( this, &r );   //create new framewindow (see above)
  112. }
  113.  
  114.  
  115. void main ( void)
  116. {
  117.    MyApp * app = new MyApp();  //create a new application
  118.    app->Start();               //let the application work
  119. }
  120.