SendMessage()

Jul 21, 2011 at 1:38am
I'm making a simple console program that will use FindWindow to get the HWND of another program that is open. I'm then looping in a while loop trying to use SendMessage(), but when I'm running the program it never actually leaves the loop where it's trying to send the message.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "stdafx.h"
#include <Windows.h>

#define GAME_TO_MASTER_COMPLETE	 4
int send_successful = 0;

int main(int argc, char * argv[])
{
HWND master_window_handle = FindWindowA(0, "Master");
send_successful = 0;

	while(!send_successful) {
	Sleep(3); 
	send_successful = SendMessage(master_window_handle, WM_COMMAND, GAME_TO_MASTER_COMPLETE, NULL);
	}

return 0;
}


I've tried printing out the master_window_handle to make sure it's giving me back a Window and that is working fine. I'm certain the program I'm sending the message to is working correctly when processing messages because it is already receiving other messages. Any help would be greatly appreciated. Thanks!
Last edited on Jul 21, 2011 at 1:39am
Jul 21, 2011 at 1:50am
The SendMessage function does not return a bool (or int) indicating success. In this case, the return value of the SendMessage function is whatever the WndProc of "Master" returns for this particular message. If it returns zero (not sure what it will return if it is a void function), then send_successful will be zero. The infinite loop is likely due to the WndProc returning zero or due to the WndProc being a void function.
Last edited on Jul 21, 2011 at 1:52am
Topic archived. No new replies allowed.