CWinThread* AfxBeginThread(
AFX_THREADPROC pfnThreadProc,
LPVOID pParam,
int nPriority = THREAD_PRIORITY_NORMAL,
UINT nStackSize = 0,
DWORD dwCreateFlags = 0,
LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL
);
pfnThreadProc —— 是我们的线程处理函数,它的定义类似
|
标志 |
优先级值 |
|
1 |
idle (最低) |
THREAD_PRIORITY_IDLE |
如果进程优先级为realtime则调整为16,其它情况为1 |
2 |
LOWEST 低 |
THREAD_PRIORITY_LOWEST |
-2(在原有基础上-2) |
3 |
BELOW 低于标准 |
THREAD_PRIORITY_BELOW_NORMAL |
-1(在原有基础上-1) |
4 |
NORMAL(标准) |
THREAD_PRIORITY_NORMAL |
不变(取进程优先级值) |
5 |
ABOVE 高于标准 |
THREAD_PRIORITY_ABOVE_NORMAL |
+1(在原有基础上+1) |
6 |
HIGHEST (高) |
THREAD_PRIORITY_HIGHEST |
+2(在原有基础上+2) |
7 |
CRITICAL(最高) |
THREAD_PRIORITY_TIME_CRITICAL |
如果进程优先级为realtime则调整为31,其它情况为15 |
UINT __cdecl MyControllingFunction( LPVOID pParam )
{
int index=0;
CEdit* pedt=(CEdit*)pParam;
while(1)
{
CString str;
str.Format("%d",index++);
pedt->SetWindowText(str);
Sleep(1000);
}
return 0;
}
BOOL Cmfctest2Dlg::OnInitDialog()
{
…
AfxBeginThread(MyControllingFunction,&m_num);
return TRUE;
}
int CUIThread::ExitInstance()
{
m_udlg.DestroyWindow();
return CWinThread::ExitInstance();
}
Github位置:
https://github.com/HymanLiuTS/NetDevelopment
克隆本项目:
git [email protected]:HymanLiuTS/NetDevelopment.git
获取本文源代码:
git checkout NL45