初始化主窗口 win32 时,什么时候是显示模式对话框的最佳时间?
我试图在 Win32 中实现这一点,但我确信同样的规则也适用于 WinForms 的世界。
问:我创建了主窗口,然后,当它显示时,我想显示一个模式对话框。问题是;我如何知道主窗口何时完全初始化并可见?也就是说,到底什么时候是显示对话框的最佳时间?
想法:
1) 处理WM_CREATE
并作为最后一步PostMessage(WM_USER_MESSAGE)
。处理 WM_USER_MESSAGE
并显示模式对话框!
2) 处理WM_CREATE
并将计时器设置为~300 ms。处理WM_TIMER
,终止计时器并显示模式对话框!
3) 如果第一次激活PostMessage(WM_USER_MESSAGE)
,则处理WM_ACTIVATE
。处理 WM_USER_MESSAGE
并显示模式对话框!
4) 处理WM_SHOWWINDOW
,如果是第一次显示则显示模态对话框!
上述方法虽然有效,但结果并不总是那么好。有更好的方法吗?也许以某种方式处理 WM_ENTERIDLE
或 WM_KICKIDLE
消息?
I'm trying to accomplish this in Win32, but I'm sure the same rules apply in the world of WinForms.
Q: I create my main window, and then, when it is being shown, I want to show a modal dialog. The problem is; how can I know when the main window is completely initialized and visible? That is, exactly when is the best time to show the dialog?
Ideas:
1) Handle WM_CREATE
and as a final step PostMessage(WM_USER_MESSAGE)
. Handle WM_USER_MESSAGE
and show modal dialog!
2) Handle WM_CREATE
and set a timer at ~300 ms. Handle WM_TIMER
, kill timer and show modal dialog!
3) Handle WM_ACTIVATE
, if first activation PostMessage(WM_USER_MESSAGE)
. Handle WM_USER_MESSAGE
and show modal dialog!
4) Handle WM_SHOWWINDOW
, if first-time show show modal dialog!
The above approaches work, but the result is not always that good. Is there a better method? Perhaps handling WM_ENTERIDLE
or WM_KICKIDLE
messages in some way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的。显示对话框的最佳时间是:
您可以处理 WM_CREATE 并使用函数检查窗口句柄是否有效:
此时我们可以显示模式对话框。
Yes. exactly the best time to show the dialog is:
You can handle WM_CREATE and check for window handle is valid by using function:
And we can show modal dialog at that time.