Click here to Skip to main content
15,913,854 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionKill a thread Pin
deeps_cute7-May-07 3:16
deeps_cute7-May-07 3:16 
AnswerRe: Kill a thread Pin
James R. Twine7-May-07 3:19
James R. Twine7-May-07 3:19 
GeneralRe: Kill a thread Pin
Arman S.7-May-07 3:31
Arman S.7-May-07 3:31 
GeneralRe: Kill a thread Pin
James R. Twine7-May-07 3:34
James R. Twine7-May-07 3:34 
GeneralRe: Kill a thread Pin
Arman S.7-May-07 3:39
Arman S.7-May-07 3:39 
GeneralRe: Kill a thread Pin
James R. Twine7-May-07 4:19
James R. Twine7-May-07 4:19 
GeneralRe: Kill a thread Pin
David Crow7-May-07 3:39
David Crow7-May-07 3:39 
AnswerRe: Kill a thread Pin
Sam_c7-May-07 5:44
Sam_c7-May-07 5:44 
the other post cover important details, like you should close a thread by the means its ment to be closed to avoid memory leaks and other nasty stuff.

but if you really want to do it...
i used these function is a app that had to close other applications regardless of memory leaks.
here it is.. should still work i hope.
<br />
DWORD	lpProcessID, lpThreadID, lpExitCodeThread, lpExitCodeProcess;<br />
HWND	WndHandle;<br />
<br />
#ifdef _DEBUG_MSGBOXS_<br />
	AfxMessageBox(_T("Checking for Class"),MB_OK);<br />
#endif<br />
	<br />
	if(NameIsOfClass == TRUE)<br />
	{<br />
	WndHandle = ::FindWindow(AppName,NULL);		//Check for the class instance, pass handle back if successful, zero if not<br />
	}<br />
	else<br />
	{<br />
	WndHandle = ::FindWindow(NULL,AppName);<br />
	}<br />
	if(WndHandle != NULL)<br />
	{<br />
		#ifdef _DEBUG_MSGBOXS_<br />
				AfxMessageBox(_T("Class found"),MB_OK);<br />
		#endif<br />
<br />
		lpThreadID=GetWindowThreadProcessId(WndHandle,&lpProcessID);			//Get the ID's for the thread and process<br />
		HANDLE ThreadHandle = OpenThread(THREAD_ALL_ACCESS,TRUE,lpThreadID);			//Open thread to gain control<br />
		HANDLE ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS,TRUE,lpProcessID);		//open process to gain control<br />
		<br />
		if(GetExitCodeProcess(ProcessHandle,&lpExitCodeProcess) == 0 )					//get the exit code<br />
		{<br />
	 		AfxMessageBox(_T("GetExitCodeProcess function Failed with Error:"), MB_OK);<br />
			return FALSE;<br />
		}<br />
<br />
		if(GetExitCodeThread(ThreadHandle,&lpExitCodeThread) == 0)<br />
		{<br />
			AfxMessageBox(_T("GetExitCodeThread function Failed with Error:"), MB_OK);<br />
			return FALSE;<br />
		}<br />
		<br />
		TerminateThread(ThreadHandle,lpExitCodeThread);									//Kill the thread<br />
		TerminateProcess(ProcessHandle,lpExitCodeProcess);								//Kill the process<br />
	}<br />
	else<br />
	{<br />
		#ifdef _DEBUG_MSGBOXS_<br />
		AfxMessageBox(_T("Failed: Class may not be running"),MB_OK);<br />
		#endif<br />
	}<br />


that has the key functions in and works.
or atleast it did when i made it a few years back.
hope that helps

p.s i'd dont use this for threads i created, if you created the thread you need to kill it safely in the onclose event or ondestroy etc
QuestionStatic button with bitmap Pin
prathuraj7-May-07 2:39
prathuraj7-May-07 2:39 
AnswerRe: Static button with bitmap Pin
David Crow7-May-07 3:22
David Crow7-May-07 3:22 
AnswerRe: Static button with bitmap Pin
Hans Dietrich7-May-07 3:23
mentorHans Dietrich7-May-07 3:23 
QuestionC2065 Error Pin
subramanyeswari7-May-07 2:16
subramanyeswari7-May-07 2:16 
AnswerRe: C2065 Error Pin
toxcct7-May-07 2:20
toxcct7-May-07 2:20 
GeneralRe: C2065 Error Pin
subramanyeswari7-May-07 22:14
subramanyeswari7-May-07 22:14 
GeneralRe: C2065 Error Pin
toxcct8-May-07 0:23
toxcct8-May-07 0:23 
GeneralRe: C2065 Error Pin
subramanyeswari8-May-07 3:53
subramanyeswari8-May-07 3:53 
GeneralRe: C2065 Error Pin
toxcct8-May-07 3:57
toxcct8-May-07 3:57 
GeneralRe: C2065 Error Pin
subramanyeswari8-May-07 19:08
subramanyeswari8-May-07 19:08 
GeneralRe: C2065 Error Pin
toxcct8-May-07 21:51
toxcct8-May-07 21:51 
GeneralRe: C2065 Error Pin
subramanyeswari9-May-07 2:32
subramanyeswari9-May-07 2:32 
GeneralRe: C2065 Error Pin
subramanyeswari9-May-07 2:34
subramanyeswari9-May-07 2:34 
GeneralRe: C2065 Error Pin
toxcct9-May-07 2:39
toxcct9-May-07 2:39 
Questionhow to return const char* in C Pin
sandeepkavade7-May-07 1:56
sandeepkavade7-May-07 1:56 
AnswerRe: how to return const char* in C Pin
toxcct7-May-07 2:00
toxcct7-May-07 2:00 
AnswerRe: how to return const char* in C Pin
Hans Dietrich7-May-07 3:19
mentorHans Dietrich7-May-07 3:19 

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.