SendMessage() 正在发送多条消息,而不是只发送一条消息

发布于 2024-11-16 17:23:56 字数 568 浏览 2 评论 0原文

我正在将红外电视控制器添加到计算机上。到目前为止,我设法使用 JAVA 机器人类和提示命令读取控制器数据、映射按键并分配大量功能。

我现在想创建播放/暂停、停止音量+和音量-功能。问题是它不能直接通过java来完成。我知道正确的方法是使用 JNI,但我现在没有时间学习它。

我找到的解决方案是创建仅包含 SendMessage 函数的 exe 文件。例如,Play/Pase 函数的代码为:

#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;
}

程序可以工作,但不是只发送一条消息,而是不停地发送。

我不得不问。首先,当然是代码无法正常工作的原因。是否缺少中断命令或其他什么?

其次,将 ~0(或 0xFFFF)分配给 Windows 处理程序意味着什么。

谢谢,我愿意接受任何解决方案。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一个人的旅程 2024-11-23 17:23:56

MSDN SendMesage:

如果该参数为HWND_BROADCAST((HWND)0xffff),则消息发送到系统中所有顶层窗口,包括禁用或不可见的无主窗口、重叠窗口和弹出窗口;但该消息不会发送到子窗口。

使用 SendMessage 进行广播会同步发送到所有这些窗口。如何处理此消息取决于应用程序。

是的——这种方法听起来就很危险。你能找到另一种没有 HWND_BROADCAST 的方法来做你想做的事吗?

平均值,
马丁

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

深居我梦 2024-11-23 17:23:56

我在尝试编写一个 java web 服务器来控制运行 mediaportal 的媒体 PC 时遇到了同样的问题,仅使用本地网络上的 web 浏览器作为客户端,但我仅限于 java.robot 类中的内容。

我认为使用从 Java 调用的 exe 的想法是正确的,也许看看一个执行所有消息的程序,而不是拥有单独的 exe 文件。
我认为这可能就像您正在寻找的:

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

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

っ〆星空下的拥抱 2024-11-23 17:23:56

~0 是 HWND_BROADCAST。该消息被发送到系统中的所有顶级窗口。该程序只发送一次消息。可能程序被执行多次,或者消息在多个窗口中处理。

使用 Spy++ 来调查这一点。 Spy++ 是 Microsoft SDK 和 Visual Studio 的一部分。

~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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文