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.

267 lines
5.1 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: LgWnd.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of LgWnd.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "..\LgLib\Version.h"
  16. #include "LgWnd.h"
  17. CLgWnd::CLgWnd()
  18. {
  19. m_hWnd = NULL;
  20. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgWnd::CLgWnd" );
  21. }
  22. CLgWnd::~CLgWnd()
  23. {
  24. DestroyWindow();
  25. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgWnd::~CLgWnd" );
  26. }
  27. BOOL CLgWnd::Create( HWND hParentWnd, INT x, INT y, INT cx, INT cy )
  28. {
  29. DestroyWindow();
  30. // register wnd class
  31. WNDCLASS wc;
  32. wc.cbClsExtra = 0;
  33. wc.cbWndExtra = 0;
  34. wc.hbrBackground = NULL;
  35. wc.hCursor = ::LoadCursor( NULL, IDC_ARROW );
  36. wc.hIcon = NULL;
  37. wc.hInstance = (HINSTANCE)::GetWindowLong( hParentWnd, GWL_HINSTANCE );
  38. wc.lpfnWndProc = WindowProc_;
  39. wc.lpszClassName = "LgsRadarWndClass";
  40. wc.lpszMenuName = NULL;
  41. wc.style = CS_HREDRAW | CS_VREDRAW;
  42. if( !::RegisterClass( &wc ) )
  43. return FALSE;
  44. // create window
  45. m_hWnd = ::CreateWindow( wc.lpszClassName, NULL, WS_CHILD, x, y, cx, cy, hParentWnd, NULL, wc.hInstance, this );
  46. if( !m_hWnd )
  47. return FALSE;
  48. return TRUE;
  49. }
  50. BOOL CLgWnd::DestroyWindow()
  51. {
  52. if( !m_hWnd )
  53. return FALSE;
  54. return ::DestroyWindow( m_hWnd );
  55. }
  56. LRESULT CLgWnd::WindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  57. {
  58. switch( uMsg )
  59. {
  60. case WM_DESTROY:
  61. OnDestroy();
  62. break;
  63. }
  64. return ::DefWindowProc( hWnd, uMsg, wParam, lParam );
  65. }
  66. LRESULT CLgWnd::WindowProc_( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  67. {
  68. CLgWnd* pLgsRadar = (CLgWnd*)::GetWindowLong( hWnd, GWL_USERDATA );
  69. if( pLgsRadar )
  70. return pLgsRadar->WindowProc( hWnd, uMsg, wParam, lParam );
  71. if( uMsg == WM_CREATE )
  72. {
  73. CLgWnd *pLgsRadar = (CLgWnd*)((LPCREATESTRUCT)lParam)->lpCreateParams;
  74. if( pLgsRadar )
  75. {
  76. ::SetWindowLong( hWnd, GWL_USERDATA, (LONG)pLgsRadar );
  77. return pLgsRadar->WindowProc( hWnd, uMsg, wParam, lParam );
  78. }
  79. }
  80. return ::DefWindowProc( hWnd, uMsg, wParam, lParam );
  81. }
  82. void CLgWnd::OnDestroy()
  83. {
  84. m_hWnd = NULL;
  85. }
  86. CLgDC* CLgWnd::GetDC()
  87. {
  88. if( m_DC.GetSafeHdc() )
  89. return NULL;
  90. HDC hDC = ::GetDC( m_hWnd );
  91. if( !m_DC.Attach( hDC ) )
  92. {
  93. ::ReleaseDC( m_hWnd, hDC );
  94. return FALSE;
  95. }
  96. return &m_DC;
  97. }
  98. BOOL CLgWnd::ReleaseDC( CLgDC* pDC )
  99. {
  100. if( pDC != &m_DC )
  101. return FALSE;
  102. HDC hDC = m_DC.Detach();
  103. if( !hDC )
  104. return FALSE;
  105. return ::ReleaseDC( m_hWnd, hDC );
  106. }
  107. //------------------------------- CDC LITE ------------------------------------
  108. CLgDC::CLgDC()
  109. {
  110. m_hDC = NULL;
  111. m_nCreationMode = LGDCCM_NONE;
  112. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgDC::CLgDC" );
  113. }
  114. CLgDC::~CLgDC()
  115. {
  116. switch( m_nCreationMode )
  117. {
  118. case LGDCCM_NONE:
  119. break;
  120. case LGDCCM_ATTACH:
  121. Detach();
  122. break;
  123. case LGDCCM_CREATECOMPATIBLEDC:
  124. DeleteDC();
  125. break;
  126. }
  127. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgDC::~CLgDC" );
  128. }
  129. BOOL CLgDC::Attach( HDC hDC )
  130. {
  131. if( m_hDC )
  132. return FALSE;
  133. m_hDC = hDC;
  134. m_nCreationMode = LGDCCM_ATTACH;
  135. return TRUE;
  136. }
  137. HDC CLgDC::Detach()
  138. {
  139. if( m_nCreationMode != LGDCCM_ATTACH )
  140. return NULL;
  141. HDC hDC = m_hDC;
  142. m_hDC = NULL;
  143. m_nCreationMode = LGDCCM_NONE;
  144. return hDC;
  145. }
  146. BOOL CLgDC::CreateCompatibleDC( CLgDC* pDC )
  147. {
  148. if( m_hDC )
  149. return FALSE;
  150. m_hDC = ::CreateCompatibleDC( pDC->m_hDC );
  151. if( !m_hDC )
  152. return FALSE;
  153. m_nCreationMode = LGDCCM_CREATECOMPATIBLEDC;
  154. return TRUE;
  155. }
  156. BOOL CLgDC::DeleteDC()
  157. {
  158. if( m_nCreationMode != LGDCCM_CREATECOMPATIBLEDC )
  159. return FALSE;
  160. ::DeleteDC( m_hDC );
  161. m_hDC = NULL;
  162. m_nCreationMode = LGDCCM_NONE;
  163. return TRUE;
  164. }
  165. HDC CLgDC::GetSafeHdc()
  166. {
  167. return m_hDC;
  168. }
  169. CLgClientDC::CLgClientDC( CLgWnd* pWnd )
  170. {
  171. HDC hDC = ::GetDC( pWnd->GetSafeHwnd() );
  172. if( hDC )
  173. {
  174. if( Attach( hDC ) )
  175. m_pWnd = pWnd;
  176. else
  177. {
  178. ::ReleaseDC( pWnd->GetSafeHwnd(), hDC );
  179. m_pWnd = NULL;
  180. }
  181. }
  182. else
  183. m_pWnd = NULL;
  184. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgClientDC::CLgClientDC" );
  185. }
  186. CLgClientDC::~CLgClientDC()
  187. {
  188. if( m_pWnd )
  189. {
  190. ::ReleaseDC( m_pWnd->GetSafeHwnd(), Detach() );
  191. }
  192. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgClientDC::~CLgClientDC" );
  193. }
  194. CLgPaintDC::CLgPaintDC( CLgWnd* pWnd )
  195. {
  196. HDC hDC = ::BeginPaint( pWnd->GetSafeHwnd(), &m_PaintStruct );
  197. if( hDC )
  198. {
  199. if( Attach( hDC ) )
  200. m_pWnd = pWnd;
  201. else
  202. {
  203. ::EndPaint( pWnd->GetSafeHwnd(), &m_PaintStruct );
  204. m_pWnd = NULL;
  205. }
  206. }
  207. else
  208. m_pWnd = NULL;
  209. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgPaintDC::CLgPaintDC" );
  210. }
  211. CLgPaintDC::~CLgPaintDC()
  212. {
  213. if( m_pWnd )
  214. {
  215. ::EndPaint( m_pWnd->GetSafeHwnd(), &m_PaintStruct );
  216. }
  217. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgPaintDC::~CLgPaintDC" );
  218. }