如何使用Windows + m键盘快捷键最小化我的应用程序? [英] How to minimize my application with the Windows+m keyboard shortcut?

查看:117
本文介绍了如何使用Windows + m键盘快捷键最小化我的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VB.NET 2008中有一个简单的winforms应用程序.我使用的表单具有完全自定义的外观,因此没有标题栏,因此没有最小化,最大化和关闭按钮.我已经创建了自定义控件来替换这些控件.

I have a simple winforms application in VB.NET 2008. I am using a form with a completely custom look, so there is no title bar, thus no minimize, maximize, and close buttons. I've created custom controls to replace those.

如果我正在运行我的应用程序,然后单击显示桌面"快捷方式,则所有程序(包括我的程序)都将最小化.但是,如果我使用 Windows + M 快捷方式,则除我以外的所有程序都将最小化.似乎缺少表单上的内置最小化按钮导致我的应用忽略了 Windows + M .

If I have my app running, and I click the 'Show Desktop' shortcut, all the programs minimize properly, including mine. But, if I use the Windows + M shortcut, all the programs EXCEPT mine minimize. It seems that the lack of the built-in minimize button on the form causes my app to ignore Windows + M.

如何检测 Windows + M ,特别是在我的应用程序未激活的情况下,或者如何复制内置的最小化"按钮的功能?

How can I detect Windows + M, especially if my app is not active, or how can I duplicate the functionality of the built-in Minimize button?

我尝试实现以下代码,但没有成功.

I've tried implementing the following code, with no success.

Const WM_SIZE As Integer = &H5
Const SIZE_MINIMIZED As Integer = &H1

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
  MyBase.WndProc(m)

  If m.Msg = WM_SIZE Then
     If m.WParam = SIZE_MINIMIZED Then
        //Minimize the form.
        Me.WindowState = FormWindowState.Minimized
     End If

  End If
End Sub

这似乎是正确的方法(感谢SLaks),但是我的应用似乎没有收到来自 Windows + M 的任何消息.或者,更有可能的是,我没有正确拦截它们.

This seems like the right approach (thanks to SLaks), but my app doesn't seem to be receiving any messages from Windows + M. Or, more likely, I'm not intercepting them properly.

我已经检查了我的应用程序通过Spy ++收到的消息(再次感谢SLaks),并且似乎WM_SIZE消息未发送到我的应用程序.我尝试了带有标准标题栏和按钮的常规winforms应用程序,当按 Windows + M 时,它会按预期收到WM_SIZE消息.某种程度上,缺少标题栏会阻止在自定义窗体的WndProc中接收到WM_SIZE消息.

I've checked out the messages that my app is receiving with Spy++ (thanks again SLaks) and it looks like the WM_SIZE message is not getting sent to my app. I tried a regular winforms app with the standard title bar and buttons, and it receives the WM_SIZE message as expected when Windows + M is pressed. Somehow the lack of a title bar is preventing the WM_SIZE message from being received in my custom form's WndProc.

我越深入研究这个问题,我就越认为解决这种问题的方法就越多.我已经确认,如果表单没有边框,则不会收到WM_SIZE消息.坐在我旁边的开发人员在Qt中使用C ++,并且表现出完全相同的行为:当按下 Windows + M 时,没有窗体/窗口边框=没有消息可最小化. Windows + D 确实可以使所有内容最小化,但是我相信这与显示桌面"按钮相同.

The more I dig into this, the more that I think there may not be a way around this behavior. I've confirmed that if the form does not have a border, no WM_SIZE message is received. The developer sitting next to me uses C++ in Qt, and the exact same behavior is exhibited: No form/window border = no message to minimize when Windows + M is pressed. Windows + D does work to minimize everything, but I believe that is a duplicate of the Show Desktop button.

我得出的结论是,如果表单没有边框,Windows甚至不会生成消息,因此无法拦截它.我注意到Windows Media Player表现出了相同的行为.处于皮肤模式时, Windows + M 不会将其最小化.

I'm coming to the conclusion that if a form has no border, Windows does not even generate a message, thus there is no way to intercept it. I've noticed that Windows Media Player exhibits this same behavior. When it is in skinned mode, Windows + M does not minimize it.

推荐答案

使用Spy ++检查当按下Window + M时您的应用收到的Windows消息,然后在窗体的WndProc中检查该消息并最小化窗体.

Use Spy++ to check which Windows messages your app receives when Window+M is pressed, then check for that message in your form's WndProc and minimze the form.

Windows + M似乎发送了 消息,且wParam设置为SIZE_MINIMIZED.

It appears that Windows+M sends a WM_SIZE message with wParam set to SIZE_MINIMIZED.

这篇关于如何使用Windows + m键盘快捷键最小化我的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