如何能够通过对话框的命令按钮开启一个进程(命令行程序),同时对话框上的另一个按钮可以终止该进程。如果进程运行直至结束,对话框可以及时知道。
使用WaitForSingleObject好像无法实现,开启了进程以后无法返回,即无法使对话框及其上的按钮有效。

解决方案 »

  1.   

    MsgWaitForMultipleObjects/MsgWaitForMultipleObjectsEx
      

  2.   

    The following code fragment illustrates the use of the MsgWaitForMultipleObjects function in a message loop.
    int MessageLoop ( 
        HANDLE* lphObjects,  // handles that need to be waited on 
        int     cObjects     // number of handles to wait on 
      )

        // The message loop lasts until we get a WM_QUIT message,
        // upon which we shall return from the function.
        while (TRUE)
        {
            // block-local variable 
            DWORD result ; 
            MSG msg ;         // Read all of the messages in this next loop, 
            // removing each message as we read it.
            while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) 
            { 
                // If it is a quit message, exit.
                if (msg.message == WM_QUIT)  
                    return 1; 
                // Otherwise, dispatch the message.
                DispatchMessage(&msg); 
            } // End of PeekMessage while loop.        // Wait for any message sent or posted to this queue 
            // or for one of the passed handles be set to signaled.
            result = MsgWaitForMultipleObjects(cObjects, lphObjects, 
                     FALSE, INFINITE, QS_ALLINPUT);         // The result tells us the type of event we have.
            if (result == (WAIT_OBJECT_0 + cObjects))
            {
                // New messages have arrived. 
                // Continue to the top of the always while loop to 
                // dispatch them and resume waiting.
                continue;
            } 
            else 
            { 
                // One of the handles became signaled. 
                DoStuff (result - WAIT_OBJECT_0) ; 
            } // End of else clause.
        } // End of the always while loop. 
    } // End of function.
      

  3.   

    谢谢DentistryDoctor(MVP称号也不能顶上缺失的文凭(厚积薄发)) ,对于我的要求,对话框的启动钮启动进程,取消钮可以中途终止进程运行。应该何时由谁调用DialogBox,CreateProcess和MessageLoop呢?