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.

96 lines
2.5 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998
  4. *
  5. * TITLE: THRDNTFY.H
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 9/28/1999
  12. *
  13. * DESCRIPTION: Class declarations for a class that is sent from the background
  14. * thread to the UI thread.
  15. *
  16. *******************************************************************************/
  17. #ifndef __THRDNTFY_H_INCLUDED
  18. #define __THRDNTFY_H_INCLUDED
  19. #include <windows.h>
  20. #define STR_THREAD_NOTIFICATION_MESSAGE TEXT("WiaDowloadManagerThreadNotificationMessage")
  21. #define STR_WIAEVENT_NOTIFICATION_MESSAGE TEXT("WiaDowloadManagerWiaEventNotificationMessage")
  22. //
  23. // If the callee doesn't return this value, we delete the message data ourselves.
  24. //
  25. #define HANDLED_THREAD_MESSAGE 1001
  26. class CThreadNotificationMessage
  27. {
  28. private:
  29. UINT m_nMessage;
  30. public:
  31. CThreadNotificationMessage( UINT nMessage = 0 )
  32. : m_nMessage(nMessage)
  33. {
  34. }
  35. virtual ~CThreadNotificationMessage(void)
  36. {
  37. }
  38. UINT Message(void) const
  39. {
  40. return m_nMessage;
  41. }
  42. void Message( UINT nMessage )
  43. {
  44. m_nMessage = nMessage;
  45. }
  46. private:
  47. static UINT s_nThreadNotificationMessage;
  48. public:
  49. static void SendMessage( HWND hWnd, CThreadNotificationMessage *pThreadNotificationMessage )
  50. {
  51. if (pThreadNotificationMessage)
  52. {
  53. LRESULT lRes = 0;
  54. if (!s_nThreadNotificationMessage)
  55. {
  56. s_nThreadNotificationMessage = RegisterWindowMessage(STR_THREAD_NOTIFICATION_MESSAGE);
  57. }
  58. if (s_nThreadNotificationMessage)
  59. {
  60. lRes = ::SendMessage( hWnd, s_nThreadNotificationMessage, pThreadNotificationMessage->Message(), reinterpret_cast<LPARAM>(pThreadNotificationMessage) );
  61. }
  62. if (HANDLED_THREAD_MESSAGE != lRes)
  63. {
  64. delete pThreadNotificationMessage;
  65. }
  66. }
  67. }
  68. };
  69. // Some handy message crackers. Made to resemble the ones defined in simcrack.h
  70. #define WTM_BEGIN_THREAD_NOTIFY_MESSAGE_HANDLERS()\
  71. CThreadNotificationMessage *_pThreadNotificationMessage = reinterpret_cast<CThreadNotificationMessage*>(lParam);\
  72. if (_pThreadNotificationMessage)\
  73. {
  74. #define WTM_HANDLE_NOTIFY_MESSAGE( _msg, _handler )\
  75. if (_pThreadNotificationMessage->Message() == (_msg))\
  76. {\
  77. _handler( _msg, _pThreadNotificationMessage );\
  78. }
  79. #define WTM_END_THREAD_NOTIFY_MESSAGE_HANDLERS()\
  80. }\
  81. return 0
  82. #endif //__THRDNTFY_H_INCLUDED