Displaying the Adapters

The following code works with Forefront TMG Management to display the adapters. This code is written by the Active Template Library (ATL) object wizard and is used at the start of development.

To use the ATL object wizard

  1. Open Microsoft Visual C++.
  2. Click New ATL Object on the Insert menu.
  3. Select MMC Snapin from the Objects list.
  4. Click Next.
  5. Type Adapters in the ShortName edit box on the Names tab.
  6. Select the Extension and IExtendcontextmenu check boxes on the MMC Snapin tab. (Be sure to leave IComponentData, IComponent, and ISnapInAbout selected.).
  7. Clear the Support Persistence check box.
  8. On the MMC Snapin tab, in the Extends Node box, select the node that you want to extend (Servers).

The wizard produces the following code.

HRESULT CAdaptersData::Notify( MMC_NOTIFY_TYPE event,
	long arg,
	long param,
	IComponentData* pComponentData,
	IComponent* pComponent,
	DATA_OBJECT_TYPES type)
{
	// Add code to handle the different notifications.
	// Handle MMCN_SHOW and MMCN_EXPAND to enumerate child items.
	// In response to MMCN_SHOW you must enumerate both the scope
	// and result-pane items.
	// For MMCN_EXPAND you only need to enumerate the scope items
	// Use IConsoleNameSpace::InsertItem to insert scope pane items
	// Use IResultData::InsertItem to insert result pane item.
	HRESULT hr = E_NOTIMPL;
 
 
	_ASSERTE(pComponentData != NULL || pComponent != NULL);
 
	CComPtr<IConsole> spConsole;
	CComQIPtr<IHeaderCtrl, &IID_IHeaderCtrl> spHeader;
	if (pComponentData != NULL)
		spConsole = ((CAdapters*)pComponentData)->m_spConsole;
	else
	{
		spConsole = ((CAdaptersComponent*)pComponent)->m_spConsole;
		spHeader = spConsole;
}
 
	switch (event)
	{
	case MMCN_SHOW:
		{
			CComQIPtr<IResultData, &IID_IResultData> spResultData(spConsole);
			// TODO : Enumerate the result pane items
			hr = S_OK;
			break;
	}
	case MMCN_EXPAND:
		{
			CComQIPtr<IConsoleNameSpace, &IID_IConsoleNameSpace> spConsoleNameSpace(spConsole);
			// TODO : Enumerate scope pane items
			hr = S_OK;
			break;
	}
	case MMCN_ADD_IMAGES:
		{
			// Add Images
			IImageList* pImageList = (IImageList*) arg;
			hr = E_FAIL;
			// Load bitmaps associated with the scope pane
			// and add them to the image list
			// Loads the default bitmaps generated by the wizard
			// Change as required
			HBITMAP hBitmap16 = LoadBitmap(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDB_ADAPTERS_16));
			if (hBitmap16 != NULL)
			{
				HBITMAP hBitmap32 = LoadBitmap(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDB_ADAPTERS_32));
				if (hBitmap32 != NULL)
				{
					hr = pImageList->ImageListSetStrip((long*)hBitmap16, 
					(long*)hBitmap32, 0, RGB(0, 128, 128));
					if (FAILED(hr))
						ATLTRACE(_T("IImageList::ImageListSetStrip failed\n"));
			}
		}
			break;
	}
}
	return hr;
}

Send comments about this topic to Microsoft

Build date: 11/30/2009

© 2008 Microsoft Corporation. All rights reserved.