Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Sync record pointer on 2 running apps
Message
 
À
05/09/2005 16:50:56
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 7 SP1
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Divers
Thread ID:
01046837
Message ID:
01046898
Vues:
19
Hi Randy,

>I have a Point of Sale app running and an Inventory app on the task bar. How can I 'grow' the inventory app on the same record as the Point of Sale?

You need some sort of interprocess communication. Here are three possibilities:

1) In one application install a timer. The timer regularly checks a record in a table. If the content changes it reads the record number from the record and moves the record pointer. The POS application writes the record number into the table everytime the record pointer moves.

2) You create a COM EXE server compiled as a multi-use server. When you instantiate an object in this server from any application, all objects are stored in the same instance. The first object created in the COM server creates a public collection object. All applications put a reference to their application object into the collection. This way, an application can use the collection to talk directly to any other registered application. In VFP 7 you have to replace the collection with an array

3) With VFP 9 you can use BINDEVENT() to bind to the WM_COPYDATA message. This allows you to send data from one application to another. Here's a sample. The sending side (POS application):
*========================================================================================
* Sends data to another program
*========================================================================================
LParameter tnSrcHWND, tnDstHWND, tcData, tnIdentifier

	*--------------------------------------------------------------------------------------
	* Declare API functions
	*--------------------------------------------------------------------------------------
	Declare Long HeapAlloc in win32api Long, Long, Long
	Declare Long GetProcessHeap in win32api
	Declare Long HeapFree in win32api Long, Long, Long

	#define WM_COPYDATA 0x4A
	
	*--------------------------------------------------------------------------------------
	* Create a COPYDATASTRUCT structure
	*--------------------------------------------------------------------------------------
	Local lcStruct, lnMem
	lnMem = HeapAlloc( GetProcessHeap(), 0, Len(m.tcData)+12 )
	lcStruct = ;
		toInt(m.tnIdentifier,4) + ;
		toInt(Len(m.tcData),4) + ;
		toInt(m.lnMem+12,4) + ;
		m.tcData
	Sys(2600,m.lnMem,Len(m.lcStruct),m.lcStruct)
		
	*--------------------------------------------------------------------------------------
	* Send data to the other application
	*--------------------------------------------------------------------------------------
	Local lnRetVal
	Declare Long SendMessage in win32api Long, Long, Long, Long
	lnRetVal = SendMessage( m.tnDstHWND, WM_COPYDATA, m.tnSrcHWND, lnMem )
	
	*--------------------------------------------------------------------------------------
	* Free up memory
	*--------------------------------------------------------------------------------------
	HeapFree( GetProcessHeap(), 0, m.lnMem )

Return m.lnRetVal
The receing side (inventory app):
*========================================================================================
* Set up a handler to receive data posted with WM_COPYDATA
*========================================================================================

#define WM_COPYDATA 0x004A
_Screen.WindowState =1
Public goCOPYDATA
goCOPYDATA = CreateObject("COPYDATA_Handler")
? "handle: ", Transform(goCOPYDATA.hWND,"@0")

Define Class COPYDATA_Handler as Form

	Procedure Init
		BindEvent( This.hWND, WM_COPYDATA, This, "WndProc" )
	EndProc 
	
	Function WndProc
	Lparameters tnHwnd, tnMsg, tnWParam, tnLParam
		Local lcStruct, lnIdentifier, lcData
		lcStruct = Sys(2600,m.tnLParam,12)
		lnIdentifier = FromInt(Left(m.lcStruct,4))
		lcData = Sys(2600,FromInt(Right(m.lcStruct,4)),FromInt(SubStr(m.lcStruct,5,4)))
_Screen.WindowState = 0

		? lnIdentifier, lcData
	Return 99
	
EndDefine
--
Christof
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform