当前位置:网站首页>How to add a thread in MFC
How to add a thread in MFC
2022-07-19 13:13:00 【Nobody】
In this paper, we introduce a new method in MFC An operation often encountered in programming : How to add a thread ? I don't say much nonsense , Go straight to step .
First, create a new one thread_op.h and thread_op.c file .
I added an image processing thread here , The header file is as follows :
#pragma once
#include <stdlib.h>
#include "afxwin.h"
#define WM_CONF_IMGPROC WM_USER+101 // This macro is critical
enum TEST_RES_CODE {
TR_FAIL,
TR_SUCCESS,
TR_EXCEPTION,
};
typedef struct TestResult {
bool isbrpass;
bool isdarkpass;
long brnum;
}TestResult;
typedef struct ImgThreadPra {
CWnd* pDlg;
int size;
}ImgThreadPra;
UINT imgProcThread(LPVOID pParam);
The corresponding implementation files are as follows :
#include <stdlib.h>
#include "afxwin.h"
#include "thread_op.h"
UINT imgProcThread(LPVOID pParam)
{
ImgThreadPra* pStruct = (ImgThreadPra*)pParam;
if (pStruct == NULL || pStruct->pDlg == NULL)
return -1;
/* Pass the result to the main thread */
pStruct->pDlg->SendMessage(WM_CONF_IMGPROC, 0, (long)* testResult);
}
next , Add an object to the class in the dialog header file .
CWinThread *pTestThread;
TestThreadPra imgTestThreadPra;
LRESULT WindowProc(UINT message, WPARAM WParam, LPARAM lParam);
Establish the connection with the main dialog box in the initialization interface of the dialog box main program :
ImgThreadPra.pDlg = this;
After that, some operations that you want to perform after clicking the button are left to other threads to operate , such as :
void CguiDlg::OnBnClickedOk()
{
// TODO: Add control notification handler code here
CDialogEx::OnOK();
pTestThread = AfxBeginThread(imgProcThread, &imgTestThreadPra);
}
Last in windowProc Medium switch Add case Processing can be :
LRESULT testTool::WindowProc(UINT message, WPARAM WParam, LPARAM lParam)
{
TestResult *ret = NULL;
switch WM_CONF_IMGPROC:
testResult = (TestResult*)lParam;
break;
return CDialog::WindowProc(message, wParam, lParam);
}
边栏推荐
- Cadmium sulfide supported mil-125 (TI) | streptavidin (SA) - zirconium porphyrin MOF composite (PCN- [email protected] )|Shell core
- Cobalt iron bimetallic organic skeleton cox/mil-100 (FE) | [email protected]
- torch.utils.data.DataLoader说明
- 【Pygame 学习笔记】7.事件
- OSSImport迁移之路
- 力扣64-最小路径和——动态规划入门题型
- Supported metal organic framework zif-8 / graphene oxide hydrogen storage material | titanium dioxide /zif-8 composite | silicon dioxide @zif8 nano material
- PostgreSQL function usage record
- Which domestic API tool is better? It turned out to be it
- 2022全球开发者薪资曝光:中国排第19名,平均年薪23,790美元
猜你喜欢

Uio-66 | fe3o4/cu3 (BTC) 2 metal organic framework (MOF) nanocomposites supported on silver nanoparticles | nagdf4:yb, er upconversion nanoparticles @zif-8

LeetCode 0117. 填充每个节点的下一个右侧节点指针 II

【错误记录/selectpicker】dropdown menu显示位置出现偏移

【Pygame 学习笔记】6.Cursor 鼠标光标

Reg of sequential logic and combinatorial logic

每周小结(*65):有计划的输出

XML建模(简单易学)

Return to risk ratio: the most important indicator of investment opportunities 2020-03-14
[email protected] Cobalt iron bimetallic organic skeleton cox/mil-100 (FE) | [email protected]

Security measures for tcp/ip protocol vulnerabilities
随机推荐
Binary tree 2-symmetry recursion problem
[try to hack] ARP and ARP deception
[error record /selectpicker] the display position of dropdown menu is offset
Is the career direction of test / development programmers over 35 a turning point in the workplace?
The difference and use between get request and post request
What are the pain points of collaborative tools collaborative office management
[pyGame learning notes] 7 event
Li Kou 413 division of equal difference sequence dynamic programming
sqli-labs(less-11)
Porphyrin encapsulated organometallic frame materials [email protected] |
About the "bottom reading" mentality, it makes you exhausted 2020-03-15
torch.utils.data.DataLoader说明
Security measures for tcp/ip protocol vulnerabilities
整理了一份通用的内存管理驱动代码
AcWing 257. Explanation of prisoner detention (bipartite picture)
Solutions to the failure of dedecms dream weaving to save the current column changes
MOF customized product | n-k2ti4o9/g-c3n4/uio-66 ternary composite | paper based au-aginse2-zif-8 Nanocomposite
LeetCode 0117. 填充每个节点的下一个右侧节点指针 II
2022年最新吉林建筑安全员模拟题库及答案
When will the deflationary market reverse? How should we operate? 2020-03-13