$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
CREATE FORM AS QFORM
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
CREATE recvlbl AS QLABEL
CAPTION="Receive:"
top=3
left=form.clientwidth/2+15
END CREATE
CREATE redit1 AS QRICHEDIT
hideselection=0
scrollbars=3
top=18
left=5
width=form.clientwidth/2-10
height=form.clientheight-60
END CREATE
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
END CREATE
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
form.SHOWMODAL
|