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

  1. #include "client.h"
  2.  
  3. #include XColor_i
  4. #include XMessageBox_i
  5. #include XMenuBar_i
  6. #include XString_i
  7. #include XDDE_i
  8.  
  9. #include <stdlib.h>
  10.  
  11. SHORT volume = 50;
  12.  
  13. class MyDDE: public XDDE
  14. {
  15.    public:
  16.       MyDDE( XWindow * w):XDDE(w, "Sample8", "SampleTopic"){;}
  17.       void DataReceived( ULONG size, void * data, char * itemName, SHORT format);
  18.       void Connected( OOL_WINDOWHANDLE handle);
  19.       void DisConnected( void );
  20. };
  21.  
  22.  
  23. void MyDDE :: Connected( OOL_WINDOWHANDLE handle)
  24. {
  25.    //init was succesful, we have a connect
  26.    GetOwner()->SetText( "DDEClient - connected");
  27.  
  28.    //ask for data
  29.    Advise();
  30. }
  31.  
  32.  
  33. void MyDDE :: DisConnected( void )
  34. {
  35.    GetOwner()->SetText( "DDEClient - not connected");
  36. }
  37.  
  38.  
  39. void MyDDE :: DataReceived( ULONG size, void * data, char * itemName, SHORT format)
  40. {
  41.    XString item = itemName;
  42.    LONG id = 0;
  43.  
  44.    if(item == "FIELD1")
  45.       id = ENTRY_ONE;
  46.    if(item == "FIELD2")
  47.       id = ENTRY_TWO;
  48.    if(item == "FIELD3")
  49.       id = ENTRY_THREE;
  50.    if(item == "FIELD4")
  51.       id = ENTRY_FOUR;
  52.  
  53.    if( id )
  54.       {
  55.          XFrameWindow * w = (XFrameWindow*) GetOwner();
  56.          XWindow * entry = w->GetWindow( id );
  57.          if( entry )
  58.             entry->SetText( (char*) data );
  59.       }
  60. }
  61.  
  62.  
  63. MyAppWindow :: MyAppWindow( XApplication * app, XResource * r ): XFrameWindow( r, "Sample8 - DDEClient", XFrameWindow::defaultDialogStyle | FRM_TASKLIST | FRM_CENTER, NULL, NULL, TRUE)
  64. {
  65.    Show();
  66.  
  67.    Activate();
  68.  
  69.    //construct a dde
  70.    dde = new MyDDE(this );
  71.  
  72.    //connect
  73.    dde->Init();
  74. }
  75.  
  76.  
  77. MyAppWindow :: ~MyAppWindow()
  78. {
  79.    dde->UnAdvise();
  80.    delete dde;
  81. }
  82.  
  83.  
  84. MyApp :: MyApp(): XApplication()
  85. {
  86.    XResource r( IDM_MAIN, GetResourceLibrary());
  87.    window = new MyAppWindow( this, &r );   //create new framewindow (see above)
  88. }
  89.  
  90. void main ( void)
  91. {
  92.    MyApp * app = new MyApp();  //create a new application
  93.    app->Start();               //let the application work
  94. }
  95.