Old fashion design for PC-104
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
4.5 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 13/04/2001
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: ClockWnd.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of ClockWnd.cpp
  13. //----------------------------------------------------------------------------
  14. // ClockWnd.cpp : implementation file
  15. //
  16. #include "stdafx.h"
  17. #include "chicago.h"
  18. #include "ClockWnd.h"
  19. #include "Version.h"
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CClockWnd
  27. CClockWnd::CClockWnd()
  28. {
  29. }
  30. CClockWnd::~CClockWnd()
  31. {
  32. }
  33. BEGIN_MESSAGE_MAP(CClockWnd, CWnd)
  34. //{{AFX_MSG_MAP(CClockWnd)
  35. ON_WM_PAINT()
  36. ON_WM_TIMER()
  37. ON_WM_LBUTTONDOWN()
  38. ON_WM_RBUTTONDOWN()
  39. //}}AFX_MSG_MAP
  40. END_MESSAGE_MAP()
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CClockWnd message handlers
  43. BOOL CClockWnd::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
  44. {
  45. if( CWnd::CreateEx(WS_EX_DLGMODALFRAME, lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext) )
  46. {
  47. CDC *pDC = GetDC();
  48. m_DigitsDC.CreateCompatibleDC( pDC );
  49. ReleaseDC( pDC );
  50. HBITMAP hBitmap = (HBITMAP)::LoadImage( NULL, "DIGITS.BMP", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE );
  51. // m_DigitsBitmap.LoadBitmap( IDB_BITMAP_DIGITS );
  52. m_DigitsBitmap.Attach( hBitmap );
  53. m_pDigitsBitmapOld = m_DigitsDC.SelectObject( &m_DigitsBitmap );
  54. m_nDigitType = 0;
  55. m_ActualSize.cx = 44 * 8;
  56. m_ActualSize.cy = 83;
  57. return TRUE;
  58. }
  59. return FALSE;
  60. }
  61. void CClockWnd::OnPaint()
  62. {
  63. CPaintDC dc(this);
  64. PaintTime( &dc );
  65. }
  66. void CClockWnd::OnTimer(UINT nIDEvent)
  67. {
  68. CDC *pDC = GetDC();
  69. PaintTime( pDC );
  70. ReleaseDC( pDC );
  71. CWnd::OnTimer(nIDEvent);
  72. }
  73. void CClockWnd::OnLButtonDown(UINT nFlags, CPoint point)
  74. {
  75. m_nDigitType = (m_nDigitType + 1)%3;
  76. CDC *pDC = GetDC();
  77. PaintTime( pDC );
  78. ReleaseDC( pDC );
  79. CWnd::OnLButtonDown(nFlags, point);
  80. }
  81. void CClockWnd::OnRButtonDown(UINT nFlags, CPoint point)
  82. {
  83. m_nDigitType = (m_nDigitType + 2)%3;
  84. CDC *pDC = GetDC();
  85. PaintTime( pDC );
  86. ReleaseDC( pDC );
  87. CWnd::OnRButtonDown(nFlags, point);
  88. }
  89. void CClockWnd::PaintTime(CDC *pDC)
  90. {
  91. SYSTEMTIME st;
  92. ::GetLocalTime( &st );
  93. CRect rect;
  94. GetClientRect( &rect );
  95. int srcWidth = m_ActualSize.cx / 8;
  96. int srcHeight = m_ActualSize.cy;
  97. int width = rect.Width() / 8;
  98. int height = srcHeight * width / srcWidth;
  99. CPoint p( (rect.Width() - 8 * width) / 2, (rect.Height() - height) / 2 );
  100. CRect rect1( rect.left, rect.top, rect.left + p.x, rect.bottom );
  101. CRect rect2( rect.left + p.x + width * 8, rect.top, rect.right, rect.bottom );
  102. CRect rect3( rect.left + p.x, rect.top, rect.left + p.x + width * 8, rect.top + p.y );
  103. CRect rect4( rect.left + p.x, rect.top + p.y + height, rect.left + p.x + width * 8, rect.bottom );
  104. const int hShift = m_nDigitType * srcHeight;
  105. COLORREF color = m_DigitsDC.GetPixel( 0, hShift );
  106. pDC->FillSolidRect( &rect1, color );
  107. pDC->FillSolidRect( &rect2, color );
  108. pDC->FillSolidRect( &rect3, color );
  109. pDC->FillSolidRect( &rect4, color );
  110. // pDC->FillSolidRect( &rect, );
  111. pDC->StretchBlt( width * 0 + p.x, p.y, width, height, &m_DigitsDC, srcWidth * (st.wHour / 10), hShift, srcWidth, srcHeight, SRCCOPY );
  112. pDC->StretchBlt( width * 1 + p.x, p.y, width, height, &m_DigitsDC, srcWidth * (st.wHour % 10), hShift, srcWidth, srcHeight, SRCCOPY );
  113. pDC->StretchBlt( width * 2 + p.x, p.y, width, height, &m_DigitsDC, srcWidth * 10, hShift, srcWidth, srcHeight, SRCCOPY );
  114. pDC->StretchBlt( width * 3 + p.x, p.y, width, height, &m_DigitsDC, srcWidth * (st.wMinute / 10), hShift, srcWidth, srcHeight, SRCCOPY );
  115. pDC->StretchBlt( width * 4 + p.x, p.y, width, height, &m_DigitsDC, srcWidth * (st.wMinute % 10), hShift, srcWidth, srcHeight, SRCCOPY );
  116. pDC->StretchBlt( width * 5 + p.x, p.y, width, height, &m_DigitsDC, srcWidth * 10, hShift, srcWidth, srcHeight, SRCCOPY );
  117. pDC->StretchBlt( width * 6 + p.x, p.y, width, height, &m_DigitsDC, srcWidth * (st.wSecond / 10), hShift, srcWidth, srcHeight, SRCCOPY );
  118. pDC->StretchBlt( width * 7 + p.x, p.y, width, height, &m_DigitsDC, srcWidth * (st.wSecond % 10), hShift, srcWidth, srcHeight, SRCCOPY );
  119. }