"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
Note that when the main window is created in InitInstance, it is not
required to be
responsive to messages. But a splash screen created in InitInstance *is*
required to be
responsive to messages, but the message pump is not yet working. When the
main window is
created, it doesn't have to start rersponding until the Run() invocation
starts the
message pump, and it is not expected to be responsive. But a splash
screen done as a
local variable in InitInstance means that the time-consuming startup is
*also* being done
from InitInstance, hence no message pump to cause any screen update of the
window before,
or while, this long computation runs.
In general, the main window is created in InitInstance, but for a splash
screen that
requires updating, this is not a good idea.
Sometimes, in InitInstance, I would simply PostMessage a message to the
newly-created
window to start doing the loading of the information. But more often, I
will let the
initial document or view do the loading (e.g., in the OnNewDocument, on
OpenDocument, or
OnInitialUpdate). I will simply have the doc or view PostMessage a
message to the
mainframe saying "Starting loading". If appropriate, the mainframe will
pop up the splash
screen. This means I'm always running a viable message pump. In my early
days of Windows
programming I made the same error as is made here, and the results were
rather ugly.
joe
On Tue, 11 Mar 2008 13:10:58 -0700, "Mark Salsbery [MVP]"
<MarkSalsbery[MVP]@newsgroup.nospam> wrote:
"Torsten Hensel" <Hensz@expires-31-03-2008.news-group.org> wrote in
message
news:1205250766.78@user.newsoffice.de...
Hi!
I created a simple dialog-based application. Then I created a modeless
dialog in MyApp::InitInstance - the dialog object is created on the
stack.
The stack object is going out of scope, forcing the destruction of the
window from the destructor.
As mentioned, you need to create it on the heap if you want it to stay in
existence beyond InitInstance().
I disagree with Joe - creating an app's main window is often done in
InitInstance().
Mark
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm