Prev: CMFCMenuBar as a context menu ?
Next: MFC under VS2010
From: Guido Franzke on 26 Mar 2010 10:06 Hello NG, when I start my MDI App, 2 DocTemplates are opened with OpenDocumentFile(NULL). Each window has special and time costing function calls in OnInitialUpdate. Now I want the first window to be ready initialized and shown, and after that open the second window. Sleep not work between both OpenDocumentFile. So I tried the following: FileNewWindow1(); if (pMainFrame->MDIGetActive()) (pMainFrame->MDIGetActive())->MDIMaximize(); pMainFrame->UpdateWindow(); int ikum=0; while (::g_pWindow1==NULL && ikum<15) { Sleep(500); ikum++; } if (g_pWindow1) { ikum=0; while (g_pWindow1->m_bInOnInitialUpdate && ikum<15) { Sleep(500); ikum++; } } } pMainFrame->UpdateWindow(); FileNewWindow2(); But this does not help me. The window1 is not shown totally, but the window2 already opens. How can I manage to open the first window, let it show totally, wait e.g. 5 seconds, and then open the second window? Thanks for help, Guido
From: Tom Serface on 26 Mar 2010 12:21 I don't think the framework will allow you to do that, but you could open the second window as hidden (SW_HIDE) and then send a message to it from the first when it is done doing whatever initialization it needs to do. Then the second window can show itself and update controls or whatever. Tom "Guido Franzke" <guidof73(a)yahoo.de> wrote in message news:#QNR32OzKHA.2644(a)TK2MSFTNGP04.phx.gbl... > Hello NG, > > when I start my MDI App, 2 DocTemplates are opened with > OpenDocumentFile(NULL). > Each window has special and time costing function calls in > OnInitialUpdate. > Now I want the first window to be ready initialized and shown, and after > that open the second window. Sleep not work between both OpenDocumentFile. > So I tried the following: > > FileNewWindow1(); > if (pMainFrame->MDIGetActive()) > (pMainFrame->MDIGetActive())->MDIMaximize(); > pMainFrame->UpdateWindow(); > > int ikum=0; > while (::g_pWindow1==NULL && ikum<15) > { > Sleep(500); > ikum++; > } > if (g_pWindow1) > { > ikum=0; > while (g_pWindow1->m_bInOnInitialUpdate && ikum<15) > { > Sleep(500); > ikum++; > } > } > } > pMainFrame->UpdateWindow(); > FileNewWindow2(); > > But this does not help me. The window1 is not shown totally, but the > window2 > already opens. > > How can I manage to open the first window, let it show totally, wait e.g. > 5 > seconds, and then open the second window? > > Thanks for help, > Guido > >
From: Joseph M. Newcomer on 26 Mar 2010 13:44 Generally, the framework does not provide guarantees about initialization sequences. I'm not even sure what you mean when you say "start 2 doc templates". Generally you will use them to create views which you attach to a single document. On Fri, 26 Mar 2010 15:06:10 +0100, "Guido Franzke" <guidof73(a)yahoo.de> wrote: >Hello NG, > >when I start my MDI App, 2 DocTemplates are opened with >OpenDocumentFile(NULL). >Each window has special and time costing function calls in OnInitialUpdate. >Now I want the first window to be ready initialized and shown, and after >that open the second window. Sleep not work between both OpenDocumentFile. >So I tried the following: > > FileNewWindow1(); > if (pMainFrame->MDIGetActive()) > (pMainFrame->MDIGetActive())->MDIMaximize(); > pMainFrame->UpdateWindow(); > > int ikum=0; > while (::g_pWindow1==NULL && ikum<15) **** The use of a global variable scares me. It doesn't make sense to use one. **** > { > Sleep(500); **** This makes no sense; all that happens is that the thread sleeps for 500ms, during which it does NOTHING. This means that it cannot "concurrently" (while sleeping) initialize any other window, because you've stopped the thread. A Sleep() in the main GUI thread is ALWAYS a mistake! *** > ikum++; > } > if (g_pWindow1) > { > ikum=0; > while (g_pWindow1->m_bInOnInitialUpdate && ikum<15) > { > Sleep(500); **** A fundamental error repeated inside a loop! **** > ikum++; > } > } > } > pMainFrame->UpdateWindow(); > FileNewWindow2(); > >But this does not help me. The window1 is not shown totally, but the window2 >already opens. **** You are confused about what is going on here. First, you have not actually said what you are trying to accomplish; are you trying to get two views on one document, or two document-view pairs up? And the UpdateWindow() is for the main frame; if you want to see the view displayed, you should attempt an UpdateWIndow in the OnInitialUpdate to see if this changes the picture. Sleep() will NEVER change ANYTHING; all it does is stop the thread for 500ms, during which it cannot do ANYTHING, including updating the other window. **** > >How can I manage to open the first window, let it show totally, wait e.g. 5 >seconds, and then open the second window? **** In the OnInitialUpdate of the first window, do a SetTimer(IDT_LAUNCH_OTHER_WINDOW, 5000, NULL). where IDT_LAUNCH_OTHER_WINDOW is some constant not used for any other timer in this window class, e.g., if it is the only timer, "1" is a good value #define IDT_LAUNCH_OTHER_WINDOW 1 In the OnTimer handler, when you get this notification, you can PostMessage to the main fram to launch the other window, using a user-defined message. joe **** > >Thanks for help, >Guido > Joseph M. Newcomer [MVP] email: newcomer(a)flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm
|
Pages: 1 Prev: CMFCMenuBar as a context menu ? Next: MFC under VS2010 |