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.

137 lines
3.9 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998
  4. *
  5. * TITLE: GWIAEVNT.H
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 12/29/1999
  12. *
  13. * DESCRIPTION: Generic reusable WIA event handler that posts the specified
  14. * message to the specified window.
  15. *
  16. * The message will be sent with the following arguments:
  17. *
  18. *
  19. * WPARAM = NULL
  20. * LPARAM = CGenericWiaEventHandler::CEventMessage *pEventMessage
  21. *
  22. * pEventMessage MUST be freed in the message handler using delete
  23. *
  24. * pEventMessage is allocated using an overloaded new operator, to ensure that
  25. * the same allocator and de-allocator are used.
  26. *
  27. *******************************************************************************/
  28. #ifndef __GWIAEVNT_H_INCLUDED
  29. #define __GWIAEVNT_H_INCLUDED
  30. #include <windows.h>
  31. #include "wia.h"
  32. #include "simstr.h"
  33. #include "wiadebug.h"
  34. #include "modlock.h"
  35. //
  36. // If the callee doesn't return this value, we delete the message data ourselves.
  37. //
  38. #define HANDLED_EVENT_MESSAGE 1002
  39. class CGenericWiaEventHandler : public IWiaEventCallback
  40. {
  41. public:
  42. class CEventMessage
  43. {
  44. private:
  45. GUID m_guidEventId;
  46. CSimpleStringWide m_wstrEventDescription;
  47. CSimpleStringWide m_wstrDeviceId;
  48. CSimpleStringWide m_wstrDeviceDescription;
  49. DWORD m_dwDeviceType;
  50. CSimpleStringWide m_wstrFullItemName;
  51. private:
  52. // No implementation
  53. CEventMessage(void);
  54. CEventMessage( const CEventMessage & );
  55. CEventMessage &operator=( const CEventMessage & );
  56. public:
  57. CEventMessage( const GUID &guidEventId, LPCWSTR pwszEventDescription, LPCWSTR pwszDeviceId, LPCWSTR pwszDeviceDescription, DWORD dwDeviceType, LPCWSTR pwszFullItemName )
  58. : m_guidEventId(guidEventId),
  59. m_wstrEventDescription(pwszEventDescription),
  60. m_wstrDeviceId(pwszDeviceId),
  61. m_wstrDeviceDescription(pwszDeviceDescription),
  62. m_dwDeviceType(dwDeviceType),
  63. m_wstrFullItemName(pwszFullItemName)
  64. {
  65. }
  66. GUID EventId(void) const
  67. {
  68. return m_guidEventId;
  69. }
  70. CSimpleStringWide EventDescription(void) const
  71. {
  72. return m_wstrEventDescription;
  73. }
  74. CSimpleStringWide DeviceId(void) const
  75. {
  76. return m_wstrDeviceId;
  77. }
  78. CSimpleStringWide DeviceDescription(void) const
  79. {
  80. return m_wstrDeviceDescription;
  81. }
  82. DWORD DeviceType(void) const
  83. {
  84. return m_dwDeviceType;
  85. }
  86. CSimpleStringWide FullItemName(void) const
  87. {
  88. return m_wstrFullItemName;
  89. }
  90. void *operator new( size_t nSize )
  91. {
  92. if (nSize)
  93. {
  94. return reinterpret_cast<void*>(LocalAlloc(LPTR,nSize));
  95. }
  96. return NULL;
  97. }
  98. void operator delete( void *pVoid )
  99. {
  100. if (pVoid)
  101. {
  102. LocalFree( pVoid );
  103. }
  104. }
  105. };
  106. private:
  107. HWND m_hWnd;
  108. UINT m_nWiaEventMessage;
  109. LONG m_cRef;
  110. public:
  111. CGenericWiaEventHandler(void);
  112. ~CGenericWiaEventHandler(void) {}
  113. STDMETHODIMP Initialize( HWND hWnd, UINT nWiaEventMessage );
  114. // IUnknown
  115. STDMETHODIMP QueryInterface( REFIID riid, LPVOID *ppvObject );
  116. STDMETHODIMP_(ULONG) AddRef(void);
  117. STDMETHODIMP_(ULONG) Release(void);
  118. //IWiaEventCallback
  119. STDMETHODIMP ImageEventCallback( const GUID *pEventGUID, BSTR bstrEventDescription, BSTR bstrDeviceID, BSTR bstrDeviceDescription, DWORD dwDeviceType, BSTR bstrFullItemName, ULONG *pulEventType, ULONG ulReserved );
  120. public:
  121. static HRESULT RegisterForWiaEvent( LPCWSTR pwszDeviceId, const GUID &guidEvent, IUnknown **ppUnknown, HWND hWnd, UINT nMsg );
  122. };
  123. #endif //__GWIAEVNT_H_INCLUDED