Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. NEWBIE: how to iniate dialog after application window is shown?

NEWBIE: how to iniate dialog after application window is shown?

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++tutorial
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MVH
    wrote on last edited by
    #1

    I'm using MSVC++6, and I have a normal Doc/view application. I have an item in the File menu, which iniates a dialog. How can I initiate the dialog automatically when the application is started, _after_ the application window is fully visible? I have placed a call to the function in more places than I want to think about, and I always get the dialog _before_ the application window is drawn. I'm just so tired of that, so tired... ;P

    D 1 Reply Last reply
    0
    • M MVH

      I'm using MSVC++6, and I have a normal Doc/view application. I have an item in the File menu, which iniates a dialog. How can I initiate the dialog automatically when the application is started, _after_ the application window is fully visible? I have placed a call to the function in more places than I want to think about, and I always get the dialog _before_ the application window is drawn. I'm just so tired of that, so tired... ;P

      D Offline
      D Offline
      Daniel Strigl
      wrote on last edited by
      #2

      Try to add the dialog call in the InitInstance() function of your application before you return the function.

      BOOL CTestApp::InitInstance()
      {
      ...
      m_pMainWnd->ShowWindow(SW_SHOW);
      m_pMainWnd->UpdateWindow();
      ...
      CMyDialog dlg;
      dlg.DoModal();

      return TRUE;
      }

      Daniel ;) --------------------------- Never change a running system!

      L 1 Reply Last reply
      0
      • D Daniel Strigl

        Try to add the dialog call in the InitInstance() function of your application before you return the function.

        BOOL CTestApp::InitInstance()
        {
        ...
        m_pMainWnd->ShowWindow(SW_SHOW);
        m_pMainWnd->UpdateWindow();
        ...
        CMyDialog dlg;
        dlg.DoModal();

        return TRUE;
        }

        Daniel ;) --------------------------- Never change a running system!

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        The function is in CView derived class. How could I get a pointer there so I won't have to rewrite the code in InitInstance? (Explanation: The OnFileSelectserver() function is in CView derived class, and it has calls to CDocument derived class. Now it would need to be called from CWinApp based class.)

        D J 2 Replies Last reply
        0
        • L Lost User

          The function is in CView derived class. How could I get a pointer there so I won't have to rewrite the code in InitInstance? (Explanation: The OnFileSelectserver() function is in CView derived class, and it has calls to CDocument derived class. Now it would need to be called from CWinApp based class.)

          D Offline
          D Offline
          Daniel Strigl
          wrote on last edited by
          #4

          What kind of pointer do you have in CView derived class? I thought you want do display a dialog after showing the application ... is that right? Daniel ;) --------------------------- Never change a running system!

          M 1 Reply Last reply
          0
          • L Lost User

            The function is in CView derived class. How could I get a pointer there so I won't have to rewrite the code in InitInstance? (Explanation: The OnFileSelectserver() function is in CView derived class, and it has calls to CDocument derived class. Now it would need to be called from CWinApp based class.)

            J Offline
            J Offline
            jhwurmbach
            wrote on last edited by
            #5

            If you want to fire you dialog right after the application starts, that is before a document has been opened, you will have to do it as was posted. But if you want your dialog to open after a document had been loaded and its view had been created, you could use your views OnInitialUpdate() message handler. A pointer to the active (SDI-)view can be obtained using CFrameWnd::GetActiveView(). (For MDI, there is a possibility shown in that MSDN entry). -- "My opinions may have changed, but not the fact that I am right." Found in the sig of Herbert Kaminski

            1 Reply Last reply
            0
            • D Daniel Strigl

              What kind of pointer do you have in CView derived class? I thought you want do display a dialog after showing the application ... is that right? Daniel ;) --------------------------- Never change a running system!

              M Offline
              M Offline
              MVH
              wrote on last edited by
              #6

              Yes, I want to show a dialog *after* showing the application window. All solutions I have tried will show the dialog before painting the application window. Err.. I am not sure what you mean with "what kind of pointer do you have in CView derived class". The only flaw in my application (that I know of ;) ) is that the dialog should be iniated automatically instead of having to iniate it from menu. The menu item is handled in CView derived class (CMyView), in OnFileSelectserver() function. That function has calls to CDocument derived class (CMyDocument). So I need to be able to call CMyView::OnFileSelectserver() from inside CWinApp based class (CMyApp), in InitInstance(). How to do that? Putting the CMyView::OnFileSelectserver() in CMyView::OnInitialUpdate() causes the dialog to be shown first, then a pause as the program gathers data and only after that the application is shown. Doing that skips the progress bar and gives the impression that nothing is happening. That's the problem. First application window, THEN dialog.

              D 1 Reply Last reply
              0
              • M MVH

                Yes, I want to show a dialog *after* showing the application window. All solutions I have tried will show the dialog before painting the application window. Err.. I am not sure what you mean with "what kind of pointer do you have in CView derived class". The only flaw in my application (that I know of ;) ) is that the dialog should be iniated automatically instead of having to iniate it from menu. The menu item is handled in CView derived class (CMyView), in OnFileSelectserver() function. That function has calls to CDocument derived class (CMyDocument). So I need to be able to call CMyView::OnFileSelectserver() from inside CWinApp based class (CMyApp), in InitInstance(). How to do that? Putting the CMyView::OnFileSelectserver() in CMyView::OnInitialUpdate() causes the dialog to be shown first, then a pause as the program gathers data and only after that the application is shown. Doing that skips the progress bar and gives the impression that nothing is happening. That's the problem. First application window, THEN dialog.

                D Offline
                D Offline
                Daniel Strigl
                wrote on last edited by
                #7

                Add the following code lines in your InitInstance function of your application:

                ...
                m_pMainWnd->ShowWindow(SW_SHOW);
                m_pMainWnd->UpdateWindow();
                **CYourView* pView = (CYourView*) ((CFrameWnd*) m_pMainWnd)->GetActiveView();

                pView->SendMessage(WM_COMMAND, ID_for_your_OnFileSelectserver_menu_item, 0);**
                return TRUE;

                Insert the right ID for the ID_for_your_OnFileSelectserver_menu_item in the SendMessage function. I hope this helps you! :-D Daniel ;) --------------------------- Never change a running system!

                M 2 Replies Last reply
                0
                • D Daniel Strigl

                  Add the following code lines in your InitInstance function of your application:

                  ...
                  m_pMainWnd->ShowWindow(SW_SHOW);
                  m_pMainWnd->UpdateWindow();
                  **CYourView* pView = (CYourView*) ((CFrameWnd*) m_pMainWnd)->GetActiveView();

                  pView->SendMessage(WM_COMMAND, ID_for_your_OnFileSelectserver_menu_item, 0);**
                  return TRUE;

                  Insert the right ID for the ID_for_your_OnFileSelectserver_menu_item in the SendMessage function. I hope this helps you! :-D Daniel ;) --------------------------- Never change a running system!

                  M Offline
                  M Offline
                  MVH
                  wrote on last edited by
                  #8

                  This looks like exactly what I need! Thanks!:) (I can't test it in action until Monday, but I am sure it will work.)

                  1 Reply Last reply
                  0
                  • D Daniel Strigl

                    Add the following code lines in your InitInstance function of your application:

                    ...
                    m_pMainWnd->ShowWindow(SW_SHOW);
                    m_pMainWnd->UpdateWindow();
                    **CYourView* pView = (CYourView*) ((CFrameWnd*) m_pMainWnd)->GetActiveView();

                    pView->SendMessage(WM_COMMAND, ID_for_your_OnFileSelectserver_menu_item, 0);**
                    return TRUE;

                    Insert the right ID for the ID_for_your_OnFileSelectserver_menu_item in the SendMessage function. I hope this helps you! :-D Daniel ;) --------------------------- Never change a running system!

                    M Offline
                    M Offline
                    MVH
                    wrote on last edited by
                    #9

                    ...aaand perfectly it did the job!

                    D 1 Reply Last reply
                    0
                    • M MVH

                      ...aaand perfectly it did the job!

                      D Offline
                      D Offline
                      Daniel Strigl
                      wrote on last edited by
                      #10

                      Fine! :) ;) Nice greets from Tyrol / Austria, Daniel. Daniel ;) --------------------------- Never change a running system!

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups