_NewEnum Property

Home Page (Objects)OverviewFAQReference

Applies to: Breakpoints object, Configurations object, Documents object, Projects object, Windows object

References objects in a collection.

Syntax

object._NewEnum

Parameters

object

An expression that evaluates to one of the objects in the Applies To list above.

Remarks

With Visual C++, you can browse a collection to find a particular item by using the _NewEnum property or the Item method. In Visual Basic, you do not need to use the _NewEnum property, because it is automatically used in the implementation of For Each ... Next.

Example

The following example is a Visual C++ code snippet you can insert into an add-in's command handler method using the ActiveX Template Library. This example uses the _NewEnum property to iterate through all open windows and display their captions in the output window.

Tip   You can iterate through these windows more efficiently by using the Item method of the Windows object.

CComPtr<IDispatch> pDisp;
   CComQIPtr<IWindows, &IID_IWindows> pWindows;
   m_pApplication->get_Windows(&pDisp);
   pWindows = pDisp;
   pDisp = NULL;
   CComPtr<IUnknown> pUnk;
   CComQIPtr<IEnumVARIANT, &IID_IEnumVARIANT> pNewEnum;
   if (SUCCEEDED(pWindows->get__NewEnum(&pUnk)) && pUnk != NULL)
   {
      pNewEnum = pUnk;
      VARIANT varWindow;
      CComQIPtr<IGenericWindow, &IID_IGenericWindow> pWindow;
while (pNewEnum->Next(1, &varWindow, NULL) == S_OK)
      {
         ASSERT (varWindow.vt == VT_DISPATCH);
         pWindow = varWindow.pdispVal;
         VariantClear(&varWindow);
         CComBSTR bstrCaption;
         pWindow->get_Caption(&bstrCaption);
         m_pApplication->PrintToOutputWindow(bstrCaption);
      }
   }