当前位置:网站首页>MFC 线程AfxBeginThread基本用法,传多个参数
MFC 线程AfxBeginThread基本用法,传多个参数
2022-07-25 14:59:00 【sam-zy】
UI线程:
CWinThread* AFXAPI AfxBeginThread(
CRuntimeClass* pThreadClass, //从CWinThread派生的RUNTIME_CLASS类
int nPriority, //指定线程优先级,如果为0,则与创建该线程的线程相同
UINT nStackSize, //指定线程的堆栈大小,如果为0,则与创建该线程的线程相同
DWORD dwCreateFlags,//创建标识 如果是CREATE_SUSPENDED 则在悬挂状态创建线程,在线程创建后线程挂起,否则线程在创建后开始线程的执行
LPSECURITY_ATTRIBUTES lpSecurityAttrs)//线程的安全属性,NT下有用。
工作者线程:
CWinThread* AfxBeginThread(AFX_THREADPROC pfnThreadProc,//入口函数,声明:UINT MyThreadFunction(LPVOID pParam)
LPVOID lParam, //传递入线程的参数,它的类型为:LPVOID,所以可以传递一个结构体入线程
int nPriority = THREAD_PRIORITY_NORMAL, //线程的优先级,一般设置为 0 .让它和主线程具有共同的优先级.
UINT nStackSize = 0, //指定新创建的线程的栈的大小.如果为 0,新创建的线程具有和主线程一样的大小的栈
DWORD dwCreateFlags = 0, //CREATE_SUSPENDED:线程创建以后,会处于挂起状态,直到调用:ResumeThread
//0:创建线程后就开始运行.
LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL //如果为 NULL,那么新创建的线程就具有和主线程一样的安全性.
); //返回值: 成功时返回一个指向新线程的线程对象的指针,否则NULL。
线程优先级:https://blog.csdn.net/zhengyanan815/article/details/53786639
工作者线程使用:
1.传入单个参数
1.线程处理函数
void* Camera::CodeSaveThread(void* pParam)
{
CString Codes = *(CString*)pParam; //无类型指针变为整形数指针
//...
//...
AfxEndThread(0);
return 0;
}
2.启动一个线程:
CString Code = _T("test");
AfxBeginThread((AFX_THREADPROC)CodeSaveThread, (void*)&Code, THREAD_PRIORITY_IDLE); //存日志
2.传多个参数(结构体)
1.线程处理函数
struct LogStruct //存日志结构体
{
CString LogName;
CString DataStr;
};
void* Camera::CodeSaveThread(void* pParam)
{
LogStruct LogStru = *(LogStruct*)pParam; //无类型指针变为整形数指针
CString LogName = LogStru.LogName ;
CString Codes = LogStru.DataStr;
//...
//...
AfxEndThread(0);
return 0;
}
2.启动一个线程:
CString Code = _T("test");
LogStruct LogStru;
LogStru.LogName = _T("Log");
LogStru.DataStr = Code;
AfxBeginThread((AFX_THREADPROC)CodeSaveThread, (void*)&LogStru, 0); //存日志
边栏推荐
- Copy files / folders through Robocopy
- 关于RDBMS和非RDBMS【数据库系统】
- String type time comparison method with error string.compareto
- Splice a field of the list set into a single string
- awk从入门到入土(20)awk解析命令行参数
- Examples of bio, NiO, AIO
- MySQL的登陆【数据库系统】
- 32 chrome调试工具的使用
- Awk from getting started to digging in (21) awk script debugging
- Nacos2.1.0 cluster construction
猜你喜欢

The solution to the problem that the progress bar of ros2 installation connext RMW is stuck at 13%

Wechat official account official environment online deployment, third-party public platform access

37 元素模式(行内元素,块元素,行内块元素)

SQL优化的一些建议,希望可以帮到和我一样被SQL折磨的你

【JS高级】js之正则相关函数以及正则对象_02

Vs2010添加wap移动窗体模板

【MySQL必知必会】触发器 | 权限管理

D2. picking carrots (hard version) (one question per day)

Leetcode combination sum + pruning

Deployment and simple use of PostgreSQL learning
随机推荐
Awk from entry to earth (24) extract the IP of the instruction network card
Leetcode combination sum + pruning
微信公众号正式环境上线部署,第三方公众平台接入
[C topic] Li Kou 206. reverse the linked list
32 chrome调试工具的使用
IP address classification, which determines whether a network segment is a subnet supernetwork
Raft of distributed consistency protocol
Jmeter的随机数函数怎么用
Leetcode-198- house raiding
27 选择器的分类
Implement a simple restful API server
27 classification of selectors
Heyuan City launched fire safety themed milk tea to boost fire prevention and control in summer
I hope some suggestions on SQL optimization can help you who are tortured by SQL like me
Copy files / folders through Robocopy
SQL优化的一些建议,希望可以帮到和我一样被SQL折磨的你
Browser based split screen reading
"How to use" agent mode
Client error: invalid param endpoint is blank
Deployment and simple use of PostgreSQL learning