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.

166 lines
4.3 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 15/04/2000
  5. // Last modification: 08/10/2003
  6. // Project Intruder Position Indicator
  7. // SUBSYSTEM: Preview
  8. // FILE: Preview.cpp
  9. // AUTHOR: Chizhevskiy Sergey
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file for implemenation of class CPreview
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "..\LgLib\Version.h"
  16. #include "Preview.h"
  17. CPreview::CPreview()
  18. {
  19. m_Index = 0;
  20. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CPreview::CPreview" );
  21. }
  22. CPreview::~CPreview()
  23. {
  24. if(m_hBitmap)
  25. {
  26. ::SendMessage(m_hWnd, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)NULL);
  27. ::DeleteDC(m_hMemDC);
  28. ::DeleteDC(m_hMemCopyDC);
  29. ::DeleteObject(m_hBitmap);
  30. }
  31. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CPreview::~CPreview" );
  32. }
  33. BOOL CPreview::Create(HWND hWnd, LPPOINT pPoint, LPSIZE pSize)
  34. {
  35. static const POINT p = { 0, 0 };
  36. static const POINT s = { 192 * 3, 144 * 5 };
  37. if(!pPoint)
  38. pPoint = (LPPOINT)&p;
  39. if(!pSize)
  40. pSize = (LPSIZE)&s;
  41. m_hWnd = ::CreateWindow("STATIC", NULL, WS_CHILD | SS_BITMAP, pPoint->x, pPoint->y,
  42. pSize->cx, pSize->cy, hWnd, NULL,
  43. (HINSTANCE)::GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
  44. m_Size = *pSize;
  45. HDC hDC = ::GetDC(m_hWnd);
  46. m_hMemDC = ::CreateCompatibleDC(hDC);
  47. m_hMemCopyDC = ::CreateCompatibleDC(hDC);
  48. m_hBitmap = ::CreateCompatibleBitmap(hDC, m_Size.cx, m_Size.cy);
  49. ::ReleaseDC(m_hWnd, hDC);
  50. ::SendMessage(m_hWnd, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)m_hBitmap);
  51. Reset();
  52. return TRUE;
  53. }
  54. BOOL CPreview::AddPreview(HBITMAP hBitmap)
  55. {
  56. BITMAPINFO bmi;
  57. ZeroMemory(&bmi, sizeof(bmi));
  58. bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  59. if( !::GetDIBits( m_hMemCopyDC, hBitmap, 0, 0, NULL, &bmi, DIB_RGB_COLORS ) )
  60. {
  61. bmi.bmiHeader.biWidth = 384;
  62. bmi.bmiHeader.biHeight = 288;
  63. }
  64. HBITMAP hOldBitmap1 = (HBITMAP)::SelectObject(m_hMemDC, m_hBitmap);
  65. HBITMAP hOldBitmap2 = (HBITMAP)::SelectObject(m_hMemCopyDC, hBitmap);
  66. RECT rect = { (m_Index % 3) * m_Size.cx / 3, (m_Index / 3) * m_Size.cy / 5,
  67. ((m_Index % 3) + 1 ) * m_Size.cx / 3, ((m_Index / 3) + 1) * m_Size.cy / 5 };
  68. INT nStretchMode = ::SetStretchBltMode( m_hMemDC, COLORONCOLOR );
  69. ::StretchBlt(m_hMemDC, rect.left, rect.top, m_Size.cx / 3 + 1, m_Size.cy / 5 + 1, m_hMemCopyDC, 0, 0, bmi.bmiHeader.biWidth, bmi.bmiHeader.biHeight, SRCCOPY);
  70. ::SetStretchBltMode( m_hMemDC, nStretchMode );
  71. ::SelectObject(m_hMemCopyDC, hOldBitmap2);
  72. ::SelectObject(m_hMemDC, hOldBitmap1);
  73. ::InvalidateRect(m_hWnd, &rect, FALSE);
  74. ::UpdateWindow(m_hWnd);
  75. m_Index = (m_Index + 1) % 15;
  76. return TRUE;
  77. }
  78. void CPreview::Reset()
  79. {
  80. RECT rect = { 0, 0, m_Size.cx, m_Size.cy };
  81. HBITMAP hOldBitmap = (HBITMAP)::SelectObject(m_hMemDC, m_hBitmap);
  82. ::FillRect(m_hMemDC, &rect, (HBRUSH)::GetStockObject(BLACK_BRUSH));
  83. ::SelectObject(m_hMemDC, hOldBitmap);
  84. ::InvalidateRect(m_hWnd, NULL, FALSE);
  85. ::UpdateWindow(m_hWnd );
  86. m_Index = 0;
  87. }
  88. BOOL CPreview::Show(BOOL bShow)
  89. {
  90. ::ShowWindow(m_hWnd, bShow ? SW_SHOW : SW_HIDE);
  91. ::InvalidateRect(m_hWnd, NULL, FALSE);
  92. ::UpdateWindow(m_hWnd);
  93. return TRUE;
  94. }
  95. BOOL CPreview::StoreImage1(HANDLE hFile)
  96. {
  97. BITMAPFILEHEADER bfh;
  98. BITMAPINFO bmi;
  99. DWORD dwWrite;
  100. ZeroMemory(&bmi, sizeof(bmi));
  101. bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  102. ::GetDIBits(m_hMemDC, m_hBitmap, 0, 0, NULL, &bmi, DIB_RGB_COLORS);
  103. bmi.bmiHeader.biCompression = 0;
  104. LPBYTE pByte = new BYTE[bmi.bmiHeader.biSizeImage];
  105. ::GetDIBits(m_hMemDC, m_hBitmap, 0, bmi.bmiHeader.biHeight, pByte, &bmi, DIB_RGB_COLORS);
  106. bfh.bfType = (((WORD)'M') << 8) + 'B';
  107. bfh.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + bmi.bmiHeader.biSizeImage;
  108. bfh.bfReserved1 = 0;
  109. bfh.bfReserved2 = 0;
  110. bfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
  111. ::WriteFile(hFile, &bfh, sizeof(BITMAPFILEHEADER), &dwWrite, NULL);
  112. ::WriteFile(hFile, &bmi, sizeof(BITMAPINFOHEADER), &dwWrite, NULL);
  113. ::WriteFile(hFile, pByte, bmi.bmiHeader.biSizeImage, &dwWrite, NULL);
  114. delete[] pByte;
  115. return TRUE;
  116. }