如何让我的控制台应用程序接收窗口消息?

发布于 2024-10-03 19:43:12 字数 465 浏览 0 评论 0原文

我需要在控制台应用程序中编写一个消息处理程序来处理收到的消息。例如,我注册 WM_Test 并将其发送到我的控制台应用程序,如下所示:

var
  H: THandle;
begin
  H:= FindWindow('ConsoleWindowClass', nil);
  PostMessage(H, WM_Test, 0, 0);
end;

现在我希望当我在控制台应用程序中收到此消息时显示一个消息框。

我可以在控制台程序中使用 PeekMessage 或 AllocateHWND 吗?

我知道我可以使用 来完成这项工作管道,但我想知道是否可以使用窗口消息来做到这一点。

I need to write a message handler in my console application that handles received messages. For example, I register WM_Test and send it by to my console application like this:

var
  H: THandle;
begin
  H:= FindWindow('ConsoleWindowClass', nil);
  PostMessage(H, WM_Test, 0, 0);
end;

Now I want when I receive this message in my console application to show a message box.

Can I use PeekMessage or AllocateHWND in console programs?

I know that I can do this work with a pipe, but I want know whether I can do this with window message.

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

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

发布评论

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

评论(1

等往事风中吹 2024-10-10 19:43:12

是的,你可以。使用 AllocateHWND 创建窗口句柄。然后,您可以设置各种属性(例如名称),以便您可以使用 FindWindow 找到它。

Yes you can. Use AllocateHWND to create a window handle. Then, you can set various properties (like the name), so you can find it using FindWindow.

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