使用者介面執行緒和工作者執行緒都是由afxbeginthread建立的。mfc提供了兩個過載版的afxbeginthread,乙個用於使用者介面執行緒,另乙個用於工作者執行緒,分別有如下的原型:
使用者介面執行緒的afxbeginthread的原型如下:
cwinthread* afxapi afxbeginthread(
cruntimeclass* pthreadclass,
int npriority,
uint nstacksize,
dword dwcreateflags,
lpsecurity_attributes lpsecurityattrs);
工作者執行緒的afxbeginthread的原型如下:
cwinthread* afxbeginthread(afx_threadproc pfnthreadproc,
lpvoid lparam,
int npriority = thread_priority_normal,
uint nstacksize = 0,
dword dwcreateflags = 0,
lpsecurity_attributes lpsecurityattrs = null);
工作者執行緒實驗原始碼(為對話方塊新增乙個按鈕,增加按鈕單擊事件處理函式onbnclickedplay),在該函式前新增執行緒函式的宣告,在該函式後新增執行緒函式的實現。
執行部分結果:uint threadproca(lpvoid param);
uint threadprocb(lpvoid param);
void caadlg::onbnclickedplay()
uint threadproca(lpvoid param)
return 1;
}uint threadprocb(lpvoid param)
return 1;
}
atltracegeneral - threadprocb ouput: 983
atltracegeneral - threadproca ouput: 932
atltracegeneral - threadprocb ouput: 984
atltracegeneral - threadproca ouput: 933
atltracegeneral - threadprocb ouput: 985
atltracegeneral - threadproca ouput: 934
atltracegeneral - threadprocb ouput: 986
atltracegeneral - threadprocb ouput: 987
atltracegeneral - threadproca ouput: 935
atltracegeneral - threadprocb ouput: 988
atltracegeneral - threadproca ouput: 936
atltracegeneral - threadprocb ouput: 989
atltracegeneral - threadprocb ouput: 990
atltracegeneral - threadproca ouput: 937
atltracegeneral - threadprocb ouput: 991
atltracegeneral - threadproca ouput: 938
atltracegeneral - threadproca ouput: 939
atltracegeneral - threadprocb ouput: 992
atltracegeneral - threadproca ouput: 940
atltracegeneral - threadprocb ouput: 993
atltracegeneral - threadproca ouput: 941
atltracegeneral - threadprocb ouput: 994
atltracegeneral - threadprocb ouput: 995
atltracegeneral - threadproca ouput: 942
atltracegeneral - threadprocb ouput: 996
atltracegeneral - threadprocb ouput: 997
atltracegeneral - threadproca ouput: 943
atltracegeneral - threadprocb ouput: 998
atltracegeneral - threadproca ouput: 944
atltracegeneral - threadprocb ouput: 999
使用者介面執行緒參看博文:
AfxBeginThread 幹了什麼?
跟一跟afxbeginthread的原始碼就可以很容易的發現,它呼叫了 beginthreadex,注意這傢伙傳遞的可不是你傳進去的函式函式指標,它傳的是 afxthreadentry和乙個 afx thread startup的結構,那我們的函式指標和引數呢?哦,原來都被封裝到 afx threa...
AfxBeginThread函式初探
在進行多執行緒程式設計的時候,我們經常用到afxbeginthread函式來啟動一條執行緒 該函式使用起來非常的簡單方便,其定義如下 cwinthread afxbeginthread afx threadproc pfnthreadproc,執行緒函式位址 lpvoid pparam,執行緒引數 ...
函式AfxBeginThread裡面引數意義
cwinthread afxapi afxbeginthread afx threadproc pfnthreadproc,建立的新執行緒名字 也就是乙個執行緒的標示 lpvoid pparam,傳遞進上面執行緒的內容 比如乙個結構體 以下常使用系統預設的引數 int npriority threa...