optionsHook.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include "main.h"
  2. #include "./optionsHook.h"
  3. #include "./options.h"
  4. #include "./ifc_omtoolbarconfig.h"
  5. #include "./ifc_omstatusbarconfig.h"
  6. #include <strsafe.h>
  7. OptionsConfigHook::OptionsConfigHook(HWND hTarget)
  8. : ref(1), hwnd(hTarget)
  9. {
  10. }
  11. OptionsConfigHook::~OptionsConfigHook()
  12. {
  13. }
  14. HRESULT OptionsConfigHook::CreateInstance(HWND hTarget, OptionsConfigHook **instance)
  15. {
  16. if (NULL == instance) return E_POINTER;
  17. *instance = NULL;
  18. if (NULL == hTarget || FALSE == IsWindow(hTarget))
  19. return E_INVALIDARG;
  20. *instance = new OptionsConfigHook(hTarget);
  21. if (NULL == *instance) return E_OUTOFMEMORY;
  22. return S_OK;
  23. }
  24. size_t OptionsConfigHook::AddRef()
  25. {
  26. return InterlockedIncrement((LONG*)&ref);
  27. }
  28. size_t OptionsConfigHook::Release()
  29. {
  30. if (0 == ref)
  31. return ref;
  32. LONG r = InterlockedDecrement((LONG*)&ref);
  33. if (0 == r)
  34. delete(this);
  35. return r;
  36. }
  37. int OptionsConfigHook::QueryInterface(GUID interface_guid, void **object)
  38. {
  39. if (NULL == object) return E_POINTER;
  40. else if (IsEqualIID(interface_guid, IFC_OmConfigCallback))
  41. *object = static_cast<ifc_omconfigcallback*>(this);
  42. else
  43. {
  44. *object = NULL;
  45. return E_NOINTERFACE;
  46. }
  47. if (NULL == *object)
  48. return E_UNEXPECTED;
  49. AddRef();
  50. return S_OK;
  51. }
  52. HRESULT OptionsConfigHook::ValueChanged(const GUID *configUid, UINT valueId, ULONG_PTR value)
  53. {
  54. if (NULL == configUid)
  55. return E_UNEXPECTED;
  56. BOMCONFIGCHANGED configData;
  57. configData.configUid = configUid;
  58. configData.valueId = valueId;
  59. configData.value = value;
  60. DWORD_PTR result;
  61. SendMessageTimeout(hwnd, BOM_CONFIGCHANGED, 0, (LPARAM)&configData, SMTO_ABORTIFHUNG | SMTO_NORMAL, 2000, &result);
  62. return S_OK;
  63. }
  64. #define CBCLASS OptionsConfigHook
  65. START_DISPATCH;
  66. CB(ADDREF, AddRef);
  67. CB(RELEASE, Release);
  68. CB(QUERYINTERFACE, QueryInterface);
  69. CB(API_VALUECHANGED, ValueChanged);
  70. END_DISPATCH;
  71. #undef CBCLASS