G
Guest
I need to send a message to a window in another application. The name of the
window is known at design time and set in the constant App2_MONITOR_CAPTION.
The message is defined as X_GenerateEvent.
The following VB6 code works. I assume this is possible in C#. How do you do
it?
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)
As Long
Private Declare Function RegisterWindowMessage Lib "user32" Alias
"RegisterWindowMessageA" (ByVal lpString As String) As Long
Private Const App2_MONITOR_CAPTION = "App2 Custom Monitor"
Private App2_GenerateEvent As Long
Private Sub Command1_Click()
Dim handle As Long
handle = FindWindow(vbNullString, App2_MONITOR_CAPTION)
If handle = 0 Then Exit Sub
App2_GenerateEvent = RegisterWindowMessage("X_GenerateEvent")
SendMessage handle, App2_GenerateEvent, 0, 0
End Sub
window is known at design time and set in the constant App2_MONITOR_CAPTION.
The message is defined as X_GenerateEvent.
The following VB6 code works. I assume this is possible in C#. How do you do
it?
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)
As Long
Private Declare Function RegisterWindowMessage Lib "user32" Alias
"RegisterWindowMessageA" (ByVal lpString As String) As Long
Private Const App2_MONITOR_CAPTION = "App2 Custom Monitor"
Private App2_GenerateEvent As Long
Private Sub Command1_Click()
Dim handle As Long
handle = FindWindow(vbNullString, App2_MONITOR_CAPTION)
If handle = 0 Then Exit Sub
App2_GenerateEvent = RegisterWindowMessage("X_GenerateEvent")
SendMessage handle, App2_GenerateEvent, 0, 0
End Sub