'Complile each one with a different name. They use RapidQ's
' SendMessage function, an API function called FindWindow and each uses
' the form's WndProc to detect any incoming data.
'
' =================program #1========================
' name this ap_a.rqb and compile
' Bill K 12-2002
$APPTYPE GUI
$TYPECHECK ON
$OPTIMIZE ON
' $INCLUDE "C:\RAPIDQ\DEBUG2.INC"
CONST CRLF=CHR$(13) & CHR$(10)
CONST WM_COPYDATA = &H4A
TYPE COPYDATASTRUCT
dwData AS LONG
cbData AS LONG
lpData AS LONG
END TYPE
DIM DataStruct AS COPYDATASTRUCT
DEFSTR strSend, strRecv
'
DECLARE SUB SendData
DECLARE SUB FormWndProc (Hwnd&, uMsg&, wParam&, lParam&)
DECLARE FUNCTION FindWindow LIB "user32" ALIAS _
"FindWindowA" (ByVal lpClassName AS String, _
ByVal lpWindowName AS String) AS LONG
'
CREATE FORM AS QFORM
' title the other application will search for:
CAPTION="Application A"
left=100
top=100
CREATE sendbtn AS QBUTTON
WIDTH=75
TOP=form.clientheight-33
LEFT=(form.clientwidth-sendbtn.width)/4-15
CAPTION="SEND"
ONCLICK=senddata
END CREATE
CREATE sendlbl AS QLABEL
caption="Send:"
top=3
left=10
END CREATE 'sendlbl
CREATE recvlbl AS QLABEL
caption="Receive:"
top=3
left=form.clientwidth/2+15
END CREATE 'recvlbl
CREATE redit1 AS QRICHEDIT
hideselection=0
scrollbars=3
top=18
left=5
width=form.clientwidth/2-10
height=form.clientheight-60
END CREATE ' redit
CREATE Redit2 AS QRICHEDIT
hideselection=0
scrollbars=3
top=18
left=redit1.LEFT + redit1.width +10
width=form.clientwidth/2-10
height=form.clientheight-60
END CREATE ' Redit2
END CREATE ' FORM
'
SUB SendData
DEFLNG wndhnd
wndhnd=Findwindow("TForm","Application B")
IF wndhnd=0 THEN
SHOWMESSAGE "Could not find Application B"
EXIT SUB
END IF
strSend=redit1.text
DataStruct.lpData = VARPTR(strSend)
DataStruct.cbData = LEN(strSend)
SENDMESSAGE wndhnd, WM_COPYDATA, 0, DataStruct
END SUB
'
SUB FormWndProc (Hwnd&, uMsg&, wParam&, lParam&)
IF uMsg& = WM_COPYDATA THEN
DIM MStream AS QMEMORYSTREAM
MStream.MemCopyFrom(lParam&, 12)
MStream.Position = 0
MStream.ReadUDT(DataStruct)
MStream.Close
strRecv = VARPTR$(DataStruct.lpData)
Redit2.addstrings strRecv
END IF
END SUB
'
REDIT1.ADDSTRINGS "This is sample data text" + crlf + "from Application A"
Form.WndProc = FormWndProc' best if this is
' just before showmodal
Form.showmodal

'========end of ap_a.rqb


--------------------------------------------------------------------------------\
--------

' Sotfware N° 2

'Complile each one with a different name.They use RapidQ's SendMessage
'function, an API function called FindWindow and each uses the form's
'WndProc to detect any incoming data.
'
' =================program #2========================
' name this ap_b.rqb and compile
' Bill K 12-2002
$APPTYPE GUI
$TYPECHECK ON
$OPTIMIZE ON
CONST CRLF=CHR$(13) & CHR$(10)
CONST WM_COPYDATA = &H4A
TYPE COPYDATASTRUCT
dwData AS LONG
cbData AS LONG
lpData AS LONG
END TYPE
DIM DataStruct AS COPYDATASTRUCT
DEFSTR strSend, strRecv
'
DECLARE SUB SendData
DECLARE SUB FormWndProc (Hwnd&, uMsg&, wParam&, lParam&)
DECLARE FUNCTION FindWindow LIB "user32" ALIAS "FindWindowA" (ByVal lpClassName
AS String, ByVal lpWindowName
AS String) AS LONG
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA"
(lpPrevWndFunc&, Hwnd&, uMsg&,
wParam&,lParam&) As Long
'
CREATE FORM AS QFORM
' title the other application will search for:
CAPTION="Application B"
left=500
top=100
CREATE sendbtn AS QBUTTON
WIDTH=75
TOP=form.clientheight-33
LEFT=(form.clientwidth-sendbtn.width)/4-15
CAPTION="SEND"
ONCLICK=senddata
END CREATE
CREATE sendlbl AS QLABEL
caption="Send:"
top=3
left=10
END CREATE 'sendlbl
CREATE recvlbl AS QLABEL
caption="Receive:"
top=3
left=form.clientwidth/2+15
END CREATE 'recvlbl
CREATE redit1 AS QRICHEDIT
hideselection=0
scrollbars=3
top=18
left=5
width=form.clientwidth/2-10
height=form.clientheight-60
END CREATE ' redit
CREATE Redit2 AS QRICHEDIT
hideselection=0
scrollbars=3
top=18
left=redit1.LEFT + redit1.width +10
width=form.clientwidth/2-10
height=form.clientheight-60
END CREATE ' Redit2
END CREATE ' FORM
'
SUB SendData
DEFLNG wndhnd
wndhnd=Findwindow("TForm","Application A")
IF wndhnd=0 THEN
SHOWMESSAGE "Could not find Application A"
EXIT SUB
END IF
strSend=redit1.text
DataStruct.lpData = VARPTR(strSend)
DataStruct.cbData = LEN(strSend)
SENDMESSAGE wndhnd, WM_COPYDATA, 0, DataStruct
END SUB
'
SUB FormWndProc (Hwnd&, uMsg&, wParam&, lParam&)
IF uMsg& = WM_COPYDATA THEN
DIM MStream AS QMEMORYSTREAM
MStream.MemCopyFrom(lParam&, 12)
MStream.Position = 0
MStream.ReadUDT(DataStruct)
MStream.Close
strRecv = VARPTR$(DataStruct.lpData)
Redit2.addstrings strRecv
END IF
END SUB
'
REDIT1.ADDSTRINGS "This is sample data text" + _
crlf + "from Application B"
Form.WndProc = FormWndProc' best if this is
' just before showmodal
form.showmodal

'=== end ap_b.rqb

