home *** CD-ROM | disk | FTP | other *** search
- *
- * DDE-FiveWin-Support
- * (w) by Joerg Karwath 4/95
- * CIS 100333,3034
- *
- * It's free. Everything. Use or delete it.
- *
- * Too include it in your own programs see read_me file.
- *
- *
- #include "DdeFV.ch"
- #include "FiveWin.ch"
-
- * Predefined Clipboard Formats *
- #define CF_TEXT 1 // only text is supported yet
- #define CF_BITMAP 2
- #define CF_METAFILEPICT 3
- #define CF_SYLK 4
- #define CF_DIF 5
- #define CF_TIFF 6
- #define CF_OEMTEXT 7
- #define CF_DIB 8
- #define CF_PALETTE 9
- #define CF_PENDATA 10
- #define CF_RIFF 11
- #define CF_WAVE 12
- *
- //----------------------------------------------------------------------------//
-
- CLASS TDdeServer
-
- DATA oWnd // Main-Window-Object
-
- DATA cService, cTopic // SERVER DATA!!
- DATA bInit // executed on activation of connect
- DATA bExecute // executed on DDE_EXECUTE Message
- DATA bRequest // executed on DDE_REQUEST Message
- DATA bPoke // executed on DDE_POKE Message
- DATA bTerminate // executed on DDE_TERMINATE Message
- DATA lActive
- DATA hClientHandle
-
-
- METHOD New( oWnd,cService, cTopic,;
- bInit,bExecute,bRequest,bPoke,bTerminate;
- ) CONSTRUCTOR
- METHOD End()
- METHOD DDE_INIT (nWParam,nLParam)
- METHOD DDE_EXE (nWParam,nLParam)
- METHOD DDE_REQ (nWParam,nLParam)
- METHOD DDE_POKE (nWParam,nLParam)
- METHOD DDE_TERM (nWParam,nLParam)
- ENDCLASS
-
-
- //----------------------------------------------------------------------------//
-
- METHOD New( oWnd, cService, cTopic, bInit ,bExecute,;
- bRequest,bPoke,bTerminate ) CLASS TDdeServer
-
- // oWnd Main-Window (not the Childs!)
-
- ::oWnd = oWnd
- ::cService = upper(cService)
- ::cTopic = upper(cTopic)
- ::bInit = bInit
- ::bExecute = bExecute
- ::bRequest = bRequest
- ::bPoke = bPoke
- ::bTerminate = bTerminate
- ::lActive = .f.
- ::hClientHandle = 0
-
- ::oWnd:bDDE_INIT={|nWParam,nLParam|::DDE_INIT(nWParam,nLParam)}
- ::oWnd:bDDE_EXE={|nWParam,nLParam|::DDE_EXE(nWParam,nLParam)}
- ::oWnd:bDDE_REQ={|nWParam,nLParam|::DDE_REQ(nWParam,nLParam)}
- ::oWnd:bDDE_POKE={|nWParam,nLParam|::DDE_POKE(nWParam,nLParam)}
- ::oWnd:bDDE_TERM={|nWParam,nLParam|::DDE_TERM(nWParam,nLParam)}
- // from this point the Server is active and can react
- return nil
-
- //----------------------------------------------------------------------------//
- METHOD End() CLASS TDdeServer
- **
- ::hClientHandle=0
- ::lActive := .f.
- ::oWnd:bDDE_INIT=nil
- ::oWnd:bDDE_EXE=nil
- ::oWnd:bDDE_REQ=nil
- ::oWnd:bDDE_POKE=nil
- ::oWnd:bDDE_TERM=nil
- return nil
-
-
-
- //----------------------------------------------------------------------------//
-
- *************************
- METHOD DDE_INIT (nWParam,nLParam) CLASS TDdeServer
- **
- local cService,cTopic
- local lOk
- // a global DDE_INITIATE with NULL service and/or
- // NULL topic is not supported yet.
-
- // check, if ::cService and ::cTopic do match
- cService=upper(GlobalGetAtom(nLoWord(nLParam)))
- cTopic=upper(GlobalGetAtom(nHiWord(nLParam)))
- if cService==::cService .and. cTopic==::cTopic
- // Hit
- ::hClientHandle=nWParam
- lOk=.t. // default: connect even without INIT-Block
- if valtype(::bInit)="B"
- // do NOT open a window or wait for a user input
- // in the bInit Codeblock. The system could hang (if this occurs try pressing the ALT-key to continue)
- if eval(::bInit,cService,cTopic)=.f.
- lOk=.f.
- endif
- endif
- // Now post the ACK to the client
- if lOk=.t.
- PostMessage(::hClientHandle,;
- WM_DDE_ACK , ::oWnd:hWnd, nLParam )
- ::lActive=.t.
- endif
- endif
- return 0
-
-
- *************************
- METHOD DDE_EXE (nWParam,nLParam) CLASS TDdeServer
- **
- local cData
- local nRetCode:=0 // User defineable ReturnCode
- local lBusy:=.f. // .t.=Busy (nAck must then be 0)
- local lAck:=.f. // .t.=okay
- local hAck // Handle for ACK-GlobalMemoryObject
- *
- if ::lActive=.t. .and. nWParam=::hClientHandle
- cData=DdeGetCommand( nLParam )
- if valtype(::bExecute)="B"
- if eval(::bExecute,cData)=.t.
- lAck=.t.
- else
- lBusy=.t.
- endif
- endif
- // Rⁿckmeldung setzen
- hAck=CrDdeAck( nRetCode,lBusy,lAck )
- PostMessage( ::hClientHandle, WM_DDE_ACK , ::oWnd:hWnd,;
- nMakeLong( hAck, nHiWord(nLParam) ) )
- endif
- return 0
-
-
- *************************
- METHOD DDE_REQ (nWParam,nLParam) CLASS TDdeServer
- **
- local cItem,cData,hData
- local nRetCode:=0 // User defineable ReturnCode
- local lOk
- local lBusy:=.f. // .t.=Busy (nAck must then be 0)
- local lAck:=.f. // .t.=okay
- local hAck // Handle for ACK-GlobalMemoryObject
- *
- if ::lActive=.t. .and. nWParam=::hClientHandle
- cItem=GlobalGetAtom(nHiWord(nLParam))
- lOk=.f.
- if valtype(::bRequest)="B"
- // in this Version only CF_TEXT Handles will
- // be answered
- if nLoWord(nLParam)=CF_TEXT
- cData=eval(::bRequest,cItem)
- if valtype(cData)="C"
- // send DATA
- hData=CrDdeData(cData)
- PostMessage(::hClientHandle,;
- WM_DDE_DATA , ::oWnd:hWnd, nMakeLong(hData,nHiWord(nLParam)))
- lOk=.t.
- endif
- endif
- endif
- // DATA sent?
- if lOk=.f.
- // no, then post ACK as failed
- hAck=CrDdeAck( nRetCode,lBusy,lAck )
- PostMessage( ::hClientHandle, WM_DDE_ACK , ::oWnd:hWnd,;
- nMakeLong( hAck, nHiWord(nLParam) ) )
- endif
- endif
- return 0
-
-
- *************************
- METHOD DDE_POKE (nWParam,nLParam) CLASS TDdeServer
- **
- local cItem,cData,hData
- local lOk
- local nRetCode:=0 // User defineable ReturnCode
- local lBusy:=.f. // .t.=Busy (nAck must then be 0)
- local lAck:=.f. // .t.=okay
- local hAck // Handle for ACK-GlobalMemoryObject
- *
- if ::lActive=.t. .and. nWParam=::hClientHandle
- cData=GetDdePoke( nLoWord( nLParam ) ) // Get Poke-Data
- cItem=GlobalGetAtom(nHiWord(nLParam)) // Get Poke-Item (Identifier)
- if valtype(::bPoke)="B"
- if eval(::bPoke,cItem,cData,@nRetCode)=.t.
- lAck=.t.
- else
- lBusy=.t.
- endif
- else // Poke not supported, ACK=.f., BUSY=.f.
- endif
- hAck=CrDdeAck( nRetCode,lBusy,lAck )
- // Rⁿckmeldung setzen
- PostMessage( ::hClientHandle, WM_DDE_ACK , ::oWnd:hWnd,;
- nMakeLong( hAck, nHiWord(nLParam) ) )
- endif
- return 0
-
- *************************
- METHOD DDE_TERM (nWParam,nLParam) CLASS TDdeServer
- **
- if ::lActive=.t. .and. nWParam=::hClientHandle
- if valtype(::bTerminate)="B"
- eval(::bTerminate)
- endif
- ::lActive := .f. // set conversation to inactiv
- // don't use :end() here because this
- // wouldn't allow to reestablish the
- // conservation
- PostMessage( ::hClientHandle, WM_DDE_TERMINATE , ::oWnd:hWnd, 0)
- ::hClientHandle=0
- endif
- return 0
-
-
-
-
-