Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / December 2006

Tip: Looking for answers? Try searching our database.

using SendMessage with notepad

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Anja - 17 Dec 2006 15:07 GMT
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
Anja - 17 Dec 2006 15:18 GMT
> Hi everyone,
>
[quoted text clipped - 47 lines]
> 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
Douglas J. Steele - 17 Dec 2006 16:17 GMT
Why are you trying to automate Notepad?

Can you not simply read the data from the text file into a variable, do
whatever manipulations you need to with the text, and then write the data
back out (if need be)?

It's entirely possible that SendMessage will not work in the way you're
hoping, since Notepad doesn't expose itself for automation.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)

> Hi everyone,
>
[quoted text clipped - 52 lines]
> Thx,
> Anja
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.