开发者

SendMessage() is sending multiple messages instead of only one

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, PLA开发者_JS百科Y_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


Ive come across the same problem trying to write a java webserver to control my media PC running mediaportal using only a web browser on the local network as the client but I'm limited to what is in the java.robot class only.

I think the idea of using an exe called from Java is the right one, maybe look at a program that does all the messages instead of having individual exe files. I think this might be like what you are looking for:

http://wiki.team-mediaportal.com/index.php?title=1_MEDIAPORTAL_1/17_Extensions/System_%26_Utilities/SendMessage


~0 is HWND_BROADCAST. The message is sent to all top-level windows in the system. This program sends the message exactly once. Possibly the program is executed many times, or message is handled in multiple windows.

Use Spy++ to investigate this. Spy++ is part of Microsoft SDK and Visual Studio.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