how do i send messages to other applications? what i want to do is send some text into WordPad from another program.

i tried invoking EnumWindows to get the handle of WordPad then invoking PostMessage hWordPadWin, WM_CHAR, "A", 1 but it doesn't seem to do anything. Is WM_CHAR the right message to insert some code into WordPad? Here is part of my code,

...
.if uMsg == WM_CREATE
invoke EnumWindows, addr EnumWinsProc, 0
...

EnumWinsProc proc hWin :DWORD,
lParam :DWORD
invoke GetClassName, hWin, offset sztextstring, 64
mov edx, offset sztextstring
mov ebx, offset szWordPad
mov ecx, 64

comparestring:
mov al,
mov ah,
cmp al, ah
jne notstring
cmp al, 0
jne notyet
cmp ah, 0
je stringisequal
notyet: inc edx
inc ebx
dec ecx
jne comparestring

notstring:
xor ebx, ebx
xor ecx, ecx
xor edx, edx
mov eax, 1
ret

stringisequal:
invoke PostMessage, hWin, WM_CHAR, "A", 1
.if eax==0
invoke GetLastError
invoke FormatMessage, FORMAT_MESSAGE_FROM_SYSTEM, 0, eax, 0, offset sztextstring, 64, 0
PrintString sztextstring
.endif
xor ebx, ebx
xor ecx, ecx
xor edx, edx
return 0
ret

EnumWinsProc endp
Posted on 2002-03-25 23:07:46 by Spider
i normally use keybd_event for a window that is assumed to be in the foreground, though SendMessage or PostMessage are slightly more flexible in handling these types of things.

WordPad might be trapping WM_KEYUP or WM_KEYDOWN instead. Try sending those instead.
Posted on 2002-03-25 23:38:41 by jademtech
You have to enumerate the child windows as well to get wordpad's edit window.
Posted on 2002-03-26 00:49:14 by grv575
Spider,

If you can get the main window handle of the instance of Wordpad that is running, getting the handle of the edit control is easy enough. You can then try using rich edit control messages with it but be aware that there are limitations to what you can do as the two apps run in different memory space.

Regards,

hutch@movsd.com
Posted on 2002-03-26 02:06:20 by hutch--
hey thanks all. the reason i need to do this is because i am writing a japanese ime which uses hand-writing recognition, all in assembly. another question, can i make my own child window in another application? and is it the same for word 2000, i don't think it uses a rich-edit control?
Posted on 2002-03-26 02:53:34 by Spider
If you want to send text to winword, check out the DDE functions in the SDK helpfile.
DDE = Dynamic Data Exchange.

Winword is a DDE-enabled server.

Here's an example (in basic)
http://www.techsoft.de/htbasic/support/ddeexam5.htm

Just convert to ASM syntax
Posted on 2002-03-26 03:25:00 by Jurgen
For word2000, DDE would really be the preferred way to go but if you just want a quick hack you can change the wordpad example to these classnames:

szWordPad db "OpusApp",0
szWordPadEdit db "_WwG",0
Posted on 2002-03-26 03:32:11 by grv575
i changed the class name to "OpusApp" and the other one to "_WwG" and it was fine for single byte character sets, but when i invoke a WM_IME_CHAR with PostMessageW and send some unicode in a different language a ? mark is shown. does the control use unicode, or would it use other encodings like SJIS etc.? am i best to use that DDE thing? here is my current code.

; #########################################################################

.486 ; create 32 bit code
.model flat, stdcall ; 32 bit memory model
option casemap :none ; case sensitive

include template.inc ; local includes for this file
include dbmacros.asm
include errormac.asm
include \masm32\include\debug.inc
includelib \masm32\lib\debug.lib

EnumWinsProc PROTO :DWORD,:DWORD
EnumChildWinsProc PROTO :DWORD,:DWORD

.data

hWndWordPad dd 0
sztextstring db 65 dup (0)
szWordPad db "OpusApp",0 ;"WordPadClass",0
szWordPadEdit db "_WwG",0

.code

start:
invoke EnumWindows, addr EnumWinsProc, 0
invoke EnumChildWindows, hWndWordPad, addr EnumChildWinsProc, 0
invoke ExitProcess,0

EnumWinsProc proc uses ebx haWnd :DWORD, lParam :DWORD
invoke GetClassName, haWnd, offset sztextstring, 64
mov edx, offset sztextstring
mov ebx, offset szWordPad
mov ecx, 64

comparestring:
mov al,
mov ah,
cmp al, ah
jne notstring
cmp al, 0
jne notyet
cmp ah, 0
je stringisequal
notyet: inc edx
inc ebx
dec ecx
jne comparestring

notstring:
xor ebx, ebx
xor ecx, ecx
xor edx, edx
mov eax, 1
ret

stringisequal:
mov eax, haWnd
mov hWndWordPad,eax
xor ebx, ebx
xor ecx, ecx
xor edx, edx
xor eax, eax
ret

EnumWinsProc endp

EnumChildWinsProc proc uses ebx hWnnd :DWORD, lParam :DWORD
invoke GetClassName, hWnnd, offset sztextstring, 64
PrintString sztextstring

mov edx, offset sztextstring
mov ebx, offset szWordPadEdit
mov ecx, 64

acomparestring:
mov al,
mov ah,
cmp al, ah
jne anotstring
cmp al, 0
jne anotyet
cmp ah, 0
je astringisequal
anotyet: inc edx
inc ebx
dec ecx
jne acomparestring

anotstring:
xor ebx, ebx
xor ecx, ecx
xor edx, edx
mov eax, 1
ret

astringisequal:
invoke PostMessageW, hWnnd, WM_IME_CHAR, 3056h, 1
.if eax==0
invoke GetLastError
invoke FormatMessage, FORMAT_MESSAGE_FROM_SYSTEM, 0, eax, 0, offset sztextstring, 64, 0
PrintString sztextstring
.endif
PrintString sztextstring
xor ebx, ebx
xor ecx, ecx
xor edx, edx
xor eax, eax
ret

EnumChildWinsProc endp


end start
Posted on 2002-03-26 05:11:31 by Spider
yeah the DDE will obviously perform all the unicode/etc translation for you
Posted on 2002-03-26 13:18:27 by grv575
maybe i'm missing something here, but if you're just trying to get the handle of other apps, use FindWindow to get the parent, and FindWindowEx to get the child windows, that's the easiest method, then use SendMessage or PostMessage to send the message :)
Posted on 2002-03-27 04:40:55 by Asm_Freak
got a parent/child example here. maybe this could help too.
Posted on 2003-12-26 07:11:13 by raidu