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.
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.
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?
EDIT:
I've tried implementing the following code, with no success.
Const WM_SIZE As Integer = &H5
Const SIZE_MINIMIZED As Integer = &H1
Protected开发者_StackOverflow中文版 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
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.
EDIT:
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.
EDIT:
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.
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.
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.
It appears that Windows+M sends a WM_SIZE
message with wParam set to SIZE_MINIMIZED
.
Check this forum http://www.windows-tech.info/3/e4b66d1b1b690888.php the solution is to override the CreateParams method of the form.
I face the same problem. The solution I found, is to hide the application when it's minimized. So the icon is visible in the taskbar when the window is open, but not visible when the application is minimised.
精彩评论