Leaked source code of windows server 2003
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.

114 lines
2.6 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 2002 **/
  4. /**********************************************************************/
  5. /*
  6. MdlsDlg.cpp
  7. The class to handle modelss dialog in the snapin
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "modeless.h"
  12. #include "MdlsDlg.h"
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CModelessDlg dialog
  20. CModelessDlg::CModelessDlg()
  21. : CBaseDialog()
  22. {
  23. //{{AFX_DATA_INIT(CModelessDlg)
  24. // NOTE: the ClassWizard will add member initialization here
  25. //}}AFX_DATA_INIT
  26. m_hEventThreadKilled = ::CreateEvent(NULL, FALSE, FALSE, NULL);
  27. Assert(m_hEventThreadKilled);
  28. }
  29. CModelessDlg::~CModelessDlg()
  30. {
  31. if (m_hEventThreadKilled)
  32. ::CloseHandle(m_hEventThreadKilled);
  33. m_hEventThreadKilled = 0;
  34. }
  35. void CModelessDlg::DoDataExchange(CDataExchange* pDX)
  36. {
  37. CBaseDialog::DoDataExchange(pDX);
  38. //{{AFX_DATA_MAP(CModelessDlg)
  39. //}}AFX_DATA_MAP
  40. }
  41. BEGIN_MESSAGE_MAP(CModelessDlg, CBaseDialog)
  42. //{{AFX_MSG_MAP(CModelessDlg)
  43. //}}AFX_MSG_MAP
  44. END_MESSAGE_MAP()
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CModelessDlg message handlers
  47. void CModelessDlg::OnOK()
  48. {
  49. DestroyWindow();
  50. // Explicitly kill this thread.
  51. AfxPostQuitMessage(0);
  52. }
  53. void CModelessDlg::OnCancel()
  54. {
  55. DestroyWindow();
  56. // Explicitly kill this thread.
  57. AfxPostQuitMessage(0);
  58. }
  59. void CreateModelessDlg(CModelessDlg * pDlg,
  60. HWND hWndParent,
  61. UINT nIDD)
  62. {
  63. ModelessThread * pMT;
  64. // If the dialog is still up, don't create a new one
  65. if (pDlg->GetSafeHwnd())
  66. {
  67. ::SetActiveWindow(pDlg->GetSafeHwnd());
  68. return;
  69. }
  70. pMT = new ModelessThread(hWndParent,
  71. nIDD,
  72. pDlg->GetSignalEvent(),
  73. pDlg);
  74. pMT->CreateThread();
  75. }
  76. void WaitForModelessDlgClose(CModelessDlg *pDlg)
  77. {
  78. if (pDlg->GetSafeHwnd())
  79. {
  80. // Post a cancel to that window
  81. // Do an explicit post so that it executes on the other thread
  82. pDlg->PostMessage(WM_COMMAND, IDCANCEL, 0);
  83. // Now we need to wait for the event to be signalled so that
  84. // its memory can be cleaned up
  85. WaitForSingleObject(pDlg->GetSignalEvent(), INFINITE);
  86. }
  87. }