Create two windows in one application?
It might be a simple question, but I don't know where to start the search for the answer. How do I create two individual windows interface in one application using native winapi? Do I put two CreateWindow()
functions using same HINSTANCE
? What if I want a login screen windows and the content page such that login screen comes first, and after I press the button, the login screen is destroyed, and the content page appears. How do I do such trick?
I was thinking of using DestroyWindow
and then CreateWindow
inside the button cli开发者_开发知识库ck message. However, this would mean the main while
loop (for translate/dispatch msg) in WinMain
will exit its loop and cause the whole program to exit. Another way is to pre-create it in WinMain
, but how would I notify the WinMain
if the button was clicked and enter the second loop instead of exiting the program?
You're over-thinking it. To create two windows, call CreateWindow
twice. It's just that simple.
Calling DestroyWindow
does not cause your program to exit its message pump. Calling PostQuitMessage
is what does that. So don't do that.
When the button is clicked, destroy the one window and create the other. There are no tricks. The message pump delivers messages to all windows (unless you're doing it wrong by explicitly requesting messages for one window, but you shouldn't do that).
精彩评论