To determine whether a designer supports ActiveX controls, the host calls the designer's IDesignerToolbox::IsSupported method for every control in the host's toolbox. If the designer supports the control, it must return S_OK; otherwise, it returns S_FALSE. The host enables the items that the designer supports and disables the others.
The IsSupported method is declared as follows:
HRESULT IsSupported (IDataObject* pdo);
The host passes a pointer to an IDataObject interface. Your implementation of the IsSupported method should call IDataObject::GetData to get the data for the item in order to determine whether it supports the item. See the COM Programmer’s Reference in the Platform Software Development Kit (SDK) for details on the IDataObject interface.
The host assumes that the designer always supports its own toolbox items (those registered under the DesignerToolbox subkey), and so does not call IsSupported for those items. Furthermore, the host does not call IsSupported for designer-specific toolbox items supplied by another designer; instead, it always disables them.
Through the IsSupported method, a designer can disable specific ActiveX controls in the host's toolbox. For example, a designer might disable a control that causes problems when used in the designer, or a control that specifies a particular Required Component Category that the designer does not support.
If a designer does not support any ActiveX controls, it should implement this method and simply return S_FALSE from IsSupported. On the other hand, if the designer supports ActiveX controls but does not need to provide any of its own toolbox items, it can simply implement IDesignerToolbox and not register a DesignerToolbox subkey.
The following example shows the kinds of tasks the IsSupported routine commonly must perform. Error handling is omitted for brevity.
// Initialize storage structure before calling IDataObject::GetData().
stgm.hGlobal = NULL;
// Fill in FORMATETC to get data.
fe.cfFormat = m_cfCLSID;
fe.ptd = NULL;
fe.dwAspect = DVASPECT_CONTENT;
fe.lindex = -1;
fe.tymed = TYMED_HGLOBAL;
// Call IDataObject::GetData to get the data.
hr = pdo->GetData(&fe, &stgm);
// Lock the object in memory and retrieve the control name.
char * pszTemp = NULL;
pvGlobal = GlobalLock(stgm.hGlobal);
pszTemp = (char *)pvGlobal;
// Compare strings to make sure we support this control.
if (tcsnicmp( m_szBadCtrlClsid, pszTemp, strlen(m_szBadCtrlClsid)))
{
// It's the BadCtrl, and we don't support it.
hr = S_FALSE;
}
// Release all memory.
GlobalUnlock (stgm.hGlobal);
return (hr);