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