问题
When the user clicks the window title/button in the taskbar, what .NET event (or Windows API message) is sent to the window?
I'm using C#/.NET 2.0/Windows Forms.
Thank you
回答1:
To discover the messages that are send to a window at various points you should consider using Microsoft Spy++. On my machine it is located at the following path
"D:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\spyxx.exe"
Note I am using 64bit OS hence the (x86).
The type and number of messages is quite big and I am sure varies slightly between OS versions like XP and Windows 7. However the key events/mesages would probably remain pretty constant.
WM_ACTIVATE (When activating and deactivating) WM_WINDOWPOSCHANGING WM_WINDOWPOSCHANGED etc.
Another good tool is ManagedSpy, but I have not tried it on anything other than XP, it does not seem to run on Windows 7 64bit, but I have not done much investigation (Yet!). http://msdn.microsoft.com/en-us/magazine/cc163617.aspx
回答2:
The Activated and Deactivate events usually occur when you click on the taskbar button, but not always. They also occur when you just click on the window or click away to another window.
The one time I found that they don't occur is when the window is active, you click on the taskbar button to minimize the app, and Deactivate occurs as well as Activated. Then when you click on the taskbar button to restore the window, the Activated event doesn't fire. This seems weird to me.
来源:https://stackoverflow.com/questions/2835374/what-event-is-sent-to-a-windows-forms-window-when-its-button-from-the-taskbar-is