资源简介
程序使用TAB控件生成了3个Dialog,每个dialog上都有一个简单的MFC多线程实例,简单易懂,且有注释,是MFC多线程学习的好帮手,多线程传参数:传递窗口句柄等等
代码片段和文件信息
// Dialog1.cpp : implementation file
//
#include “stdafx.h“
#include “MultiThread11.h“
#include “Dialog1.h“
extern m_flag;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDialog1 dialog
BOOL m_flag = TRUE;
CDialog1::CDialog1(CWnd* pParent /*=NULL*/)
: CDialog(CDialog1::IDD pParent)
{
//{{AFX_DATA_INIT(CDialog1)
//}}AFX_DATA_INIT
}
void CDialog1::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDialog1)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDialog1 CDialog)
//{{AFX_MSG_MAP(CDialog1)
ON_BN_CLICKED(IDC_BUTTON1 OnButton1)
ON_BN_CLICKED(IDC_BUTTON2 OnButton2)
ON_BN_CLICKED(IDC_BUTTON3 OnButton3)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDialog1 message handlers
void ThreadFunc(LPVOID pParam)
{
CString strTime;
CDialog1 *dlg;
dlg = (CDialog1 *)pParam;
CTime time;
m_flag = TRUE;
while(m_flag)
{
time = CTime::GetCurrentTime();
strTime=time.Format(“%H:%M:%S“);
::SetDlgItemText(dlg->m_hWndIDC_EDIT1strTime);
// GetDlgItem(IDC_EDIT1)->setwindow
Sleep(1000);
}
ExitThread(1);
}
void CDialog1::OnButton1() //启动线程//传递的参数 是 窗口对象指针
{
// TODO: Add your control notification handler code here
hThread=CreateThread(NULL
0
(LPTHREAD_START_ROUTINE)ThreadFunc
this
0
&ThreadID);
GetDlgItem(IDC_BUTTON1)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON2)->EnableWindow(TRUE);
}
void CDialog1::OnButton2()
{
// TODO: Add your control notification handler code here
m_flag = false;
GetDlgItem(IDC_BUTTON1)->EnableWindow(true);
GetDlgItem(IDC_BUTTON2)->EnableWindow(FALSE);
}
void CDialog1::OnButton3()
{
// TODO: Add your control notification handler code here
TerminateThread(hThread1);
GetDlgItem(IDC_BUTTON1)->EnableWindow(true);
GetDlgItem(IDC_BUTTON2)->EnableWindow(FALSE);
}
- 上一篇:C++项目源代码适合新手练手及参考
- 下一篇:华为C++语言编程规范
相关资源
- GD32通过规则组寄存器 DMA获取多组AD
- VC6LineNumberAddin.dll
- Adobe Acrobat X Pro汉化CIDFont字体包
- qt进度条(RoundProgressBar)
- gd32的单通道adc用dma采集
- ADS1263驱动程序+电路图
- STM32-ads1256
- AD5328驱动程序
- ADS1256-STM32参考程序
- stm32 AD7506
- Linux那些事儿之我是USB core
- 显示屏操作(stm32f103c8t6(SAN))
- FREERTOS 实时内核 实用指南
- 基于STM32的音频信号采样与FFT分析
- stm32 BootLoader程序(main.c)
- 高性能服务器代码(50_06th_server_thre
- mfc 调用redis
- CreatBitmap图片合成源码
- The GNU C Library Reference Manual (1196页)
- FreeRTOS FreeModbus
- 使用 IBM Rational Systems Developer 和 Rati
- Microsoft Visual C++ 2005 Redistributable Pack
- 水晶报表Crystal Reports运行环境CRRunti
- Effective C++ More effective C++ 中文版 .ch
- 《Data Structures and Algorithm Analysis in C
- ResHacker 3.5 汉化 绝对可用
- Microsoft Visual C++ 2010 Redistributable Pack
- MFC绘制Bezier曲线B样条曲线曲线拟合
- python 3.8终极大法解决Microsoft Visual C
- ADRC相关技术资料
川公网安备 51152502000135号
评论
共有 条评论