Click here to Skip to main content
15,895,799 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to switch the views by CButton cointrol on CFormview view in MDI Pin
Vaclav_17-Sep-07 16:10
Vaclav_17-Sep-07 16:10 
QuestionRe: How to switch the views by CButton cointrol on CFormview view in MDI Pin
Nelek17-Sep-07 20:14
protectorNelek17-Sep-07 20:14 
QuestionRe: How to switch the views by CButton cointrol on CFormview view in MDI Pin
Nelek17-Sep-07 20:00
protectorNelek17-Sep-07 20:00 
AnswerRe: How to switch the views by CButton cointrol on CFormview view in MDI Pin
Vaclav_18-Sep-07 10:23
Vaclav_18-Sep-07 10:23 
GeneralAbout the assertion Pin
Nelek18-Sep-07 21:23
protectorNelek18-Sep-07 21:23 
QuestionWhere does the application's code go? Pin
daniel3343317-Sep-07 11:33
daniel3343317-Sep-07 11:33 
AnswerRe: Where does the application's code go? Pin
David Crow17-Sep-07 11:54
David Crow17-Sep-07 11:54 
AnswerRe: Where does the application's code go? Pin
Mark Salsbery17-Sep-07 12:23
Mark Salsbery17-Sep-07 12:23 
For info on starting another process, see  here[^]

Once you get the other process running, if you want to wait for it to finish,
you're getting out of newbie territory.

If you want the spawning app to remain responsive, it needs to process window
messages while waiting for the spawned app to complete.  There's lots of ways
to do this.

Here's an example of one method for you to study. 

This example

1) creates another process (I used Notepad as an example)

2) disables the main window of the calling app so the user can't do anything there
(note that this example was tested from the main window class.  You may need to
enable/disable your app's main window a little differently, depending on where this code
is used)

3) enters a modal loop to wait for the spawned process to terminate.  To keep
the calling app responsive in the meantime, queued window messages are dispatched.

4) enables the main window of the calling app so the user can continue

*Edit* Replace those stupid smilies with capital 'P's LOL

 nRet=dlg.DoModal();

   // Handle the return value from DoModal
   switch ( nRet )
   {
   case IDOK:
   {
    STARTUPINFO StartupInfo;
    memset(&StartupInfo, 0, sizeof(STARTUPINFO));
    StartupInfo.cb = sizeof(STARTUPINFO);  
//    StartupInfo.lpReserved = 0;  
//    StartupInfo.lpDesktop = 0;  
//    StartupInfo.lpTitle = 0;  
//    StartupInfo.dwX = 0;  
//    StartupInfo.dwY = 0;  
//    StartupInfo.dwXSize = 100;  
//    StartupInfo.dwYSize = 100;  
//    StartupInfo.dwXCountChars = 0;  
//    StartupInfo.dwYCountChars = 0;  
//    StartupInfo.dwFillAttribute = 0;  
    StartupInfo.dwFlags = STARTF_USESHOWWINDOW;  
    StartupInfo.wShowWindow = SW_SHOWDEFAULT;  
//    StartupInfo.cbReserved2;  
//    StartupInfo.lpReserved2;  
//    StartupInfo.hStdInput;  
//    StartupInfo.hStdOutput;  
//    StartupInfo.hStdError;

    PROCESS_INFORMATION ProcessInfo;

    if (::CreateProcess(_T("C:\\WINDOWS\\notepad.exe"),    //  LPCTSTR lpApplicationName,
                            NULL,                    //  LPTSTR lpCommandLine,
                            0,                        //  LPSECURITY_ATTRIBUTES lpProcessAttributes,
                            0,                        //  LPSECURITY_ATTRIBUTES lpThreadAttributes,
                            FALSE,                    //  BOOL bInheritHandles,
                            NORMAL_PRIORITY_CLASS,    //  DWORD dwCreationFlags,
                            0,                        //  LPVOID lpEnvironment,
                            0,                        //  LPCTSTR lpCurrentDirectory,
                            &StartupInfo,            //  LPSTARTUPINFO lpStartupInfo,
                            &;ProcessInfo            //  LPPROCESS_INFORMATION lpProcessInformation
                            ))
    {
        // Disable the main application window so user can't do anything
        EnableWindow(FALSE);

        // Wait for the spawned process to terminate
        while (true)
        {
            DWORD dwWaitRet = ::MsgWaitForMultipleObjects(1, &;ProcessInfo.hProcess, FALSE, INFINITE, QS_ALLEVENTS);

            if (WAIT_OBJECT_0 == dwWaitRet)
            {
                // Spawned app has terminated

                break;
            }
            else if (WAIT_OBJECT_0 + 1 == dwWaitRet)
            {
                // Queued window message(s) available

                // Dispatch all queued messages
                MSG msg;
                while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) 
                    AfxGetApp()->;PumpMessage(); 
            }
        }

        // Cleanup
        ::CloseHandle(ProcessInfo.hProcess);  
        ::CloseHandle(ProcessInfo.hThread);  

        // Re-enable the main application window
        EnableWindow(TRUE);
    }
   }
}
I hope this gives you some ideas to work with.  There's many ways to do this.
This example is relatively simple and doesn't involve multiple threads.

