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.

118 lines
2.9 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: Background.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of Background.cpp
  13. //----------------------------------------------------------------------------
  14. // Background.cpp: implementation of the CBackground class.
  15. //
  16. //////////////////////////////////////////////////////////////////////
  17. #include "stdafx.h"
  18. #include "Background.h"
  19. #ifdef _DEBUG
  20. #undef THIS_FILE
  21. static char THIS_FILE[]=__FILE__;
  22. #define new DEBUG_NEW
  23. #endif
  24. //////////////////////////////////////////////////////////////////////
  25. // Construction/Destruction
  26. //////////////////////////////////////////////////////////////////////
  27. CBackground::CBackground()
  28. {
  29. m_Type = ET_GENERIC;
  30. m_Size = CSize( 1000, 1000 );
  31. m_VersionInfo.dwOSVersionInfoSize = sizeof( m_VersionInfo );
  32. ::GetVersionEx( &m_VersionInfo );
  33. ::InitializeCriticalSection( &m_CritSection );
  34. }
  35. CBackground::~CBackground()
  36. {
  37. ::DeleteCriticalSection( &m_CritSection );
  38. }
  39. BOOL CBackground::Load( LPCTSTR pFileName, CLgFileGroup *pFileGroup )
  40. {
  41. m_Type = ET_GENERIC;
  42. HBITMAP hBitmap = NULL;
  43. if( pFileGroup )
  44. hBitmap = (HBITMAP)pFileGroup->LoadImage( pFileName, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE );
  45. else
  46. hBitmap = (HBITMAP)::LoadImage( NULL, pFileName, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE );
  47. if( hBitmap )
  48. {
  49. if( m_MemoryDC.Create( hBitmap, FALSE ) )
  50. {
  51. m_Size = m_MemoryDC.GetSize();
  52. m_Type = ET_BITMAP;
  53. return TRUE;
  54. }
  55. }
  56. TCHAR pBuffer[MAX_PATH];
  57. BOOL bFromFileGroup = ( bFromFileGroup = pFileGroup && pFileGroup->GetTemp( pFileName, pBuffer, MAX_PATH ) );
  58. if( m_MetaFile.Load( bFromFileGroup ? pBuffer : pFileName ) )
  59. {
  60. m_Size = m_MetaFile.GetSize();
  61. m_Type = ET_METAFILE;
  62. if( bFromFileGroup )
  63. DeleteFile( pBuffer );
  64. return TRUE;
  65. }
  66. if( bFromFileGroup )
  67. DeleteFile( pBuffer );
  68. return FALSE;
  69. }
  70. BOOL CBackground::Draw( CDC *pDC, CRect *pRect )
  71. {
  72. ::EnterCriticalSection( &m_CritSection );
  73. int smode;
  74. bool bNT = ( m_VersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT );
  75. BOOL bSuccess;
  76. switch( m_Type )
  77. {
  78. case ET_BITMAP:
  79. smode = pDC->SetStretchBltMode( bNT ? HALFTONE : COLORONCOLOR );
  80. pDC->StretchBlt( pRect->left, pRect->top, pRect->Width(), pRect->Height(),
  81. &m_MemoryDC, 0, 0, m_Size.cx, m_Size.cy, SRCCOPY );
  82. pDC->SetStretchBltMode( smode );
  83. bSuccess = TRUE;
  84. break;
  85. case ET_METAFILE:
  86. pDC->PlayMetaFile( m_MetaFile, pRect );
  87. bSuccess = TRUE;
  88. break;
  89. default:
  90. pDC->FillSolidRect( pRect, RGB(0x7F,0,0) );
  91. bSuccess = FALSE;
  92. break;
  93. }
  94. ::LeaveCriticalSection( &m_CritSection );
  95. return bSuccess;
  96. }