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.

147 lines
3.8 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: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: ImageWnd.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of ImageWnd.cpp
  13. //----------------------------------------------------------------------------
  14. // ImageWnd.cpp : implementation file
  15. //
  16. #include "stdafx.h"
  17. #include "chicago.h"
  18. #include "ImageWnd.h"
  19. #include "..\..\LgLib\Version.h"
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CImageWnd
  27. CImageWnd::CImageWnd()
  28. {
  29. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CImageWnd::CImageWnd") );
  30. }
  31. CImageWnd::~CImageWnd()
  32. {
  33. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CImageWnd::~CImageWnd") );
  34. }
  35. BEGIN_MESSAGE_MAP(CImageWnd, CWnd)
  36. //{{AFX_MSG_MAP(CImageWnd)
  37. ON_WM_PAINT()
  38. ON_WM_SIZE()
  39. //}}AFX_MSG_MAP
  40. END_MESSAGE_MAP()
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CImageWnd message handlers
  43. BOOL CImageWnd::Create(CWnd *pParentWnd, int x, int y, int cx, int cy)
  44. {
  45. CString strClassName = ::AfxRegisterWndClass( CS_HREDRAW | CS_VREDRAW, ::LoadCursor( NULL, IDC_ARROW ), NULL, NULL );
  46. CRect rect( x, y, x + cx, y + cy );
  47. if( CWnd::Create( strClassName, NULL, WS_CHILD|WS_VISIBLE, rect, pParentWnd, 0 ) )
  48. {
  49. m_MemDC.Create( cx, cy );
  50. CClientDC dc( this );
  51. m_CopyDC.CreateCompatibleDC( &dc );
  52. return TRUE;
  53. }
  54. return FALSE;
  55. }
  56. BOOL CImageWnd::Create( CWnd *pParentWnd, CRect *pRect )
  57. {
  58. return CImageWnd::Create( pParentWnd, pRect->left, pRect->top, pRect->Width(), pRect->Height() );
  59. }
  60. void CImageWnd::PostNcDestroy()
  61. {
  62. m_CopyDC.DeleteDC();
  63. CWnd::PostNcDestroy();
  64. }
  65. void CImageWnd::OnPaint()
  66. {
  67. CPaintDC dc(this); // device context for painting
  68. CRect rect;
  69. GetClientRect( &rect );
  70. dc.BitBlt( 0, 0, rect.Width(), rect.Height(), &m_MemDC, 0, 0, SRCCOPY );
  71. }
  72. void CImageWnd::SetImage( LPBITMAPINFO pBmi, LPBYTE pBuffer )
  73. {
  74. if( pBmi && pBuffer )
  75. {
  76. // create DDB bitmap indirect
  77. LPBYTE pBits = NULL;
  78. HBITMAP hBitmap = ::CreateDIBSection( m_CopyDC.GetSafeHdc(), pBmi, DIB_RGB_COLORS, (void**)&pBits, NULL, 0UL );
  79. if( pBits )
  80. {
  81. // copy data to image bits
  82. ::CopyMemory( pBits, pBuffer, pBmi->bmiHeader.biSizeImage );
  83. // create temp CBitmap object and attach it to DDB bitmap
  84. CBitmap bmp;
  85. bmp.Attach( hBitmap );
  86. // select temp bitmap into m_CopyDC
  87. CBitmap *pBitmapOld = m_CopyDC.SelectObject( &bmp );
  88. // copy from m_CopyDC to m_MemDC
  89. int nOldStretchMode = m_MemDC.SetStretchBltMode( COLORONCOLOR );
  90. m_MemDC.StretchBlt( 0, 0, m_MemDC.GetSize().cx, m_MemDC.GetSize().cy, &m_CopyDC,
  91. 0, 0, pBmi->bmiHeader.biWidth, pBmi->bmiHeader.biHeight, SRCCOPY );
  92. m_MemDC.SetStretchBltMode( nOldStretchMode );
  93. // restore selected bitmap in m_CopyDC
  94. m_CopyDC.SelectObject( pBitmapOld );
  95. // detach and delete DDB bitmap
  96. bmp.Detach();
  97. ::DeleteObject( hBitmap );
  98. }
  99. }
  100. else
  101. {
  102. // clear bitmap (filling with black)
  103. CRect rect( 0, 0, m_MemDC.GetSize().cx, m_MemDC.GetSize().cy );
  104. m_MemDC.FillSolidRect( &rect, RGB(0,0,0) );
  105. COLORREF nOldTextColor = m_MemDC.SetTextColor( RGB(0x7F,0x7F,0x7F) );
  106. m_MemDC.DrawText( CString( _T("No captured image") ), &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
  107. m_MemDC.SetTextColor( nOldTextColor );
  108. }
  109. if( GetSafeHwnd() )
  110. {
  111. InvalidateRect( NULL );
  112. RedrawWindow();
  113. }
  114. }
  115. void CImageWnd::OnSize(UINT nType, int cx, int cy)
  116. {
  117. CWnd::OnSize(nType, cx, cy);
  118. if( cx && cy )
  119. m_MemDC.Create( cx, cy );
  120. }