MFC多线程的简单实现

// CGetLocalListenPortList 消息处理程序
BOOL CXxx::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	//其它代码
	
	//HWND hWnd=GetSafeHwnd();//获得窗口句柄
	AfxBeginThread((AFX_THREADPROC)ThreadFunction,m_hWnd);	//启动线程

	return TRUE;
}


//线程函数,为静态成员函数
UINT CXxx::ThreadFunction(LPVOID pParam)
{
	int i = 0;
	while(1)
	{
		if (i >= 200)
		{
			i = 0;
		}
		else
		{
			i++;
		}
		
		//int型转CString型
		char buffer[100] = {0};
		sprintf(buffer,"%d",i);				
		TCHAR pid[100] = _T("");
		mbstowcs(pid,buffer,100);
		CString csTemp(pid);
	}
	return 0;
}

你可能感兴趣的:(MFC)