About Windows: what i need to know before simulate the keys?

i build a program for execute(ShellExecute() ) another program. then i change window position program(SetWindowPos() ).
until here fine, but i need to know 2 things:

1 - when we use ShellExecute(), can we Wait until the program window is ready for simulate the keys?

2 - sometimes i fail, without any error message, using the SetWindowPos(). i belive i know why i fail, but i need a correction: if the window program isn't ready, what happens with SetWindowPos()?
(if i use Sleep(2000) between the 1st and second, the SetWindowPos() will works normaly.
if the window program isn't ready, what happens with SetWindowPos()


Check the return value from SetWindowPos and call GetLastError() if neccessary.
is zero. seems that i must wait that the window is ready or something because the:
CTRL+1 or even CTRL+2 makes the window hide and then show it.
so if i use the SendInput() and then the SetWindowPos(), with GetForegroundWindow(), the SetWindowPos() must fail, right?(because can do the job to another window)
Topic archived. No new replies allowed.