www.pudn.com > 数字硬盘录像机软件代码.rar > Digitclock.cpp


// DigitClock.cpp : implementation file 
// 
#include "stdafx.h" 
#include "GtMpeg.h" 
#include "DigitClock.h" 
#include "GtMpegWnd.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
////////////////////////////////////////// 
// 
////////////////////////////////////////// 
COLORREF CDigitClock::origin = RGB(0,255,0);  
////////////////////////////////////////// 
// 
////////////////////////////////////////// 
CDigitClock::CDigitClock() 
{ 
	m_style = XDC_NOSECOND; 
	m_color = origin; 
	for(int i = 0; i< 12; i++)  
		m_Bitmap[i].LoadBitmap(IDB_CLOCK_0+i); 
	m_DotBitmap.LoadBitmap(IDB_DOT); 
	m_bCreate=FALSE; 
} 
 
CDigitClock::~CDigitClock() 
{ 
} 
////////////////////////////////////////// 
// 
////////////////////////////////////////// 
BEGIN_MESSAGE_MAP(CDigitClock, CStatic) 
	//{{AFX_MSG_MAP(CDigitClock) 
	ON_WM_TIMER() 
	ON_WM_DESTROY() 
	ON_WM_ERASEBKGND() 
	ON_WM_PAINT() 
	ON_WM_CREATE() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
