| Re: using SendMessage with notepad |
|
 |
|
 |
|
 |
|
 |
Group: microsoft.public.access.modulesdaovba · Group Profile
Author: AnjaAnja Date: Dec 17, 2006 07:18
Anja wrote:
> 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.
Ok, I figured out that I had to use the WM_SETTEXT message.
Can someone tell me how I can use SendMessage to send the keystroke
(Alt F). Do I have to use 2 sendmessage calls?
Cheers,
Anja
>
> Please help.
>
> Thx,
> Anja
|