ISelectionContainer::SelectObjects

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. Set to 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. The SelectObjects method allows any of these objects to be selected.

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 table that follows 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

The name of the object.

DISPID_NAME

The index of the object.

DISPID_OBJECT

The type of the object.

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 thing 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's necessary because the host has to display the main control window differently (with stretch bars) if its selection is selected, which is always the case.