HANDLE hThread=NULL;

DWORD WINAPI ThreadFunc(LPVOID lpParam)
{
	HWND hwnd=(HWND)lpParam;
	//MessageBox(hwnd,"1","1",MB_OK);
	SetDlgItemText(hwnd,IDC_STATUS,"正在登陆");
	Sleep(5000);
	//MessageBox(hwnd,"2","2",MB_OK);
	SetDlgItemText(hwnd,IDC_STATUS,"登陆成功");

	CloseHandle(hThread);hThread=NULL;
	return 0;

}

void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
	//static HANDLE hThread=NULL;

    switch(id)
    {
        case IDC_OK:
		{
			hThread=CreateThread(NULL,0,ThreadFunc,(LPVOID)hwnd,0,0);

			//MessageBox(hwnd,TEXT("欢迎访问如鹏网 www.RuPeng.com 大学生计算机学习社区"),TEXT("问好"),MB_OK);
		}
        break;
		case IDC_CANCEL:
		{
			if (hThread!=NULL)
			{
/*
2.可以在线程的外部调用
BOOL TerminateThread( HANDLE hThread, DWORD dwExitCode )
来强行终止一个线程的运行,
然后调用CloseHandle()函数释放线程所占用的堆栈
*/				TerminateThread( hThread, 1);
				CloseHandle(hThread);
				hThread=NULL;
				SetDlgItemText(hwnd,IDC_STATUS,"登陆取消");
			}
		}
		break;
        default:
		break;
    }
}