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. Run MFC Program Without Dialog Showing

Run MFC Program Without Dialog Showing

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++
14 Posts 6 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.
  • A Andraw111

    Hi, dear all, I have a MFC program which do some calculation, store in a file, then plot the results to a graphic on dialog. Now I have another program which only want to use the calculation result stored in file from above MFC program but don't want to show the dialog, how can I do it? I modify the codes in InitInstance() as below: m_pMainWnd->ShowWindow(SW_HIDE); m_pMainWnd->UpdateWindow(); return FALSE; the dialog is not shown, but user still can see the dialog flush before hiding, how can I avoid it? Thanks!

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

    Take the calculation code and move it to a separate source file so you can add it to different projects.

    Veni, vidi, abiit domum

    A 1 Reply Last reply
    0
    • A Alan Balkany

      Hmm... Maybe you could try: ShowWindow(SW_MINIMIZE);

      A Offline
      A Offline
      Andraw111
      wrote on last edited by
      #6

      I try it, but you can see the process that the dialog is minimized, that's not what I expected. Thanks!

      A 1 Reply Last reply
      0
      • L Lost User

        Take the calculation code and move it to a separate source file so you can add it to different projects.

        Veni, vidi, abiit domum

        A Offline
        A Offline
        Andraw111
        wrote on last edited by
        #7

        Richard, Thanks for reply. the existing program is used by several projects, soome want the dialog, some not. so I just want to pass a argument to indicate show dialog or not.

        L 1 Reply Last reply
        0
        • A Andraw111

          Richard, Thanks for reply. the existing program is used by several projects, soome want the dialog, some not. so I just want to pass a argument to indicate show dialog or not.

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

          OK, so accept a parameter and if it's false do not show the dialog, something like:

          int APIENTRY WinMain(HINSTANCE hInstance, // instance value of the invoked application
          HINSTANCE hPrevInstance, // no longer used
          PSTR pszCmdLine, // pointer to the MS-DOS command line
          int nCmdShow // value indicating initial state of the window
          )
          {
          BOOL myParameter;
          // get the parameter from the command line and convert to BOOL

          if (myParameter == TRUE)
          {
              DialogBoxParam(hInstance,
                             MAKEINTRESOURCE(IDD\_DLG),
                             NULL,
                             (DLGPROC)DlgProc,
                             NULL
                             );
          }
          else
          {
              // call the function to calculate and write the file
          }
          
          return TRUE;
          

          }

          Where is the problem?

          Veni, vidi, abiit domum

          D 1 Reply Last reply
          0
          • A Andraw111

            I try it, but you can see the process that the dialog is minimized, that's not what I expected. Thanks!

            A Offline
            A Offline
            Alan Balkany
            wrote on last edited by
            #9

            Another idea: Use this: http://msdn.microsoft.com/en-us/library/kc4ez6dk%28v=vs.90%29.aspx[^] to lock the window while you bring up the dialog, with the window hidden. LockWindowUpdate may prevent the flash while the dialog is displayed then hidden.

            1 Reply Last reply
            0
            • L Lost User

              OK, so accept a parameter and if it's false do not show the dialog, something like:

              int APIENTRY WinMain(HINSTANCE hInstance, // instance value of the invoked application
              HINSTANCE hPrevInstance, // no longer used
              PSTR pszCmdLine, // pointer to the MS-DOS command line
              int nCmdShow // value indicating initial state of the window
              )
              {
              BOOL myParameter;
              // get the parameter from the command line and convert to BOOL

              if (myParameter == TRUE)
              {
                  DialogBoxParam(hInstance,
                                 MAKEINTRESOURCE(IDD\_DLG),
                                 NULL,
                                 (DLGPROC)DlgProc,
                                 NULL
                                 );
              }
              else
              {
                  // call the function to calculate and write the file
              }
              
              return TRUE;
              

              }

              Where is the problem?

              Veni, vidi, abiit domum

              D Offline
              D Offline
              digitalspace xjtu
              wrote on last edited by
              #10

              Following Richard's idea , if you program based on MFC Dialog , I think you can change InitialInstance() like this ...........

              BOOL myParameter;
              CMFCApplication4Dlg \*pMainWnd = new CMFCApplication4Dlg;
              
              if(myParameter)  // need a dialog
              {
                    pMainWnd->DoModal();
              }else {    // needn't a dialog
              pMainWnd->CreateEx(NULL,\_T("STATIC"), L"Hi", **WS\_BORDER** ,   //WS\_VISIBLE is not need
                        CRect(-15, -15, -15, -15), NULL,NULL); 
                   
                   // start a thread which include **while** loop, 
                   // that can keep dialog running until you stop it by yourself 
                   // otherwise the programe will exit very quickly
              }
              

              ........

              F 1 Reply Last reply
              0
              • D digitalspace xjtu

                Following Richard's idea , if you program based on MFC Dialog , I think you can change InitialInstance() like this ...........

                BOOL myParameter;
                CMFCApplication4Dlg \*pMainWnd = new CMFCApplication4Dlg;
                
                if(myParameter)  // need a dialog
                {
                      pMainWnd->DoModal();
                }else {    // needn't a dialog
                pMainWnd->CreateEx(NULL,\_T("STATIC"), L"Hi", **WS\_BORDER** ,   //WS\_VISIBLE is not need
                          CRect(-15, -15, -15, -15), NULL,NULL); 
                     
                     // start a thread which include **while** loop, 
                     // that can keep dialog running until you stop it by yourself 
                     // otherwise the programe will exit very quickly
                }
                

                ........

                F Offline
                F Offline
                Freak30
                wrote on last edited by
                #11

                I wouldn't create the main window at all if no Dialog/MainFrame is needed. Just call the class doing the processing from InitInstance(), if no window is requested. The program will end automatically when the processing is complete. In case of the windowed mode you can start the same processing from a button click or menu item click.

                The good thing about pessimism is, that you are always either right or pleasently surprised.

                1 Reply Last reply
                0
                • A Andraw111

                  Hi, dear all, I have a MFC program which do some calculation, store in a file, then plot the results to a graphic on dialog. Now I have another program which only want to use the calculation result stored in file from above MFC program but don't want to show the dialog, how can I do it? I modify the codes in InitInstance() as below: m_pMainWnd->ShowWindow(SW_HIDE); m_pMainWnd->UpdateWindow(); return FALSE; the dialog is not shown, but user still can see the dialog flush before hiding, how can I avoid it? Thanks!

                  A Offline
                  A Offline
                  Andraw111
                  wrote on last edited by
                  #12

                  Hi, dear all, I solve this issue, thanks for all of you for your help. inside InitInstance() function m_nCmdShow = SW_HIDE; CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); ......... ....... ....... m_pMainWnd->ShowWindow(m_nCmdShow); m_pMainWnd->UpdateWindow(); return FALSE;

                  D 1 Reply Last reply
                  0
                  • A Andraw111

                    Hi, dear all, I have a MFC program which do some calculation, store in a file, then plot the results to a graphic on dialog. Now I have another program which only want to use the calculation result stored in file from above MFC program but don't want to show the dialog, how can I do it? I modify the codes in InitInstance() as below: m_pMainWnd->ShowWindow(SW_HIDE); m_pMainWnd->UpdateWindow(); return FALSE; the dialog is not shown, but user still can see the dialog flush before hiding, how can I avoid it? Thanks!

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #13

                    Andraw111 wrote:

                    Now I have another program which only want to use the calculation result stored in file

                    Then why are you creating such overhead by making it an MFC app? Why not just create a console app with a hidden window? My guess would be 10-15 lines of code within main().

                    "One man's wage rise is another man's price increase." - Harold Wilson

                    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                    "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

                    1 Reply Last reply
                    0
                    • A Andraw111

                      Hi, dear all, I solve this issue, thanks for all of you for your help. inside InitInstance() function m_nCmdShow = SW_HIDE; CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); ......... ....... ....... m_pMainWnd->ShowWindow(m_nCmdShow); m_pMainWnd->UpdateWindow(); return FALSE;

                      D Offline
                      D Offline
                      digitalspace xjtu
                      wrote on last edited by
                      #14

                      It seems no different compared with your original version. why it works?

                      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