mytimer.cpp

来自「本人工作中的一个软件开发实例。里面包含了数据库」· C++ 代码 · 共 71 行

CPP
71
字号
// MyTimer.cpp: implementation of the CMyTimer class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "MyTimer.h"
#include "ColorEdit.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

CTimerMap CMyTimer::m_sTimeMap;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

//构造函数
CMyTimer::CMyTimer(UINT nPickerID,UINT nTimeType)
{
	m_nPickerID=nPickerID;   //保存鹤位ID
	m_nTimeType=nTimeType;   //保存时钟类型
	m_nTimerID = 0;          //保存时钟ID    
}

//析构函数
CMyTimer::~CMyTimer()
{
}

//时钟回调函数
void CALLBACK CMyTimer::MyTimerProc(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime)
{
	CString sz;
	sz.Format("%s",m_sTimeMap[idEvent]->szContent);
	//AfxMessageBox(sz);

	int m_PickerID=m_sTimeMap[idEvent]->m_nPickerID;   //鹤位ID
	int m_TimeType=m_sTimeMap[idEvent]->m_nTimeType;   //时钟类型
    HWND pWnd=AfxGetApp()->m_pMainWnd->GetSafeHwnd();  //父窗口HWND

	if(m_TimeType==TIMEOUT)  //超时
	{
        HWND m_hwnd=GetDlgItem(pWnd,PICKERID(m_PickerID));
		CColorEdit * m_ColorEdit=(CColorEdit *)(CWnd::FromHandle(m_hwnd));
		m_ColorEdit->SetColor(RED);
	}
	else  //刷新
	{
		 CString   strSend;
         ::SetWindowText(::GetDlgItem(pWnd,SEND(m_PickerID)),strSend);  //更新已发油
	}	
}

//设置时钟
void CMyTimer::SetMyTimer(UINT nElapse,CString sz)
{
	szContent = sz;
	m_nTimerID = SetTimer(NULL,NULL,nElapse,MyTimerProc);
	m_sTimeMap[m_nTimerID] = this;
}

//删除时钟
void CMyTimer::KillMyTimer()
{
	KillTimer(NULL,m_nTimerID);
	m_sTimeMap.RemoveKey(m_nTimerID);
} 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?