home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 21 / IOPROG_21.ISO / SOFT / DDESUP.ZIP / DDESERV.PRG < prev    next >
Encoding:
Text File  |  1995-05-02  |  6.7 KB  |  241 lines

  1. *
  2. *    DDE-FiveWin-Support
  3. *  (w) by Joerg Karwath 4/95
  4. *  CIS 100333,3034
  5. *
  6. * It's free. Everything. Use or delete it.
  7. *
  8. * Too include it in your own programs see read_me file.
  9. *
  10. *
  11. #include "DdeFV.ch"
  12. #include "FiveWin.ch"
  13.  
  14. * Predefined Clipboard Formats *
  15. #define CF_TEXT              1    // only text is supported yet
  16. #define CF_BITMAP            2
  17. #define CF_METAFILEPICT      3
  18. #define CF_SYLK              4
  19. #define CF_DIF               5
  20. #define CF_TIFF              6
  21. #define CF_OEMTEXT           7
  22. #define CF_DIB               8
  23. #define CF_PALETTE           9
  24. #define CF_PENDATA          10
  25. #define CF_RIFF             11
  26. #define CF_WAVE             12
  27. *
  28. //----------------------------------------------------------------------------//
  29.  
  30. CLASS TDdeServer
  31.  
  32.    DATA   oWnd        // Main-Window-Object
  33.  
  34.    DATA   cService, cTopic    // SERVER DATA!!
  35.    DATA   bInit        // executed on activation of connect
  36.    DATA   bExecute    // executed on DDE_EXECUTE Message
  37.    DATA   bRequest    // executed on DDE_REQUEST Message
  38.    DATA   bPoke        // executed on DDE_POKE Message
  39.    DATA   bTerminate    // executed on DDE_TERMINATE Message
  40.    DATA   lActive
  41.    DATA   hClientHandle
  42.    
  43.  
  44.    METHOD New( oWnd,cService, cTopic,;
  45.         bInit,bExecute,bRequest,bPoke,bTerminate;
  46.             ) CONSTRUCTOR
  47.    METHOD End()
  48.    METHOD DDE_INIT (nWParam,nLParam)
  49.    METHOD DDE_EXE (nWParam,nLParam)
  50.    METHOD DDE_REQ (nWParam,nLParam)
  51.    METHOD DDE_POKE (nWParam,nLParam)
  52.    METHOD DDE_TERM (nWParam,nLParam)
  53. ENDCLASS
  54.  
  55.  
  56. //----------------------------------------------------------------------------//
  57.  
  58. METHOD New( oWnd, cService, cTopic, bInit ,bExecute,;
  59.         bRequest,bPoke,bTerminate ) CLASS TDdeServer
  60.  
  61. // oWnd        Main-Window (not the Childs!)
  62.  
  63.    ::oWnd     = oWnd
  64.    ::cService = upper(cService)
  65.    ::cTopic   = upper(cTopic)
  66.    ::bInit    = bInit
  67.    ::bExecute = bExecute
  68.    ::bRequest = bRequest
  69.    ::bPoke    = bPoke
  70.    ::bTerminate = bTerminate
  71.    ::lActive  = .f.
  72.    ::hClientHandle = 0
  73.  
  74.    ::oWnd:bDDE_INIT={|nWParam,nLParam|::DDE_INIT(nWParam,nLParam)}
  75.    ::oWnd:bDDE_EXE={|nWParam,nLParam|::DDE_EXE(nWParam,nLParam)}
  76.    ::oWnd:bDDE_REQ={|nWParam,nLParam|::DDE_REQ(nWParam,nLParam)}
  77.    ::oWnd:bDDE_POKE={|nWParam,nLParam|::DDE_POKE(nWParam,nLParam)}
  78.    ::oWnd:bDDE_TERM={|nWParam,nLParam|::DDE_TERM(nWParam,nLParam)}
  79.    // from this point the Server is active and can react
  80. return nil
  81.  
  82. //----------------------------------------------------------------------------//
  83. METHOD End() CLASS TDdeServer
  84. **
  85. ::hClientHandle=0
  86. ::lActive := .f.
  87. ::oWnd:bDDE_INIT=nil
  88. ::oWnd:bDDE_EXE=nil
  89. ::oWnd:bDDE_REQ=nil
  90. ::oWnd:bDDE_POKE=nil
  91. ::oWnd:bDDE_TERM=nil
  92. return nil
  93.  
  94.  
  95.  
  96. //----------------------------------------------------------------------------//
  97.    
  98. *************************
  99. METHOD DDE_INIT (nWParam,nLParam)    CLASS TDdeServer
  100. **
  101. local cService,cTopic
  102. local lOk
  103. // a global DDE_INITIATE with NULL service and/or
  104. // NULL topic is not supported yet.
  105.         
  106. // check, if ::cService and ::cTopic do match
  107. cService=upper(GlobalGetAtom(nLoWord(nLParam)))
  108. cTopic=upper(GlobalGetAtom(nHiWord(nLParam)))
  109. if cService==::cService .and. cTopic==::cTopic
  110.    // Hit
  111.    ::hClientHandle=nWParam
  112.    lOk=.t.    // default: connect even without INIT-Block
  113.    if valtype(::bInit)="B"
  114.       // do NOT open a window or wait for a user input
  115.       // in the bInit Codeblock. The system could hang (if this occurs try pressing the ALT-key to continue)
  116.       if eval(::bInit,cService,cTopic)=.f.
  117.          lOk=.f.
  118.       endif
  119.    endif
  120.    // Now post the ACK to the client
  121.    if lOk=.t.
  122.       PostMessage(::hClientHandle,;
  123.         WM_DDE_ACK , ::oWnd:hWnd, nLParam )
  124.       ::lActive=.t.
  125.    endif
  126. endif
  127. return 0
  128.  
  129.  
  130. *************************
  131. METHOD DDE_EXE (nWParam,nLParam)    CLASS TDdeServer
  132. **
  133. local cData
  134. local nRetCode:=0    // User defineable ReturnCode
  135. local lBusy:=.f.    // .t.=Busy   (nAck must then be 0)
  136. local lAck:=.f.        // .t.=okay
  137. local hAck        // Handle for ACK-GlobalMemoryObject
  138. *
  139. if ::lActive=.t. .and. nWParam=::hClientHandle
  140.    cData=DdeGetCommand( nLParam )
  141.    if valtype(::bExecute)="B"
  142.       if eval(::bExecute,cData)=.t.
  143.          lAck=.t.
  144.       else
  145.          lBusy=.t.
  146.       endif
  147.    endif
  148.    // Rⁿckmeldung setzen
  149.    hAck=CrDdeAck( nRetCode,lBusy,lAck )
  150.    PostMessage( ::hClientHandle, WM_DDE_ACK , ::oWnd:hWnd,;
  151.        nMakeLong( hAck, nHiWord(nLParam) ) )
  152. endif
  153. return 0
  154.  
  155.  
  156. *************************
  157. METHOD DDE_REQ (nWParam,nLParam)    CLASS TDdeServer
  158. **
  159. local cItem,cData,hData
  160. local nRetCode:=0    // User defineable ReturnCode
  161. local lOk
  162. local lBusy:=.f.    // .t.=Busy   (nAck must then be 0)
  163. local lAck:=.f.        // .t.=okay
  164. local hAck        // Handle for ACK-GlobalMemoryObject
  165. *
  166. if ::lActive=.t. .and. nWParam=::hClientHandle
  167.    cItem=GlobalGetAtom(nHiWord(nLParam))
  168.    lOk=.f.
  169.    if valtype(::bRequest)="B"
  170.       // in this Version only CF_TEXT Handles will
  171.       // be answered
  172.       if nLoWord(nLParam)=CF_TEXT
  173.          cData=eval(::bRequest,cItem)
  174.          if valtype(cData)="C"
  175.             // send DATA
  176.             hData=CrDdeData(cData)
  177.         PostMessage(::hClientHandle,;
  178.             WM_DDE_DATA , ::oWnd:hWnd, nMakeLong(hData,nHiWord(nLParam)))
  179.             lOk=.t.
  180.          endif
  181.       endif   
  182.    endif
  183.    // DATA sent?
  184.    if lOk=.f.
  185.       // no, then post ACK as failed
  186.       hAck=CrDdeAck( nRetCode,lBusy,lAck )
  187.       PostMessage( ::hClientHandle, WM_DDE_ACK , ::oWnd:hWnd,;
  188.         nMakeLong( hAck, nHiWord(nLParam) ) )
  189.    endif
  190. endif
  191. return 0
  192.  
  193.  
  194. *************************
  195. METHOD DDE_POKE (nWParam,nLParam)    CLASS TDdeServer
  196. **
  197. local cItem,cData,hData
  198. local lOk
  199. local nRetCode:=0    // User defineable ReturnCode
  200. local lBusy:=.f.    // .t.=Busy   (nAck must then be 0)
  201. local lAck:=.f.        // .t.=okay
  202. local hAck        // Handle for ACK-GlobalMemoryObject
  203. *
  204. if ::lActive=.t. .and. nWParam=::hClientHandle
  205.    cData=GetDdePoke( nLoWord( nLParam ) )    // Get Poke-Data
  206.    cItem=GlobalGetAtom(nHiWord(nLParam))    // Get Poke-Item (Identifier)
  207.    if valtype(::bPoke)="B"
  208.       if eval(::bPoke,cItem,cData,@nRetCode)=.t.
  209.          lAck=.t.
  210.       else
  211.          lBusy=.t.
  212.       endif
  213.    else    // Poke not supported, ACK=.f., BUSY=.f.
  214.    endif
  215.    hAck=CrDdeAck( nRetCode,lBusy,lAck )
  216.    // Rⁿckmeldung setzen
  217.    PostMessage( ::hClientHandle, WM_DDE_ACK , ::oWnd:hWnd,;
  218.         nMakeLong( hAck, nHiWord(nLParam) ) )
  219. endif
  220. return 0
  221.  
  222. *************************
  223. METHOD DDE_TERM (nWParam,nLParam)    CLASS TDdeServer
  224. **
  225. if ::lActive=.t. .and. nWParam=::hClientHandle
  226.    if valtype(::bTerminate)="B"
  227.       eval(::bTerminate)
  228.    endif
  229.    ::lActive := .f.    // set conversation to inactiv
  230.                // don't use :end() here because this
  231.                // wouldn't allow to reestablish the
  232.                // conservation
  233.    PostMessage( ::hClientHandle, WM_DDE_TERMINATE , ::oWnd:hWnd, 0)
  234.    ::hClientHandle=0
  235. endif
  236. return 0
  237.  
  238.  
  239.  
  240.  
  241.