📄 displaythread.cpp
字号:
// DisplayThread.cpp: implementation of the CDisplayThread class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "UIThread.h"
#include "DisplayThread.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
IMPLEMENT_DYNCREATE(CDisplayThread,CExampleThread)
CDisplayThread::CDisplayThread()
{
}
CDisplayThread::~CDisplayThread()
{
}
int CDisplayThread::Run()
{
BOOL fSyncChecked;//同步机制复选检测
unsigned int nNumber;//存储字符串中整数
if (m_pOwner == NULL)
return -1;
//将同步对象同锁对象联系起来
CSingleLock sLock(&(m_pOwner->m_mutex));
while (!m_bDone)//控制线程运行,为终止线程服务
{
//取同步机制复选状态
fSyncChecked = m_pOwner->IsDlgButtonChecked(IDC_SYNCHRONIZE);
//确定是否使用同步机制
if (fSyncChecked)
sLock.Lock();
//读取整数
_stscanf((LPCTSTR) m_pOwner->m_strNumber,_T("%d"), &nNumber);
nNumber++;//加1
m_pOwner->m_strNumber.Empty();//字符串置空
while (nNumber != 0) //更新字符串
{
m_pOwner->m_strNumber+=(TCHAR) ('0'+nNumber%10);
nNumber/= 10;
}
//调整字符串顺序
m_pOwner->m_strNumber.MakeReverse();
//如果复选同步机制,释放资源
if (fSyncChecked)
sLock.Unlock();
//确定复选显示计数线程
if (m_pOwner->IsDlgButtonChecked(IDC_SHOWCNTRTHRD)){
m_pOwner->AddToListBox(_T("Counter: Add 1"));
Sleep(1000);
}
}//结束while
m_pOwner->PostMessage(WM_CLOSE, 0, 0L);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -