开发者

When initializing a main window win32, when is the best time to show a modal dialog?

开发者 https://www.devze.com 2023-01-04 05:09 出处:网络
I\'m t开发者_StackOverflowrying to accomplish this in Win32, but I\'m sure the same rules apply in the world of WinForms.

I'm t开发者_StackOverflowrying 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?


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:

:: GetSafeHwnd( m_hwnd)

And we can show modal dialog at that time.

0

精彩评论

暂无评论...
验证码 换一张
取 消