Yer need two processes for obvious reasons so below is code for P1 then P2. Not a lot of difference between them but I thought I would post both for us lazy bas...
Code: Select all
; Converted from french forums
; http://purebasic.hmt-forum.com/viewtopic.php?t=716
; Swap mouse coords between two processes using file mapping
; This is Process # 1 (top string gadget)
Enumeration
#Window
#sgP1
#sgP2
EndEnumeration
Structure sdataT
p1x.l: p1y.l
p2x.l: p2y.l
EndStructure
#WM_NEWMESSAGE=111
Global *sdata.sdataT
Procedure WindowCallback(WindowID,Message,wParam,lParam)
Protected r.l
r=#PB_ProcessPureBasicEvents
Select Message
Case #WM_NEWMESSAGE
If wParam=1 And lParam=1
SetGadgetText(#sgP2,"x= "+Str(*sdata\p2x)+" y= "+Str(*sdata\p2y))
EndIf
EndSelect
ProcedureReturn r
EndProcedure
Procedure main()
Protected e.l, f.l, hFMO.l, hWnd.l
f=#PB_Window_SystemMenu|#PB_Window_ScreenCentered
If OpenWindow(#Window,0,0,160,160,f,"Process 1")=0
Debug "ERROR: PB Window failed!"
ProcedureReturn
EndIf
CreateGadgetList(WindowID(#Window))
StringGadget(#sgP1,10, 10,100,20,"")
StringGadget(#sgP2,10, 32,100,20,"")
;HANDLE CreateFileMapping(
; HANDLE hFile, // handle to file to map
; LPSECURITY_ATTRIBUTES lpFileMappingAttributes, // optional security attributes
; DWORD flProtect, // protection for mapping object
; DWORD dwMaximumSizeHigh, // high-order 32 bits of object size
; DWORD dwMaximumSizeLow, // low-order 32 bits of object size
; LPCTSTR lpName // name of file-mapping object
; );
hFMO=CreatefileMapping_($FFFFFFFF, #Null, #PAGE_READWRITE, 0, SizeOf(sdataT), "Mapping")
If hFMO=0: Debug "ERROR: Mapping failed!": ProcedureReturn: EndIf
;LPVOID MapViewOfFile(
; HANDLE hFileMappingObject, // file-mapping object to map into address space
; DWORD dwDesiredAccess, // access mode
; DWORD dwFileOffsetHigh, // high-order 32 bits of file offset
; DWORD dwFileOffsetLow, // low-order 32 bits of file offset
; DWORD dwNumberOfBytesToMap // number of bytes to map
; );
*sdata=MapViewOfFile_(hFMO, #FILE_MAP_WRITE, 0, 0, 0)
SetWindowCallback(@WindowCallback())
Repeat
e=WaitWindowEvent()
Select e
Case #WM_MOUSEMOVE
hWnd=FindWindow_(0,"Process 2")
*sdata\p1x=WindowMouseX(): *sdata\p1y=WindowMouseY()
SetGadgetText(#sgP1,"x= "+Str(*sdata\p1x)+" y= "+Str(*sdata\p1y))
If hWnd: SendMessage_(hWnd, #WM_NEWMESSAGE, 1, 1): EndIf
Case #WM_CLOSE
Quit=1
EndSelect
Until Quit=1
EndProcedure
main()
Code: Select all
; Converted from french forums
; http://purebasic.hmt-forum.com/viewtopic.php?t=716
; Swap mouse coords between two processes using file mapping
; This is Process # 2 (bottom string gadget)
Enumeration
#Window
#sgP1
#sgP2
EndEnumeration
Structure sdataT
p1x.l: p1y.l
p2x.l: p2y.l
EndStructure
#WM_NEWMESSAGE=111
Global *sdata.sdataT
Procedure WindowCallback(WindowID,Message,wParam,lParam)
Protected r.l
r=#PB_ProcessPureBasicEvents
Select Message
Case #WM_NEWMESSAGE
If wParam=1 And lParam=1
SetGadgetText(#sgP1,"x= "+Str(*sdata\p1x)+" y= "+Str(*sdata\p1y))
EndIf
EndSelect
ProcedureReturn r
EndProcedure
Procedure main()
Protected e.l, f.l, hFMO.l, hWnd.l
f=#PB_Window_SystemMenu|#PB_Window_ScreenCentered
If OpenWindow(#Window,0,0,160,160,f,"Process 2")=0
Debug "ERROR: PB Window failed!"
ProcedureReturn
EndIf
CreateGadgetList(WindowID(#Window))
StringGadget(#sgP1,10, 10,100,20,"")
StringGadget(#sgP2,10, 32,100,20,"")
;HANDLE CreateFileMapping(
; HANDLE hFile, // handle to file to map
; LPSECURITY_ATTRIBUTES lpFileMappingAttributes, // optional security attributes
; DWORD flProtect, // protection for mapping object
; DWORD dwMaximumSizeHigh, // high-order 32 bits of object size
; DWORD dwMaximumSizeLow, // low-order 32 bits of object size
; LPCTSTR lpName // name of file-mapping object
; );
hFMO=CreatefileMapping_($FFFFFFFF, #Null, #PAGE_READWRITE, 0, SizeOf(sdataT), "Mapping")
If hFMO=0: Debug "ERROR: Mapping failed!": ProcedureReturn: EndIf
;LPVOID MapViewOfFile(
; HANDLE hFileMappingObject, // file-mapping object to map into address space
; DWORD dwDesiredAccess, // access mode
; DWORD dwFileOffsetHigh, // high-order 32 bits of file offset
; DWORD dwFileOffsetLow, // low-order 32 bits of file offset
; DWORD dwNumberOfBytesToMap // number of bytes to map
; );
*sdata=MapViewOfFile_(hFMO, #FILE_MAP_WRITE, 0, 0, 0)
SetWindowCallback(@WindowCallback())
Repeat
e=WaitWindowEvent()
Select e
Case #WM_MOUSEMOVE
hWnd=FindWindow_(0,"Process 1")
*sdata\p2x=WindowMouseX(): *sdata\p2y=WindowMouseY()
SetGadgetText(#sgP2,"x= "+Str(*sdata\p2x)+" y= "+Str(*sdata\p2y))
If hWnd: SendMessage_(hWnd, #WM_NEWMESSAGE, 1, 1): EndIf
Case #WM_CLOSE
Quit=1
EndSelect
Until Quit=1
EndProcedure
main()