Source code of Windows XP (NT5)
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.

130 lines
2.7 KiB

  1. ///////////////////////////////////////////////////////////
  2. //
  3. //
  4. // lockout.cpp - Implementation file for CLockOut
  5. //
  6. //
  7. #include "header.h"
  8. // Our header file
  9. #include "lockout.h"
  10. ///////////////////////////////////////////////////////////
  11. //
  12. // Construction
  13. //
  14. CLockOut::CLockOut()
  15. :m_bLocked(false)
  16. {
  17. }
  18. ///////////////////////////////////////////////////////////
  19. //
  20. // Destructor
  21. //
  22. CLockOut::~CLockOut()
  23. {
  24. Unlock() ;
  25. }
  26. ///////////////////////////////////////////////////////////
  27. //
  28. // Main function.
  29. //
  30. void
  31. CLockOut::LockOut(HWND hwndOwner)
  32. {
  33. if (!m_bLocked)
  34. {
  35. // Determine if we are parented by the desktop?
  36. // Initialize our varaibles.
  37. m_CountDisabled = 0 ;
  38. GetWindowThreadProcessId(hwndOwner, &m_ProcessId) ;
  39. // Enumerate the windows
  40. BOOL b = EnumWindows(s_EnumWindowProc, reinterpret_cast<LPARAM>(this)) ;
  41. }
  42. }
  43. ///////////////////////////////////////////////////////////
  44. //
  45. // Main function.
  46. //
  47. void
  48. CLockOut::Unlock()
  49. {
  50. if (m_bLocked)
  51. {
  52. // We only set m_bLocked if m_CountDisabled is incremented.
  53. ASSERT(m_CountDisabled > 0) ;
  54. for (int i = 0 ; i < m_CountDisabled ; i++)
  55. {
  56. if (::IsValidWindow(m_HwndDisabled[i]))
  57. {
  58. EnableWindow(m_HwndDisabled[i], TRUE);
  59. }
  60. }
  61. m_bLocked = false ;
  62. m_CountDisabled = 0 ;
  63. }
  64. }
  65. ///////////////////////////////////////////////////////////
  66. //
  67. // Callbacks
  68. //
  69. ///////////////////////////////////////////////////////////
  70. //
  71. // EnumWindowProc
  72. //
  73. BOOL
  74. CLockOut::EnumWindowProc(HWND hwnd)
  75. {
  76. ASSERT(IsValidWindow(hwnd)) ;// Window should be guarenting this.
  77. // Only need to disable if window is enabled.
  78. if (IsWindowEnabled(hwnd))
  79. {
  80. // Make sure window is in the same process.
  81. DWORD procid = NULL;
  82. GetWindowThreadProcessId(hwnd, &procid) ;
  83. if (procid == m_ProcessId)
  84. {
  85. //Disable the window.
  86. ASSERT(m_CountDisabled < c_MaxWindows) ; //TODO Make the array grow
  87. if (m_CountDisabled >= c_MaxWindows)
  88. {
  89. // Don't crash, just quit.
  90. return FALSE ;
  91. }
  92. // Add the window to the array.
  93. m_HwndDisabled[m_CountDisabled++] = hwnd ;
  94. // Disable the window
  95. EnableWindow(hwnd, FALSE) ;
  96. m_bLocked = TRUE ;
  97. }
  98. }
  99. return TRUE ;
  100. }
  101. ///////////////////////////////////////////////////////////
  102. //
  103. // Static callback
  104. //
  105. BOOL CALLBACK
  106. CLockOut::s_EnumWindowProc(HWND hwnd, LPARAM lparam)
  107. {
  108. CLockOut* p = reinterpret_cast<CLockOut*>(lparam) ;
  109. return p->EnumWindowProc(hwnd) ;
  110. }