Search This Blog

Thursday, December 18, 2008

MFC Code to Close Task manager Automatically if it is lanched

BOOL g_bStopDialogWatcherThread = FALSE; // To Stop & start Thread

UINT DialogWatcher(LPVOID lpParam)
{
g_bStopDialogWatcherThread = FALSE;
while(1)
{
Sleep(300);
HWND hWnd = ::FindWindow(NULL,"Windows Task Manager");//Windows Task Manager


if(hWnd !=NULL)
{
// ::SetForegroundWindow(hWnd);
// ::SetFocus(hWnd);
// ::SetWindowPos(hWnd,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE );
// ::SendMessage(hWnd,WM_COMMAND,(WPARAM)0x0000025C,(LPARAM)0x0000025C);

::SendMessage(hWnd,WM_CLOSE,0,0);

}

if(g_bStopDialogWatcherThread)
{
break;
}
}
return 1;
}




void CFindWindowDlg::OnbtnClick()
{
AfxBeginThread(DialogWatcher,THREAD_PRIORITY_NORMAL,0,0,0);

}

void CFindWindowDlg::OnCancel()
{
g_bStopDialogWatcherThread = TRUE;
CDialog::OnCancel();
}

No comments: