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.

186 lines
3.8 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 19/04/2000
  5. // Last modification: 08/10/2003
  6. // Project Intruder Position Indicator
  7. // SUBSYSTEM: Dialog
  8. // FILE: Dialog.cpp
  9. // AUTHOR: Chizhevskiy Sergey
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of class CDialog
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "..\LgLib\Version.h"
  16. #include "Dialog.h"
  17. CDialog::CDialog(LPCTSTR lpTemplateName )
  18. {
  19. m_hWnd = NULL;
  20. m_hParent = NULL;
  21. m_hThread = NULL;
  22. m_bModal = NULL;
  23. m_dwThreadId = 0UL;
  24. m_hInstance = NULL;
  25. m_pTemplateName = lpTemplateName;
  26. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CDialog::CDialog" );
  27. }
  28. CDialog::~CDialog()
  29. {
  30. Destroy();
  31. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CDialog::~CDialog" );
  32. }
  33. BOOL CDialog::DoModal(HWND hParent, BOOL bThread)
  34. {
  35. if(m_hThread)
  36. {
  37. if(::WaitForSingleObject(m_hThread, 0) == WAIT_OBJECT_0)
  38. {
  39. ::CloseHandle(m_hThread);
  40. m_hThread = NULL;
  41. }
  42. else
  43. return FALSE;
  44. }
  45. m_hInstance = (HINSTANCE)::GetWindowLong(m_hParent = hParent, GWL_HINSTANCE);
  46. if(bThread)
  47. {
  48. m_bModal = TRUE;
  49. m_hParent = hParent;
  50. m_hThread = ::CreateThread(NULL, 0UL, ThreadProcDialog, (LPVOID)this, 0UL, &m_dwThreadId);
  51. return TRUE;
  52. }
  53. else
  54. {
  55. m_bModal = TRUE;
  56. m_hParent = hParent;
  57. return ::DialogBoxParam(m_hInstance, m_pTemplateName, m_hParent,
  58. DialogProcDialog, (LPARAM)this );
  59. }
  60. return TRUE;
  61. }
  62. BOOL CDialog::Create(HWND hParent, BOOL bThread)
  63. {
  64. if(m_hThread)
  65. {
  66. if(::WaitForSingleObject(m_hThread, 0) == WAIT_OBJECT_0)
  67. {
  68. ::CloseHandle(m_hThread);
  69. m_hThread = NULL;
  70. }
  71. else
  72. return FALSE;
  73. }
  74. m_hInstance = (HINSTANCE)::GetWindowLong(m_hParent = hParent, GWL_HINSTANCE);
  75. if(bThread )
  76. {
  77. m_bModal = FALSE;
  78. m_hParent = hParent;
  79. m_hThread = ::CreateThread(NULL, 0UL, ThreadProcDialog, (LPVOID)this, 0UL, &m_dwThreadId);
  80. }
  81. else
  82. if(m_hWnd = ::CreateDialogParam( m_hInstance, m_pTemplateName,
  83. m_hParent, DialogProcDialog, (LPARAM)this ) )
  84. {
  85. ::ShowWindow(m_hWnd, SW_SHOW);
  86. ::UpdateWindow(m_hWnd);
  87. }
  88. return TRUE;
  89. }
  90. void CDialog::Destroy()
  91. {
  92. if(m_hWnd)
  93. {
  94. if(m_bModal)
  95. ::EndDialog(m_hWnd, 0);
  96. else
  97. ::DestroyWindow(m_hWnd);
  98. m_hWnd = NULL;
  99. }
  100. if(m_hThread)
  101. {
  102. if(::GetCurrentThreadId() == m_dwThreadId)
  103. ::PostQuitMessage(0);
  104. else
  105. {
  106. ::PostThreadMessage(m_dwThreadId, WM_QUIT, 0, 0);
  107. ::WaitForSingleObject(m_hThread, INFINITE);
  108. ::CloseHandle(m_hThread);
  109. m_hThread = NULL;
  110. m_dwThreadId = 0UL;
  111. m_hInstance = NULL;
  112. m_hParent = NULL;
  113. }
  114. }
  115. }
  116. DWORD CDialog::ThreadProc()
  117. {
  118. if(m_bModal )
  119. {
  120. return ::DialogBoxParam( m_hInstance, m_pTemplateName, m_hParent,
  121. DialogProcDialog, (LPARAM)this );
  122. }
  123. else
  124. {
  125. if(m_hWnd = ::CreateDialogParam( m_hInstance, m_pTemplateName,
  126. m_hParent, DialogProcDialog, (LPARAM)this))
  127. {
  128. ::ShowWindow(m_hWnd, SW_SHOW);
  129. ::UpdateWindow(m_hWnd);
  130. MSG msg;
  131. while(::GetMessage(&msg, 0, 0, 0))
  132. {
  133. ::TranslateMessage(&msg);
  134. ::DispatchMessage(&msg);
  135. }
  136. return 0UL;
  137. }
  138. }
  139. return 0UL;
  140. }
  141. static BOOL CALLBACK DialogProcDialog(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  142. {
  143. if(uMsg == WM_INITDIALOG)
  144. {
  145. CDialog *self = (CDialog*)lParam;
  146. self->m_hWnd = hWnd;
  147. ::SetWindowLong(hWnd, GWL_USERDATA, (DWORD)lParam);
  148. return self->DialogProc(hWnd, uMsg, wParam, lParam);;
  149. }
  150. CDialog *self = (CDialog*)::GetWindowLong(hWnd, GWL_USERDATA);
  151. if(self)
  152. return self->DialogProc(hWnd, uMsg, wParam, lParam);
  153. else
  154. return FALSE;
  155. }