Mark





Mark Salsbery
Microsoft MVP - Visual C++

Java | [Coffee]

QuestionCreating "light" backups of Visual Studio projects... Pin
@largeinsd17-Sep-07 11:14
@largeinsd17-Sep-07 11:14 
AnswerRe: Creating "light" backups of Visual Studio projects... Pin
bob1697217-Sep-07 18:00
bob1697217-Sep-07 18:00 
GeneralRe: Creating "light" backups of Visual Studio projects... Pin
@largeinsd18-Sep-07 7:01
@largeinsd18-Sep-07 7:01 
QuestionUDP Application on Vista: Fail on sendto function Pin
Cris17-Sep-07 10:20
Cris17-Sep-07 10:20 
AnswerRe: UDP Application on Vista: Fail on sendto function Pin
Mark Salsbery17-Sep-07 11:32
Mark Salsbery17-Sep-07 11:32 
AnswerRe: UDP Application on Vista: Fail on sendto function Pin
David Crow17-Sep-07 11:56
David Crow17-Sep-07 11:56 
GeneralRe: UDP Application on Vista: Fail on sendto function Pin
Cris18-Sep-07 3:53
Cris18-Sep-07 3:53 
QuestionRe: UDP Application on Vista: Fail on sendto function Pin
David Crow18-Sep-07 3:58
David Crow18-Sep-07 3:58 
AnswerRe: UDP Application on Vista: Fail on sendto function Pin
Cris18-Sep-07 4:44
Cris18-Sep-07 4:44 
GeneralRe: UDP Application on Vista: Fail on sendto function Pin
Cris20-Sep-07 3:28
Cris20-Sep-07 3:28 
QuestionHTML help integration Pin
Nathan Holt at EMOM17-Sep-07 9:41
Nathan Holt at EMOM17-Sep-07 9:41 
QuestionFailed new operator Pin
Joe Smith IX17-Sep-07 9:03
Joe Smith IX17-Sep-07 9:03 
AnswerRe: Failed new operator Pin
Mark Salsbery17-Sep-07 9:21
Mark Salsbery17-Sep-07 9:21 
GeneralRe: Failed new operator Pin
Joe Smith IX17-Sep-07 9:25
Joe Smith IX17-Sep-07 9:25 
GeneralRe: Failed new operator Pin
Mark Salsbery17-Sep-07 9:32
Mark Salsbery17-Sep-07 9:32 
GeneralRe: Failed new operator Pin
Joe Smith IX17-Sep-07 9:42
Joe Smith IX17-Sep-07 9:42 
AnswerRe: Failed new operator Pin
Nathan Holt at EMOM17-Sep-07 9:35
Nathan Holt at EMOM17-Sep-07 9:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.