Indicates that the user has picked an item from the toolbox to place on the designer.
HRESULT ItemPicked(
IDataObject *pdo
);
Parameter
pdo
[in] Pointer to a toolbox data object.
Return Values
The designer returns the following value:
Return Value | Meaning |
S_OK | The designer has added the item. |
Comments
When the user double-clicks a toolbox item to create an instance of it on the designer, the host calls the designer's ItemPicked method, passing an IDataObject pointer to the item. The designer returns S_OK to indicate that it has added the item.
Designers must call methods of the IDataObject interface to parse the returned data object. (See the COM Programmer’s Reference in the Platform Software Development Kit (SDK) for more information on this interface.) The format of the object depends on the type of the corresponding toolbox object.
For toolbox items supplied by a designer, the format is CF_DESIGNERTOOLBOXITEM, which has the clipboard format name "DesignerToolboxItem". The data consists of a zero-terminated ANSI string (stored as TYMED_GLOBAL) in the following form:
Designer-class-name.toolbox-item-id
For example, MyClass.1 represents the toolbox item in the MyClass designer with an identifier of 1. Toolbox item numbers begin with zero.
Example
The following example creates a new object on the screen at the point where the user clicked. First, the designer gets the coordinates of its client area (OurRect). Then it determines the center point and calls the local routine CreateNewObject to create the requested object at the computed position.
STDMETHODIMP MyDesigner::ItemPicked(IDataObject* pdo)
{
HRESULT hr = S_OK;
POINT ptAt;
RECT rcOurRect;
// Compute position, relative to our rectangle.
GetClientRect(m_hwnd, &rcOurRect);
// Set position - center object within our rectangle.
ptAt.x = rcOurRect.left +((rcOurRect.right - rcOurRect.left) / 2);
ptAt.y = rcOurRect.top + ((rcOurRect.bottom - rcOurRect.top) / 2);
// Create the object at its default size.
hr = CreateNewObject(pdo, &ptAt, NULL);
return hr;
}