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.

127 lines
2.5 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. PushDlgButton.h
  5. Abstract:
  6. Author:
  7. Hakki T. Bostanci (hakkib) 06-Apr-2000
  8. Revision History:
  9. --*/
  10. #ifndef _PUSHDLGBUTTON_H_
  11. #define _PUSHDLGBUTTON_H_
  12. //////////////////////////////////////////////////////////////////////////
  13. //
  14. //
  15. //
  16. class CPushDlgButton
  17. {
  18. public:
  19. CPushDlgButton(
  20. DWORD dwWatchThread,
  21. PCTSTR pszTitle,
  22. int nButtonId
  23. ) :
  24. m_dwWatchThread(dwWatchThread),
  25. m_pszTitle(pszTitle),
  26. m_nButtonId(nButtonId),
  27. m_StopEvent(TRUE, FALSE),
  28. m_Thread(ThreadProc, this),
  29. m_nMatchingWindows(0),
  30. m_nMatchingButtons(0),
  31. m_nListItems(0)
  32. {
  33. }
  34. ~CPushDlgButton()
  35. {
  36. m_StopEvent.Set();
  37. m_Thread.WaitForSingleObject();
  38. }
  39. private:
  40. static DWORD WINAPI ThreadProc(PVOID pParameter)
  41. {
  42. CPushDlgButton *that = (CPushDlgButton *) pParameter;
  43. try
  44. {
  45. while (that->m_StopEvent.WaitForSingleObject(1000) == WAIT_TIMEOUT)
  46. {
  47. EnumThreadWindows(that->m_dwWatchThread, EnumThreadWndProc, (LPARAM) that);
  48. }
  49. }
  50. catch (const CError &)
  51. {
  52. }
  53. return TRUE;
  54. }
  55. static BOOL CALLBACK EnumThreadWndProc(HWND hWnd, LPARAM lParam)
  56. {
  57. CPushDlgButton *that = (CPushDlgButton *) lParam;
  58. if (_tcscmp(CSafeWindowText(hWnd), that->m_pszTitle) == 0)
  59. {
  60. ++that->m_nMatchingWindows;
  61. EnumChildWindows(hWnd, EnumChildProc, lParam);
  62. if (that->m_nMatchingButtons)
  63. {
  64. PostMessage(hWnd, WM_COMMAND, that->m_nButtonId, 0);
  65. }
  66. while (IsWindow(hWnd))
  67. {
  68. Sleep(100);
  69. }
  70. }
  71. return TRUE;
  72. }
  73. static BOOL CALLBACK EnumChildProc(HWND hWnd, LPARAM lParam)
  74. {
  75. CPushDlgButton *that = (CPushDlgButton *) lParam;
  76. if (GetDlgCtrlID(hWnd) == that->m_nButtonId)
  77. {
  78. ++that->m_nMatchingButtons;
  79. }
  80. else if (_tcscmp(CClassName(hWnd), _T("SysListView32")) == 0)
  81. {
  82. that->m_nListItems = ListView_GetItemCount(hWnd);
  83. }
  84. return TRUE;
  85. }
  86. public:
  87. int m_nMatchingWindows;
  88. int m_nMatchingButtons;
  89. int m_nListItems;
  90. private:
  91. DWORD m_dwWatchThread;
  92. PCTSTR m_pszTitle;
  93. int m_nButtonId;
  94. Event m_StopEvent;
  95. CThread m_Thread;
  96. };
  97. #endif //_PUSHDLGBUTTON_H_