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:
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 Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long Private Declare Function SendMessageByStr& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) 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 PostMessageA Lib "user32" (ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long 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 Private Declare Function PostMessageByStr& Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) Private Const WM_SETTEXT = &HC 'Private Const EM_SETSEL = &HC 'Private Const WM_CHAR As Long = &H102 Private Sub Command1_Click() Dim x& Dim richedit& Dim WinWnd As Long, Ret As String, RetVal As Long, lpClassName As String Ret = "Untitled - Notepad" WinWnd = FindWindow(vbNullString, Ret) If WinWnd = 0 Then MsgBox "Could not find the window ...": Exit Sub MsgBox WinWnd '####PRROLLLY wanna taket his out at some point Dim sText As String sText = "Hello" SendMessageByStr WinWnd, WM_SETTEXT, 0, "hello" ' PUTS hello into the title bar of the notepad. Kinda cool, but... not my goal SendMessage WinWnd, WM_SETTEXT, 0, "hello" ' PUTS bizar characters into the App bar... Definatly, not my goal PostMessage WinWnd, WM_SETTEXT, 0, "hello" ' Type Mismatch Error PostMessageByStr& WinWnd, WM_SETTEXT, 0, "hello" ' Does absolutely nothing End Sub




Reply With Quote