unalçaliskan55
Üye
- Katılım
- 14 Kas 2017
- Mesajlar
- 4
- Puanları
- 1
- Yaş
- 36
Option Explicit
Private Const WM_COPYDATA As Long = &H4A 'An application sends the WM_COPYDATA message to pass data to another application.
Private Type COPYDATASTRUCT 'Contains data to be passed to another application by the WM_COPYDATA message.
dwData As Long ' The data to be passed to the receiving application.
cbData As Long ' The size, in bytes, of the data pointed to by the lpData member.
lpData As Long ' The data to be passed to the receiving application. This member can be NULL.
End Type 'http://msdn.microsoft.com/en-us/library/ms649010(v=vs.85).aspx
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageW" (ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
Private Declare Function SysReAllocString Lib "oleaut32.dll" (ByVal pBSTR As Long, Optional ByVal pszStrPtr As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
Public Sub SendData(ByRef frmSender As Form, ByVal OtherApphWnd As Long, ByRef strMsg As String)
Dim CDS As COPYDATASTRUCT
CDS.dwData = frmSender.hWnd 'WM_COPYDATA needs to know who sent
CDS.cbData = LenB(strMsg) + 2& 'Include room for null terminator so SysReAllocString
CDS.lpData = StrPtr(strMsg) 'can determine the string's length
'SendMessage won't return until the data has been sent and the recipient has responded.
SendMessage OtherApphWnd, WM_COPYDATA, CDS.dwData, CDS
End Sub
Public Function MainWndProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim mainRect As RECT
Dim wp As WINDOWPOS
Select Case uMsg
Case WM_COPYDATA
Dim CDS As COPYDATASTRUCT, strMsg As String 'It would be more efficient if no vars were dim'ned in the subclass procedure
CopyMemory CDS, ByVal lParam, LenB(CDS) 'Copy the data into a local buffer
SysReAllocString VarPtr(strMsg), CDS.lpData 'Retrieve a copy of the string data into strMsg
MainWndProc = 1& 'Return TRUE to signal that the message was processed
MsgBox """" & strMsg & """"
Exit Function
Case 12
Form1.Text1 = "Message from App1"
Form1.Text2 = uMsg
Form1.Text3 = wParam
Form1.Text4 = lParam
MainWndProc = 1&
Exit Function
End Select
MainWndProc = CallWindowProc(MainOldWindPoc, hWnd, uMsg, wParam, lParam)
End Function
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?