Here are two sample programs.
wndsend.prg
wndget.prg
- Code: Select all Expand view
// wndsend.prg
#include "fivewin.ch"
#include "xbrowse.ch"
REQUEST DBFCDX
//----------------------------------------------------------------------------//
function Main()
local oWnd, oBar, oBrw
USE CUSTOMER NEW VIA "DBFCDX"
DEFINE WINDOW oWnd TITLE "SendWnd"
DEFINE BUTTONBAR oBar OF oWnd SIZE 100,32 2007
DEFINE BUTTON OF oBar PROMPT "SendMsg" ACTION SendData()
SET MESSAGE OF oWnd TO '' 2007
@ 0,0 XBROWSE oBrw OF oWnd ALIAS "CUSTOMER" ;
AUTOCOLS CELL LINES NOBORDER
oBrw:CreateFromCode()
oWnd:oClient := oBrw
ACTIVATE WINDOW oWnd
CLOSE DATA
return 0
//----------------------------------------------------------------------------//
static function SendData()
local hDstWnd := FindWindow( "TCDWnd", "GetWnd" )
if Empty( hDstWnd )
? "window not found"
else
SendDataToApp( hDstWnd, 1, ;
FW_ValToExp( { CUSTOMER->FIRST, CUSTOMER->LAST, CUSTOMER->CITY } ), ;
WndMain():hWnd )
endif
return nil
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
#pragma BEGINDUMP
#include <windows.h>
#include <hbapi.h>
HB_FUNC (SENDDATATOAPP) // ( hDestWnd, nMsgID, cData, hFromWnd )
{
COPYDATASTRUCT cds;
cds.dwData = hb_parnl( 2 );
cds.cbData = hb_parclen( 3 );
cds.lpData = (PVOID) hb_parcx( 3 );
SendMessage( (HWND) hb_parnl( 1 ), WM_COPYDATA, (WPARAM) (HWND) hb_parnl( 4 ), (LPARAM) (LPVOID) &cds );
hb_ret();
}
HB_FUNC (PARSECOPYDATA)
{
PCOPYDATASTRUCT pCDS;
pCDS = (PCOPYDATASTRUCT) hb_parnl( 1 );
hb_stornl( pCDS->dwData, 2 );
hb_retclen( pCDS->lpData, pCDS->cbData );
}
#pragma ENDDUMP
//============================================================================//
wndget.prg:
- Code: Select all Expand view
// wndget.prg
#include "fivewin.ch"
#include "xbrowse.ch"
REQUEST DBFCDX
//----------------------------------------------------------------------------//
function Main()
local oWnd, oBar, oBrw
oWnd := TCDWnd():New( nil, nil, nil, nil, "GetWnd" )
DEFINE BUTTONBAR oBar OF oWnd SIZE 100,32 2007
SET MESSAGE OF oWnd TO ''
oWnd:bOnGetData := { |oWnd, oFrom, nID, cData| ;
OnGetData( oWnd, oFrom, nID, cData, oBrw ) }
@ 0,0 XBROWSE oBrw OF oWnd DATASOURCE {} ;
COLUMNS 1, 2, 3 ;
HEADERS "First", "Last", "City" ;
COLSIZES 80, 80, 80 ;
CELL LINES NOBORDER
oBrw:CreateFromCode()
oWnd:oClient := oBrw
ACTIVATE WINDOW oWnd
CLOSE DATA
return 0
//----------------------------------------------------------------------------//
static function OnGetData( oWnd, oFrom, nMsgID, cData, oBrw )
AAdd( oBrw:aArrayData, &cData )
oBrw:GoBottom()
oBrw:Refresh()
oBrw:SetFocus()
return nil
//----------------------------------------------------------------------------//
//============================================================================//
#define WM_COPYDATA 0x004A
CLASS TCDWnd FROM TWindow STATIC
DATA bOnGetData
CLASSDATA lRegistered AS LOGICAL
METHOD HandleEvent( nMsg, nWParam, nLParam )
ENDCLASS
//----------------------------------------------------------------------------//
METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS TCDWnd
local nDataID := 0, cData
if nMsg == WM_COPYDATA
if ::bOnGetData != nil
cData := ParseCopyData( nLParam, @nDataID )
Eval( ::bOnGetData, Self, nWParam, nDataID, cData )
return 0
endif
endif
return ::Super:HandleEvent( nMsg, nWParam, nLParam )
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
#pragma BEGINDUMP
#include <windows.h>
#include <hbapi.h>
HB_FUNC (SENDDATATOAPP) // ( hDestWnd, nMsgID, cData, hFromWnd )
{
COPYDATASTRUCT cds;
cds.dwData = hb_parnl( 2 );
cds.cbData = hb_parclen( 3 );
cds.lpData = (PVOID) hb_parcx( 3 );
SendMessage( (HWND) hb_parnl( 1 ), WM_COPYDATA, (WPARAM) (HWND) hb_parnl( 4 ), (LPARAM) (LPVOID) &cds );
hb_ret();
}
HB_FUNC (PARSECOPYDATA)
{
PCOPYDATASTRUCT pCDS;
pCDS = (PCOPYDATASTRUCT) hb_parnl( 1 );
hb_stornl( pCDS->dwData, 2 );
hb_retclen( pCDS->lpData, pCDS->cbData );
}
#pragma ENDDUMP
//============================================================================//
Independently compile and build the two exes wndsend.exe and wndget.exe, either in Harbour or xHarbour.
wndsend.prg opens and shows browse of customer.dbf in fwh\samples folder. You may need the exe files located in fwh\samples folder or have the customer.dbf in the same folder where the wndsend.exe resides.
Launch both programs and move the windows so that you can see both windows without overlapping each other.
wndget.exe shows browse of an empty array with three columns.
wndsend.exe shows browse of customer.dbf. Move to any row of the browse and click "SendMsg" button on the buttonbar.
Now this program sends an array of CUSTOMER->FIRST, CUSTOMER->LAST, CUSTOMER-CITY to WndGet.Exe through WM_COPYDATA message.
WndGet.exe responds to WM_COPYDATA message and retrieves the data, appends to the array and displays the data in the browse.
Keep moving to different rows in the customer browse of WndSend.Exe and press "SendMsg" button. The information of the row is received by WndGet.Exe and shown in its array browse.
Notes:
I have used SendMessage() function to send the messages. Those who are aware the difference between SendMessage() and PostMessage() may be tempted to use PostMessage(), but that does not work here.
The disadvantage of SendMessage() is that the sending program waits till the responding application completes processing the message ( or ignores ). In the case of our example, till the HandleEvent method returns 0.
Therefore the responding program should retrieve and store the message and signal handling of the event fast.