I'm tryingt to send text (the word "Hello" for now) to an "Untitled - Notepad" document. I can change the title bar, but not the text field. What am I doing wrong?


I'm using VB 5.0 in WinXP OS.

VB Code:
  1. Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
  2. Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
  3. Private Declare Function SendMessageByStr& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String)
  4. 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
  5. Private Declare Function PostMessageA Lib "user32" (ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  6. Private Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  7. Private Declare Function PostMessageByStr& Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String)
  8.  
  9.  
  10. Private Const WM_SETTEXT = &HC
  11. 'Private Const EM_SETSEL = &HC
  12. 'Private Const WM_CHAR As Long = &H102
  13.  
  14. Private Sub Command1_Click()
  15. Dim x&
  16. Dim richedit&
  17.     Dim WinWnd As Long, Ret As String, RetVal As Long, lpClassName As String
  18. Ret = "Untitled - Notepad"
  19.     WinWnd = FindWindow(vbNullString, Ret)
  20.     If WinWnd = 0 Then MsgBox "Could not find the window ...": Exit Sub
  21.     MsgBox WinWnd '####PRROLLLY wanna taket his out at some point
  22.    
  23.     Dim sText As String
  24.     sText = "Hello"
  25. SendMessageByStr WinWnd, WM_SETTEXT, 0, "hello" ' PUTS hello into the title bar of the notepad. Kinda cool, but... not my goal
  26. SendMessage WinWnd, WM_SETTEXT, 0, "hello" ' PUTS bizar characters into the App bar... Definatly, not my goal
  27. PostMessage WinWnd, WM_SETTEXT, 0, "hello" ' Type Mismatch Error
  28. PostMessageByStr& WinWnd, WM_SETTEXT, 0, "hello" ' Does absolutely nothing
  29. End Sub