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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
#include "main.h"
#include "./browserWndEnum.h"
#include "./browserWndRecord.h"
#include "./browserView.h"
#include "./browserPopup.h"
#include "./ifc_omservice.h"
OmBrowserWndEnumerator::OmBrowserWndEnumerator(const GUID *windowTypeFilter, const UINT *serviceIdFilter, OmBrowserWndRecord * const *windowList, size_t windowListSize)
: ref(1), index(0), list(NULL), size(0), filterId(FALSE), filterType(FALSE)
{
if (NULL != serviceIdFilter)
{
serviceId = *serviceIdFilter;
filterId = TRUE;
}
else
serviceId = 0;
if (NULL != windowTypeFilter)
{
windowType = *windowTypeFilter;
filterType = TRUE;
}
else
windowType = GUID_NULL;
if (NULL != windowList && 0 != windowListSize)
{
list = (OmBrowserWndRecord**)calloc(windowListSize, sizeof(OmBrowserWndRecord*));
if (NULL != list)
{
for (size_t i = 0; i < windowListSize; i++)
{
list[i] = windowList[i];
list[i]->AddRef();
}
size = windowListSize;
}
}
}
OmBrowserWndEnumerator::~OmBrowserWndEnumerator()
{
if (NULL != list)
{
for (size_t i = 0; i < size; i++)
{
list[i]->Release();
}
free(list);
}
}
HRESULT OmBrowserWndEnumerator::CreateInstance(const GUID *windowTypeFilter, const UINT *serviceIdFilter, OmBrowserWndRecord * const* windowList, size_t windowListSize, OmBrowserWndEnumerator **instance)
{
if (NULL == instance) return E_POINTER;
*instance = new OmBrowserWndEnumerator(windowTypeFilter, serviceIdFilter, windowList, windowListSize);
if (NULL == *instance) return E_OUTOFMEMORY;
return S_OK;
}
size_t OmBrowserWndEnumerator::AddRef()
{
return InterlockedIncrement((LONG*)&ref);
}
size_t OmBrowserWndEnumerator::Release()
{
if (0 == ref)
return ref;
LONG r = InterlockedDecrement((LONG*)&ref);
if (0 == r)
delete(this);
return r;
}
int OmBrowserWndEnumerator::QueryInterface(GUID interface_guid, void **object)
{
if (NULL == object) return E_POINTER;
if (IsEqualIID(interface_guid, IFC_OmBrowserWindowEnumerator))
*object = static_cast<ifc_ombrowserwndenum*>(this);
else
{
*object = NULL;
return E_NOINTERFACE;
}
if (NULL == *object)
return E_UNEXPECTED;
AddRef();
return S_OK;
}
HRESULT OmBrowserWndEnumerator::Next(ULONG listSize, HWND *elementList, ULONG *elementCount)
{
if (NULL == elementList || 0 == listSize) return E_INVALIDARG;
if (index >= size)
{
if (NULL != elementCount) *elementCount = 0;
return S_FALSE;
}
ULONG count = 0;
for (;index < size && count < listSize; index++)
{
OmBrowserWndRecord *r = list[index];
if (FALSE != filterType)
{
if (S_OK != r->IsEqualType(&windowType))
continue;
}
if (FALSE != filterId)
{
BOOL passOk = FALSE;
if (S_OK == r->IsEqualType(&WTID_BrowserView) ||
S_OK == r->IsEqualType(&WTID_BrowserPopup))
{
ifc_omservice *service;
if (FALSE != SendMessage(r->GetHwnd(), NBCM_GETSERVICE, 0, (LPARAM)&service) && NULL != service)
{
if (serviceId == service->GetId())
passOk = TRUE;
service->Release();
}
}
if (FALSE == passOk)
continue;
}
elementList[count] = r->GetHwnd();
count++;
}
if (NULL != elementCount) *elementCount = count;
return (count == listSize) ? S_OK : S_FALSE;
}
HRESULT OmBrowserWndEnumerator::Reset(void)
{
index = 0;
return S_OK;
}
HRESULT OmBrowserWndEnumerator::Skip(ULONG elementCount)
{
index += elementCount;
if (index >= size)
{
index = (size - 1);
return S_FALSE;
}
return S_OK;
}
#define CBCLASS OmBrowserWndEnumerator
START_DISPATCH;
CB(ADDREF, AddRef)
CB(RELEASE, Release)
CB(QUERYINTERFACE, QueryInterface)
CB(API_NEXT, Next)
CB(API_RESET, Reset)
CB(API_SKIP, Skip)
END_DISPATCH;
#undef CBCLASS
|