A
Anja
Hi everyone,
I am trying to use SendMessage to send a WM_CHAR to a running instance
of Notepad.
So, in my simple VBA example, I am trying to send the character 'Q' to
the notepad and this should show this in the editor area, right?
So, I have the following API declarations:
WM_CHAR message
Public Const WM_CHAR = &H102
' Right control key
Public Const VK_RCONTROL = &HA3
' Q key
Public Const VK_Q = &H51
Private Declare Function EnumWindows Lib "user32" _
(ByVal lpEnumFunc As Long, _
ByVal lParam As Long) As Long
Private Declare Function GetWindowText Lib "user32" _
Alias "GetWindowTextA" _
(ByVal hwnd As Long, _
ByVal lpString As String, _
ByVal cch As Long) As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal _
hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)
As Long
I also have functions that can do wildcard comparisons for the
FindWindow
So, in my code I have the following:
Dim appHWnd As Long
appHWnd = FnFindWindowLike("*Note*")
If (appHWnd) Then
SendMessage appHWnd, WM_CHAR, VK_Q, ByVal 0&
Else
MsgBox "Could not find a running instance of "
End If
I see that the windo handle is returned and the SendMessage call gets
executed, but I do not see a 'Q' in the notepad window.
Does the window have to have the focus for SendMessage to work or have
I misunderstood this whole process.
Please help.
Thx,
Anja
I am trying to use SendMessage to send a WM_CHAR to a running instance
of Notepad.
So, in my simple VBA example, I am trying to send the character 'Q' to
the notepad and this should show this in the editor area, right?
So, I have the following API declarations:
WM_CHAR message
Public Const WM_CHAR = &H102
' Right control key
Public Const VK_RCONTROL = &HA3
' Q key
Public Const VK_Q = &H51
Private Declare Function EnumWindows Lib "user32" _
(ByVal lpEnumFunc As Long, _
ByVal lParam As Long) As Long
Private Declare Function GetWindowText Lib "user32" _
Alias "GetWindowTextA" _
(ByVal hwnd As Long, _
ByVal lpString As String, _
ByVal cch As Long) As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal _
hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)
As Long
I also have functions that can do wildcard comparisons for the
FindWindow
So, in my code I have the following:
Dim appHWnd As Long
appHWnd = FnFindWindowLike("*Note*")
If (appHWnd) Then
SendMessage appHWnd, WM_CHAR, VK_Q, ByVal 0&
Else
MsgBox "Could not find a running instance of "
End If
I see that the windo handle is returned and the SendMessage call gets
executed, but I do not see a 'Q' in the notepad window.
Does the window have to have the focus for SendMessage to work or have
I misunderstood this whole process.
Please help.
Thx,
Anja