当前位置:网站首页>Basic usage of MFC thread afxbeginthread, passing multiple parameters
Basic usage of MFC thread afxbeginthread, passing multiple parameters
2022-07-25 15:54:00 【sam-zy】
UI Threads :
CWinThread* AFXAPI AfxBeginThread(
CRuntimeClass* pThreadClass, // from CWinThread Derived RUNTIME_CLASS class
int nPriority, // Specify thread priority , If 0, Is the same as the thread that created the thread
UINT nStackSize, // Specifies the stack size of the thread , If 0, Is the same as the thread that created the thread
DWORD dwCreateFlags,// Create logo If it is CREATE_SUSPENDED The thread is created in the suspended state , Thread suspended after thread creation , Otherwise, the thread starts executing after it is created
LPSECURITY_ATTRIBUTES lpSecurityAttrs)// Thread security properties ,NT Next useful .
Worker threads :
CWinThread* AfxBeginThread(AFX_THREADPROC pfnThreadProc,// Entry function , Statement :UINT MyThreadFunction(LPVOID pParam)
LPVOID lParam, // Parameters passed into the thread , Its type is :LPVOID, So you can pass a structure into the thread
int nPriority = THREAD_PRIORITY_NORMAL, // Thread priority , Generally set as 0 . Let it have the same priority as the main thread .
UINT nStackSize = 0, // Specify the stack size of the newly created thread . If 0, The newly created thread has a stack the same size as the main thread
DWORD dwCreateFlags = 0, //CREATE_SUSPENDED: After the thread is created , Will be suspended , Until the call :ResumeThread
//0: Start running after creating the thread .
LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL // If NULL, Then the newly created thread has the same security as the main thread .
); // Return value : When successful, it returns a pointer to the thread object of the new thread , otherwise NULL.
Thread priority :https://blog.csdn.net/zhengyanan815/article/details/53786639
Worker threads use :
1. Passing in a single parameter
1. Thread handler
void* Camera::CodeSaveThread(void* pParam)
{
CString Codes = *(CString*)pParam; // The typeless pointer becomes an integer pointer
//...
//...
AfxEndThread(0);
return 0;
}
2. Start a thread :
CString Code = _T("test");
AfxBeginThread((AFX_THREADPROC)CodeSaveThread, (void*)&Code, THREAD_PRIORITY_IDLE); // Keep a log
2. Pass multiple parameters ( Structure )
1. Thread handler
struct LogStruct // Save log structure
{
CString LogName;
CString DataStr;
};
void* Camera::CodeSaveThread(void* pParam)
{
LogStruct LogStru = *(LogStruct*)pParam; // The typeless pointer becomes an integer pointer
CString LogName = LogStru.LogName ;
CString Codes = LogStru.DataStr;
//...
//...
AfxEndThread(0);
return 0;
}
2. Start a thread :
CString Code = _T("test");
LogStruct LogStru;
LogStru.LogName = _T("Log");
LogStru.DataStr = Code;
AfxBeginThread((AFX_THREADPROC)CodeSaveThread, (void*)&LogStru, 0); // Keep a log
边栏推荐
- Games101 review: 3D transformation
- 2021 Jiangsu race a Array line segment tree, maintain value range, Euler power reduction
- 30 lines write the concurrency tool class yourself (semaphore, cyclicbarrier, countdownlatch)
- MySQL optimization summary II
- How Google cloud disk is associated with Google colab
- Leetcode - 303 area and retrieval - array immutable (design prefix and array)
- Zhaoqi Kechuang high-quality overseas returnee talent entrepreneurship and innovation service platform, online live broadcast Roadshow
- 我想问下变量配置功能是只能在SQL模式下使用吗
- MySQL教程66-数据表查询语句
- Get the ask code corresponding to the key pressed by the keyboard
猜你喜欢

LeetCode - 380 O(1) 时间插入、删除和获取随机元素 (设计 哈希表+数组)

Alibaba's internal "100 billion level concurrent system architecture design notes" are all inclusive, too comprehensive

"Digital security" alert NFT's seven Scams

Google Blog: training general agents with multi game decision transformer

Brain racking CPU context switching

Games101 review: 3D transformation

不愧是阿里内部“千亿级并发系统架构设计笔记”面面俱到,太全了

Pytorch学习笔记--SEResNet50搭建

Idea - click the file code to automatically synchronize with the directory

How matlab saves all the data after running
随机推荐
Cf365-e - Mishka and divisors, number theory +dp
Pytoch learning notes -- seresnet50 construction
Geogle colab notes 1-- run the.Py file on the cloud hard disk of Geogle
Leetcode - 359 log rate limiter (Design)
Box avoiding mouse
30 lines write the concurrency tool class yourself (semaphore, cyclicbarrier, countdownlatch)
Alibaba's internal "100 billion level concurrent system architecture design notes" are all inclusive, too comprehensive
谷歌博客:采用多重游戏决策Transformer训练通用智能体
Pytorch学习笔记-Advanced_CNN(Using Inception_Module)实现Mnist数据集分类-(注释及结果)
Matlab simulation of BPSK modulation system (1)
Pat grade a 1152 Google recruitment (20 points)
Pytoch learning notes -- Summary of common functions 2
Use cpolar to build a business website (how to buy a domain name)
Zhaoqi Kechuang high-quality overseas returnee talent entrepreneurship and innovation service platform, online live broadcast Roadshow
Cf685b find the center of gravity of each subtree of a rooted tree
通用测试用例写作规范
共2600页!又一份神级的面试手册面世~
ZOJ - 4114 flipping game DP, reasonable state representation
2021 Shanghai sai-d-cartland number variant, DP
Leetcode - 362 knock counter (Design)