300分求根据窗口句柄做守护进程-解决方法(散分喽)
STARTUPINFO si;PROCESS_INFORMATION pi; ZeroMemory(&si, sizeof(si));si.cb = sizeof(si);ZeroMemory(&pi, sizeof(pi));si.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;si.wShowWindow = SW_HIDE;do{ if(!CreateProcess("my.exe", NULL , NULL,NULL,FALSE, NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW,NULL,NULL,&si,&pi)) { return 0; } WaitForSingleObject( pi.hProcess, INFINITE);}while(true);现在想,根据句柄,做守护,句柄已获得:CWnd *pWnd = FindWindow("my.exe", NULL);HWND hwnd = pwnd->GetSafeHwnd(); //得到它的HWNDvoidwait( HWND hwnd ){ DWORD processid; HANDLE process_handle; GetWindowThreadProcessId( hwnd, &processid ); process_handle = OpenProcess( PROCESS_ALL_ACCESS, FALSE, processid ); if( process_handle ) { ::WaitForSingleObject( process_handle, INFINITE ); AfxMessageBox( "wait is ok" ); } else { AfxMessageBox( "wait is error" ); }}void CHold_notepadDlg::OnButton1() { // TODO: Add your control notification handler code here HWND notepad; notepad = ::FindWindow( _T( "Notepad" ), NULL ); if( notepad ) { wait( notepad ); } else { AfxMessageBox( "not found notepad.exe" ); }}