If you know the window handle, then
GetWindowThreadProcessId (returning a process id) and
OpenProcess (returning a process handle from process id) should help.
However I don't know if you can write to arbitrary process's memory space
...(I don't think you can
)