MFC关于解决点击关闭,对话框仍有后台程序运行问题 .

1.添加KillProcess(LPCSTR pszClassName, LPCSTR pszWindowTitle)函数;

int CTestDlg::KillProcess(LPCSTR pszClassName, LPCSTR pszWindowTitle)
{
    HANDLE hProcessHandle;  //
    ULONG nProcessID;
    HWND TheWindow;

    TheWindow = ::FindWindow( NULL, pszWindowTitle );
    ::GetWindowThreadProcessId( TheWindow, &nProcessID );
 hProcessHandle = ::OpenProcess(PROCESS_TERMINATE,FALSE,nProcessID );
    return ::TerminateProcess( hProcessHandle, 4 );
}

 

 

2.添加ON_CLOSE消息响应函数,加入KillProcess函数;

  void CTestDlg::OnClose()
{
 // TODO: Add your message handler code here and/or call default
  KillProcess(NULL,"软件的名称"); //结束进程,解决点击关闭

                                 //后台仍有进程运行!!
 CDialog::OnClose();
}

你可能感兴趣的:(mfc,opencv)