|
|
//----------------------------------------------------------------------------
// Laser Guard Ltd.
// Copyright � 2000-2002. All Rights Reserved.
// Version 1.0 01/01/2000
// Last modification: 13/04/2001
// PROJECT:
// SUBSYSTEM:
// FILE: ClockWnd.cpp
// AUTHOR: Sergey Chizhevskiy
// OVERVIEW
// ~~~~~~~~
// Source file of ClockWnd.cpp
//----------------------------------------------------------------------------
// ClockWnd.cpp : implementation file
//
#include "stdafx.h"
#include "chicago.h"
#include "ClockWnd.h"
#include "Version.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;#endif
/////////////////////////////////////////////////////////////////////////////
// CClockWnd
CClockWnd::CClockWnd(){}
CClockWnd::~CClockWnd(){}
BEGIN_MESSAGE_MAP(CClockWnd, CWnd) //{{AFX_MSG_MAP(CClockWnd)
ON_WM_PAINT() ON_WM_TIMER() ON_WM_LBUTTONDOWN() ON_WM_RBUTTONDOWN() //}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CClockWnd message handlers
BOOL CClockWnd::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) { if( CWnd::CreateEx(WS_EX_DLGMODALFRAME, lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext) ) { CDC *pDC = GetDC(); m_DigitsDC.CreateCompatibleDC( pDC ); ReleaseDC( pDC ); HBITMAP hBitmap = (HBITMAP)::LoadImage( NULL, "DIGITS.BMP", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE );// m_DigitsBitmap.LoadBitmap( IDB_BITMAP_DIGITS );
m_DigitsBitmap.Attach( hBitmap ); m_pDigitsBitmapOld = m_DigitsDC.SelectObject( &m_DigitsBitmap ); m_nDigitType = 0; m_ActualSize.cx = 44 * 8; m_ActualSize.cy = 83; return TRUE; } return FALSE;}
void CClockWnd::OnPaint() { CPaintDC dc(this);
PaintTime( &dc );}
void CClockWnd::OnTimer(UINT nIDEvent) { CDC *pDC = GetDC(); PaintTime( pDC ); ReleaseDC( pDC );
CWnd::OnTimer(nIDEvent);}
void CClockWnd::OnLButtonDown(UINT nFlags, CPoint point) { m_nDigitType = (m_nDigitType + 1)%3; CDC *pDC = GetDC(); PaintTime( pDC ); ReleaseDC( pDC ); CWnd::OnLButtonDown(nFlags, point);}
void CClockWnd::OnRButtonDown(UINT nFlags, CPoint point) { m_nDigitType = (m_nDigitType + 2)%3; CDC *pDC = GetDC(); PaintTime( pDC ); ReleaseDC( pDC ); CWnd::OnRButtonDown(nFlags, point);}
void CClockWnd::PaintTime(CDC *pDC){ SYSTEMTIME st; ::GetLocalTime( &st );
CRect rect; GetClientRect( &rect );
int srcWidth = m_ActualSize.cx / 8; int srcHeight = m_ActualSize.cy;
int width = rect.Width() / 8; int height = srcHeight * width / srcWidth; CPoint p( (rect.Width() - 8 * width) / 2, (rect.Height() - height) / 2 ); CRect rect1( rect.left, rect.top, rect.left + p.x, rect.bottom ); CRect rect2( rect.left + p.x + width * 8, rect.top, rect.right, rect.bottom ); CRect rect3( rect.left + p.x, rect.top, rect.left + p.x + width * 8, rect.top + p.y ); CRect rect4( rect.left + p.x, rect.top + p.y + height, rect.left + p.x + width * 8, rect.bottom );
const int hShift = m_nDigitType * srcHeight; COLORREF color = m_DigitsDC.GetPixel( 0, hShift );
pDC->FillSolidRect( &rect1, color ); pDC->FillSolidRect( &rect2, color ); pDC->FillSolidRect( &rect3, color ); pDC->FillSolidRect( &rect4, color );
// pDC->FillSolidRect( &rect, );
pDC->StretchBlt( width * 0 + p.x, p.y, width, height, &m_DigitsDC, srcWidth * (st.wHour / 10), hShift, srcWidth, srcHeight, SRCCOPY ); pDC->StretchBlt( width * 1 + p.x, p.y, width, height, &m_DigitsDC, srcWidth * (st.wHour % 10), hShift, srcWidth, srcHeight, SRCCOPY ); pDC->StretchBlt( width * 2 + p.x, p.y, width, height, &m_DigitsDC, srcWidth * 10, hShift, srcWidth, srcHeight, SRCCOPY ); pDC->StretchBlt( width * 3 + p.x, p.y, width, height, &m_DigitsDC, srcWidth * (st.wMinute / 10), hShift, srcWidth, srcHeight, SRCCOPY ); pDC->StretchBlt( width * 4 + p.x, p.y, width, height, &m_DigitsDC, srcWidth * (st.wMinute % 10), hShift, srcWidth, srcHeight, SRCCOPY ); pDC->StretchBlt( width * 5 + p.x, p.y, width, height, &m_DigitsDC, srcWidth * 10, hShift, srcWidth, srcHeight, SRCCOPY ); pDC->StretchBlt( width * 6 + p.x, p.y, width, height, &m_DigitsDC, srcWidth * (st.wSecond / 10), hShift, srcWidth, srcHeight, SRCCOPY ); pDC->StretchBlt( width * 7 + p.x, p.y, width, height, &m_DigitsDC, srcWidth * (st.wSecond % 10), hShift, srcWidth, srcHeight, SRCCOPY );}
|