How Do I Enumerate the Child Items of the Snap-In Object?

To properly display the contents of a snap-in object, you need to enumerate the child items of the object, if they exist. The best place for this modification is in the Notify method of the snap-in data class (in this discussion, CSnapNameData).

Note   The snap-in data class is derived from CSnapInItemImpl.

By default, the ATL Object Wizard creates a handler for this notification. In this handler, you need to modify the existing switch statement to handle the MMCN_EXPAND and MMCN_SHOW notifications.

Handling the MMCN_EXPAND Notification

The MMCN_EXPAND notification is sent when the snap-in object folder needs to be expanded or contracted. In this case, you need only enumerate the scope pane items. This enumeration is done in the case statement for the MMCN_EXPAND notification.

To insert the scope pane items, first retrieve the IConsoleNameSpace interface for the snap-in object, and then call the InsertItem method. The following code demonstrates retrieval of the necessary interfaces:

CComQIPtr<IConsoleNameSpace,
&IID_IConsoleNameSpace> spConsoleNameSpace(pConsole);
// TODO : Enumerate scope pane items with a user-defined function

Handling the MMCN_SHOW Notification

The MMCN_SHOW notification is sent when an item is selected or de-selected for the first time. This enumeration is done in the case statement for the MMCN_SHOW notification. Unlike the MMCN_EXPAND notification, you must enumerate both the result pane items and scope pane items.

First, enumerate the scope items by retrieving the IConsoleNameSpace interface for the snap-in object, and then calling the InsertItem method. After you have enumerated the scope pane items, do the same for the result pane items by retrieving the IResultData interface and making a call to InsertItem.

CComQIPtr<IConsoleNameSpace,
&IID_IConsoleNameSpace> spConsoleNameSpace(pConsole);
// TODO : Enumerate scope pane items with a user-defined function
CComQIPtr<IResultData, &IID_IResultData> spResultData(pConsole);
// TODO : Enumerate the result pane items with a user-defined function