当窗口最小化时,我想要一个事件处理程序。我正在阅读stackoverflow中的不同帖子,但没有找到完整的解决方案。我的实际问题是described here
与问here类似,我想在C#中使用DefWindowProc句柄。这样我就可以检查消息是否为WM_ACTIVATEAPP,如果应用程序被激活/取消激活,我想做一些业务逻辑。
This answer是有用的,但没有完全解释 - 比如将如何检查我的应用程序中的消息。我是否需要覆盖DefWindowProc
?
任何指针都会有所帮助。
答案 0 :(得分:1)
如何检查表单更改事件:
通过(X)单击“简化”一个简单的测试表单,并使用TaskManager重新激活:
Load Form:
635291025619140000: Got Form1_Resize()
635291025619950000: Got Form1_Resize()
635291025620060000: Got Form1_Resize()
635291025620300000: Got Form1_Resize()
635291025620470000: Got Form1_Activated()
635291025620880000: Got Form1_GotFocus()
Click on (X) to minimize:
635291026059340000: Got Form1_Resize()
635291026059780000: Got Form1_Deactivate()
635291026059950000: Got Form1_LostFocus()
TaskManager SwitchTo:
635291026483820000: Got Form1_Resize()
635291026483910000: Got Form1_Activated()
635291026484010000: Got Form1_GotFocus()
Press Win-Symbol of Form (shows Start screen):
635291026724060000: Got Form1_Deactivate()
635291026724960000: Got Form1_LostFocus()
Click (X) in Start screen:
635291027163520000: Got Form1_Resize()
635291027163610000: Got Form1_Activated()
635291027163710000: Got Form1_GotFocus()
Click (X) of Form:
635291027673050000: Got Form1_Resize()
635291027673470000: Got Form1_Deactivate()
635291027673660000: Got Form1_LostFocus()
Re-Launched externally:
635291028243720000: Got Form1_Resize()
635291028243900000: Got Form1_Activated()
635291028244010000: Got Form1_GotFocus()
你看到你总是得到Deactivated + LostFocus或Activated + GotFocus。您可以使用Deactivated + LostFocus来捕获表单将被最小化/隐藏。 那是你在找什么?