我只是举个例子
class CMyAppDlg : public CDialog {
...
void CallThreadFunc(int a, int b);
static UINT ThreadFuncWrapper(LPVOID* p);
struct ThreadParam {
CMyAppDlg* pThisl;
int a;
int b;
}; //根据线程函数的参数而定
void ThreadFunc(int a, int b); //线程函数,自己写
...
};
void CMyAppDlg::CallThreadFunc(int a, int b) {
ThreadParam* tp;
*(LPVOID*)&tp = malloc(sizeof(ThreadParam));
tp.pThis = this;
tp.a = a;
tp.b = b;
CWinThread *t = AfxBeginThread(&CMyAppDlg::ThreadFuncWrapper, tp, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
t->m_bAutoDelete = TRUE;
t->ResumeThread();
}
UINT CMyAppDlg::ThreadFuncWrapper(LPVOID* p) {
ThreadParam param = *(ThreadParam*)p;
free(p);
param.pThis->ThreadFunc(param.a, param.b);
return 0;
}
调用的地方:
CallThreadFunc(1, 2);
像这样。
代码大概是这个意思,没测试编译。如果哪里有报错自己改一下应该可以……?
http://jingyan.baidu.com/article/c35dbcb025e4088916fcbc11.html