What event is sent to a Windows Forms window when its button from the taskbar is clicked?

风流意气都作罢 提交于 2019-12-10 20:57:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!