Selects a single object from a group of objects.
HRESULT SelectObjects(
ULONG cSelect,
IUnknown **apUnkSelect,
DWORD dwFlags
);
Parameters
cSelect
[in] Index into the array of objects returned by ISelectionContainer::GetObjects.
apUnkSelect
[in] Pointer to the selected object.
dwFlags
[in] Flags modifying the selection. Callers specify SELOBJS_ACTIVATEWINDOW to activate the window that displays the selected objects.
Return Values
The return value obtained from HRESULT is one of the following:
Return Value | Meaning |
S_OK | Success. |
E_INVALIDARG | One or more of the arguments is invalid. |
Comments
The ActiveX designer implements this method.
The GetObjects method returns either all selectable objects or all selected objects, depending on the flags passed. In the SelectObjects method, the designer selects one of these objects, typically as a result of user interaction.
Because the returned objects support IDispatch, the host can obtain information directly from them. For example, to get the name of an object, the host can call IDispatch::Invoke (or ITypeInfo::Invoke) with a predefined DISPID that signifies the name. The predeclared DISPIDs are negative to ensure that they don't conflict with user-defined identifiers. The following table describes some of this information and how it is obtained. These DISPIDs are defined in the header file Typelib2.h.
Item | How It Is Obtained |
Object name | DISPID_NAME |
Object index | DISPID_OBJECT |
Object type | IProvideClassInfo::QueryInterface |
Example
The following example implements SelectObjects, using the array returned by GetObjects.
STDMETHODIMP CMySelectionContainer::SelectObjects
(
ULONG cSelect,
IUnknown **apUnkSelect,
DWORD dwFlags
)
{
// Select the first object given.
int index = -1;
if (cSelect > 0) {
// See what the selected object is. Default is the main
// object.
for (int i = 0; i < MAXOBJECTS; i++) {
if (m_state.rgObjects[i].bHaveIt &&
apUnkSelect[0] == m_state.rgObjects[i].pObject) {
index = i;
break;
}
}
MaybeSelectionChanged(index, FALSE);
}
return S_OK;
}
Although calling MaybeSelectionChanged results in a call to the host's ITrackSelection mechanism, it is necessary because the host has to display the main control window differently each time the selected object changes.