sending message to another app

hello i want to send a BT_CLICKED to another app.(which is a setup application with a next btn and a close btn)
How can i use sendmessage to click the next btn?
[169 byte] By [immortal20] at [2007-11-18 17:38:45]
# 1 Re: sending message to another app
I guess first i should ask how to get the window into HWnd
immortal20 at 2007-11-11 1:26:25 >
# 2 Re: sending message to another app
I was able to find a solution to a similar problem of mine through the following thread: http://www.dev-archive.com/forum/showthread.php?postid=907664#post907664. Good luck!
eoge at 2007-11-11 1:27:17 >
# 3 Re: sending message to another app
Ok now i have this and seems to work.

CWnd* cwnd = FindWindow(NULL,"Setup - Spybot - Search & Destroy");
CWnd* TButton = cwnd->GetDlgItem(0x0008031A); // this is the next button id

so now can i use sendmessage or postmessage to click the button, I'm so close i can feel it.
immortal20 at 2007-11-11 1:28:27 >
# 4 Re: sending message to another app
What is BT_CLICKED? If that is not what you mean, then find the right whatever and then search this forum for it first before asking about it.
Sam Hobbs at 2007-11-11 1:29:21 >
# 5 Re: sending message to another app
I meant BN_CLICKED. I Did search the forum, and i got the answer, but sad to say it is not working. I'm getting an error when it gets to sendmessage. here is the code.

CWnd *cwnd = FindWindow(NULL,"Setup - Spybot - Search & Destroy");
CWnd *button = cwnd->GetDlgItem(0x0008031A);
button->SendMessage(BN_CLICKED,1,0);
immortal20 at 2007-11-11 1:30:20 >
# 6 Re: sending message to another app
FindWindow and GetDlgItem return NULL if they did not work. You should check for NULL to prevent a problem.

However I assume that is not the current problem. I don't know where you found the answer, but that SendMessage is way, way off. Search again; the answer is easy to find.
Sam Hobbs at 2007-11-11 1:31:22 >
# 7 Re: sending message to another app
I checked the return value of getdlgitem and its giving me a 0. So basically it's null.
But the button does exist and that is the control id.
Why is it giving me a null when it does exist?
immortal20 at 2007-11-11 1:32:26 >
# 8 Re: sending message to another app
Ok i got it working, but of course another problem occurs.
The control id changes everytime i start up the app(not mine).
Why does it do that and can programmaticaly get the control id everytime the program starts?
immortal20 at 2007-11-11 1:33:31 >
# 9 Re: sending message to another app
Yes it is unusual for the control id to vary, but it certainly can. Are you sure that is what is happening? You can use Spy++ to be sure. If that is happening, then the program is doing things differently from most programs, but otherwise it is not strange or whatever.

I am not sure what the best solution is, but probably you can use FindWindow again, using the parent window and the button text for the window text.

I searched my source code and found my sample of sending a BN_CLICKED. Yours will vary but this should be close enough.WPARAM WParam = MAKEWPARAM(IDCANCEL, BN_CLICKED);
GetParent()->PostMessage(WM_COMMAND, WParam, NULL);
Sam Hobbs at 2007-11-11 1:34:28 >
# 10 Re: sending message to another app
I think the reason why the control id is changing is because it is a setup program(installshield).

Does anyone else know how i can get the control id of a button on another app?
immortal20 at 2007-11-11 1:35:27 >