I’m addapting a IR TV controller to the computer. So far I managed to read the controller data, map the keys and assign a great number of functions using JAVA robot class and prompt commands.
I want now to create play/pause, stop volume+ and volume – functions. Problem is it can’t be done diretly through java. I know the right way to do it is by using JNI, but I just don’t have the time to learn it right now.
The solution I found is to create exe files containing only the SendMessage function. For example, the code por the Play/Pase function would be:
#include <windows.h>
#define WM_APP_COMMAND 0x319
#define PLAY_PAUSE 0xE0000
int main() {
SendMessage((HWND)(~0), WM_APP_COMMAND, 0, PLAY_PAUSE);
return 0;
}
The program works, but instead of sending only one single message it keeps sending non-stop.
I have to question. The first, of course, is why the code is not working properly. Is there a break comand missing or something?.
Second is what does assigning ~0 (or 0xFFFF) to the windows handler means.
Thanks, i’m open to any kind of solution.
MSDN SendMesage:
If this parameter is HWND_BROADCAST ((HWND)0xffff), the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up windows; but the message is not sent to child windows.
Broadcasting with SendMessage synchronously sends to all those windows. How this message is handled is app-dependent.
Yes – this approach is as risky as it sounds. Can you find another way to do what you want without HWND_BROADCAST ?
Rgds,
Martin