Windows消息 [英] Windows Messages
问题描述
您好,当我的表单没有焦点时,是否可以获取Windows消息?
感谢您的答复,但我有一个问题:
我有Windows窗体应用程序而不是控制台应用程序,并且我修改了代码以过滤消息:
Hello, is it possible to get windows messages when my form doesn''t have focus?
thank you for the reply, but I have a problem:
I have a Windows Forms Application not a Console Application and I modified the code to filter the messages:
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == 0x0319)
{
MessageBox.Show("");
}
}
现在,每当我在Windows Media Center的遥控器上按一个按钮(如播放,暂停)时,我都应该看到一个MessageBox.当表单具有焦点时,代码可以正常工作,但是当我单击另一个应用程序(例如,浏览器)时,再也看不到MessageBox了.
P.S.我的应用程序的目标是使遥控器可以与所有音乐/视频播放器一起使用.
Now each time I press a button(like play, pause) on my Windows Media Center''s remote control I should see a MessageBox. The code works fine when my form has focus but when I click another application(for example my browser) I don''t see any more that MessageBox.
P.S. My application''s goal is to make the remote control work with all the music/video players.
推荐答案
是.
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
Console.WriteLine(m.ToString());
}
警告:请勿运行此程序并期望良好的响应时间.您会收到很多Windows消息,因此响应速度会很慢,因为控制台输出会像疯子一样滚动!
WARNING: Don''t run this and expect good response times. You will get a lot of windows messages, and thus slow response because the console output will be scrolling like a loony!
看起来就像您正在构建间谍应用程序.
Looks like you are building a spy application.
这篇关于Windows消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!