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