////////////////////////////////////////// 
// 
////////////////////////////////////////// 
void CDigitClock::PreSubclassWindow()  
{ 
	m_nTimer = SetTimer(1, 1000, NULL); 
	m_Bitmap[0].GetBitmap(&m_bm); 
	CStatic::PreSubclassWindow(); 
} 
////////////////////////////////////////// 
// 
////////////////////////////////////////// 
void CDigitClock::OnDestroy()  
{ 
	CStatic::OnDestroy(); 
	KillTimer(m_nTimer);	 
} 
////////////////////////////////////////// 
// 
////////////////////////////////////////// 
void CDigitClock::OnPaint()  
{ 
	CPaintDC dc(this); 
	if(!m_bCreate) 
	{ 
	  	CRect rect; 
	    GetWindowRect(rect); 
        m_w = rect.Width()/14;	 
	    rect.right=rect.left+m_w*14; 
        //MoveWindow(rect); 
		m_bCreate=TRUE; 
	} 
	CTime time = CTime::GetCurrentTime(); 
	int nh0 = time.GetHour()/10; 
	Output(nh0, 0); 
	int nh1=time.GetHour()%10;	 
	Output(nh1, 1); 
	int nh2 = time.GetHour()%10; 
	Output(nh2, 1); 
	int nm1 = time.GetMinute()/10; 
	Output(nm1, 3); 
	int nm2 = time.GetMinute()%10; 
	Output(nm2, 4); 
	int ns1 = time.GetSecond()/10; 
   	Output(ns1, 6); 
	int s2 = time.GetSecond()%10; 
	Output(s2, 7); 
	Output(10, 2); // double points 
	Output(10, 5); // double points 
	int nMonth = time.GetMonth(); 
	int nDay = time.GetDay(); 
	OutputDate(nMonth, 0); 
    OutputDate(nDay, 3); 
} 
////////////////////////////////////////// 
// 
////////////////////////////////////////// 
BOOL CDigitClock::OnEraseBkgnd(CDC* pDC)  
{ 
	CBrush brush; 
	//brush.CreateSolidBrush( ::GetSysColor(COLOR_WINDOWTEXT) );  
	brush.CreateSolidBrush(GetCurrentColor(COLOR_GREEN));  
	CBrush* pOldBrush = pDC->SelectObject(&brush); 
	CRect rectClient; 
	GetClientRect(&rectClient); 
    m_w = rectClient.Width()/14;	 
	m_h =rectClient.Height();	 
	pDC->PatBlt(0, 0, rectClient.Width(), rectClient.Height(), PATCOPY); 
	pDC->SelectObject(pOldBrush); 
	return CStatic::OnEraseBkgnd(pDC); 
} 
////////////////////////////////////////// 
// 
////////////////////////////////////////// 
void CDigitClock::OnTimer(UINT nIDEvent)  
{ 
	CGtMpegWnd *pWnd=(CGtMpegWnd *)GetParent(); 
	if(nIDEvent == m_nTimer)  
	{ 
		if(pWnd->m_nRecords>0) 
		{ 
		  for(DWORD i=0;iRecordSubsection(); 
		} 
	    if(pWnd->m_nPlays>0) 
		{ 
		   for(DWORD i=0;iPlaySubsection(); 
		   } 
		} 
		CRect rectClient; 
		GetClientRect(&rectClient); 
		m_h = rectClient.Height(); 
		m_w = rectClient.Width()/14; 
		 CTime time = CTime::GetCurrentTime(); 
        //秒 
        int ns1 = time.GetSecond()/10; 
   		Output(ns1, 6); 
		int s2 = time.GetSecond()%10; 
		Output(s2, 7); 
        if(time.GetSecond()>=55||time.GetSecond()<=5) 
		{ 
		  //分 
		  int nm1 = time.GetMinute()/10; 
		  Output(nm1, 3); 
		  int nm2 = time.GetMinute()%10; 
		  Output(nm2, 4); 
	      NMHDR Msg; 
	      Msg.hwndFrom=m_hWnd; 
          Msg.code=_CHECK_DISK_SPACE; 
          GetParent()->SendMessage(WM_NOTIFY,_CHECK_DISK_SPACE,(LPARAM)&Msg); 
		  if(theApp.GetProfileInt("系统参数","自动清理",0)==1) 
		      CleanMpegFile(GetAppPath()+"mpeg"); 
		} 
        //小时 
		if(time.GetMinute()==0) 
		{ 
		  if(time.GetSecond()<=5) 
		  { 
		    int nh0 = time.GetHour()/10; 
		    Output(nh0, 0); 
		    int nh1=time.GetHour()%10;	 
		    Output(nh1, 1); 
		    int nh2 = time.GetHour()%10; 
		    Output(nh2, 1); 
		  } 
		} 
		//Output(10, 2); // double points 
		//Output(10, 5); // double points 
		if(time.GetHour()==0) 
		{ 
		  if(time.GetMinute()<=1) 
		  { 
		    int nMonth = time.GetMonth(); 
		    int nDay = time.GetDay(); 
		    OutputDate(nMonth, 0); 
            OutputDate(nDay, 3); 
		  } 
		} 
		if(pWnd->m_bAlarming) 
		{ 
		   if(!pWnd->m_AlarmSound.IsPlaying()) 
               pWnd->m_AlarmSound.Play(); 
		} 
		pWnd->CheckEnterDelayZone(); 
		pWnd->CheckZoneRecord(); 
		pWnd->CheckSecondaryAlarm(); 
		pWnd->m_cDiskSpace.SetPos(GetDiskFreeSpaceScale(GetAppPath())); 
	} 
	CStatic::OnTimer(nIDEvent); 
} 
////////////////////////////////////////// 
// 
////////////////////////////////////////// 
void CDigitClock::Output(UINT digit, UINT pos) 
{ 
	CClientDC dc(this); 
	CDC dcMem; 
	dcMem.CreateCompatibleDC(&dc); 
    CBitmap* pOldBitmap = dcMem.SelectObject(&m_Bitmap[11]); 
	dc.BitBlt(m_w*(pos+6), 0,m_bm.bmWidth, m_bm.bmHeight,&dcMem,0,0,SRCCOPY); 
 	dcMem.SelectObject(pOldBitmap); 
	dcMem.DeleteDC(); 
	APutImage(&dc,m_w*(pos+6), 0,&m_Bitmap[digit],GetCurrentColor(COLOR_WHITE)); 
} 
////////////////////////////////////////// 
// 
////////////////////////////////////////// 
void CDigitClock::OutputDate(UINT digit, UINT pos) 
{ 
	CClientDC dc(this); 
	CDC dcMem; 
	CString sTxt; 
	sTxt.Format("%02d",digit); 
	dcMem.CreateCompatibleDC(&dc); 
	int nTmp=StringToInt(sTxt[0]); 
    CBitmap* pOldBitmap = dcMem.SelectObject(&m_Bitmap[11]); 
	dc.BitBlt(m_w*pos, 0,m_bm.bmWidth, m_bm.bmHeight,&dcMem,0,0,SRCCOPY); 
	APutImage(&dc,m_w*pos, 0,&m_Bitmap[nTmp],GetCurrentColor(COLOR_WHITE)); 
 
	nTmp=StringToInt(sTxt[1]); 
	dc.BitBlt(m_w*(pos+1), 0,m_bm.bmWidth, m_bm.bmHeight,&dcMem,0,0,SRCCOPY); 
	APutImage(&dc,m_w*(pos+1), 0,&m_Bitmap[nTmp],GetCurrentColor(COLOR_WHITE)); 
 
	dc.BitBlt(m_w*2, 0,m_bm.bmWidth, m_bm.bmHeight,&dcMem,0,0,SRCCOPY); 
	APutImage(&dc,m_w*2, 0,&m_DotBitmap,GetCurrentColor(COLOR_WHITE)); 
 
 
	dcMem.SelectObject(pOldBitmap); 
	dcMem.DeleteDC(); 
} 
////////////////////////////////////////// 
// 
////////////////////////////////////////// 
CDigitClock::CClockStyle CDigitClock::SetStyle(CClockStyle style) 
{ 
	CClockStyle temp = m_style; 
	m_style = style; 
	return temp; 
} 
////////////////////////////////////////// 
// 
////////////////////////////////////////// 
COLORREF CDigitClock::SetColor(COLORREF color) 
{ 
	if(m_color == color) 
		return color; 
	COLORREF temp = m_color; 
	m_color = color; 
/*	for(int i = 0; i< 12; i++)  
	{ 
		if(m_Bitmap[i]) 
			::DeleteObject(m_hBitmap[i]); 
		COLORMAP	mapColor; 
		mapColor.from = origin; 
		mapColor.to  = color; 
		HBITMAP temp = (HBITMAP)::CreateMappedBitmap(AfxGetApp()->m_hInstance, i+IDB_CLOCK_0, 0, &mapColor, 1); 
		m_hBitmap[i] = (HBITMAP)::CopyImage( temp, IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG | LR_COPYDELETEORG); 
	}*/ 
	return temp; 
} 
////////////////////////////////////////// 
// 
////////////////////////////////////////// 
 
int CDigitClock::OnCreate(LPCREATESTRUCT lpCreateStruct)  
{ 
	if (CStatic::OnCreate(lpCreateStruct) == -1) 
		return -1; 
	//CRect 
	 
	return 0; 
}