home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 39 / IOPROG_39.ISO / SOFT / sdkjava40.exe / data1.cab / fg_Samples / Samples / Profiler / heapmon / instview.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-04  |  2.4 KB  |  105 lines

  1. // instview.cpp
  2. //
  3. // Created 01/14/99
  4. //
  5. // (C)Copyright 1999 Microsoft Corporation, All rights reserved.
  6. //
  7.  
  8. #include "pch.hpp"
  9. #pragma hdrstop
  10.  
  11. #include "instview.hpp"
  12. #include "hpmonmgr.hpp"
  13.  
  14.  
  15. LRESULT CALLBACK ClassInstancesViewer::WndProc (HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam)
  16. {
  17.     switch (msg)
  18.     {
  19.     case WM_NOTIFY:
  20.         {
  21.             LPNMHDR pnmh = (NMHDR*)lParam; 
  22.             switch (pnmh->code)
  23.             {
  24.             case TVN_ITEMEXPANDING:
  25.             case TVN_ITEMEXPANDED:
  26.                 {
  27.                     NMTREEVIEW *pnmtv = (NMTREEVIEW*)lParam;
  28.                     TV_ITEM *ptvi = &pnmtv->itemNew;
  29.                     if (ptvi->hItem == m_htiroot)
  30.                         return BaseWndProc(wnd, msg, wParam, lParam);
  31.                 }
  32.                 break;
  33.             }
  34.         }
  35.         break;
  36.     }
  37.  
  38.     return ObjectViewer::WndProc(wnd, msg, wParam, lParam);
  39. }
  40.  
  41.  
  42. BOOL ClassInstancesViewer::GetItemText (HTREEITEM hti, PSTR &psztext, int &cchmaxtext)
  43. {
  44.     BOOL result = ObjectViewer::GetItemText(hti, psztext, cchmaxtext);
  45.  
  46.     if (result && hti == m_htiroot)
  47.     {
  48.         int len = strlen(psztext);
  49.         static CHAR prefix[] = "Instances of ";
  50.         int prefixlen = ARRAY_ELEMENTS(prefix)-1;
  51.         if (len+prefixlen < cchmaxtext)
  52.         {
  53.             MoveMemory(psztext+prefixlen, psztext, len+1);
  54.             CopyMemory(psztext, prefix, prefixlen);
  55.         }
  56.     }
  57.  
  58.     return result;
  59. }
  60.  
  61.  
  62. //static
  63. int ClassInstancesViewer::PopulateInstancesCB (ID id, ObjectID vmid, PVOID token)
  64. {
  65.     ClassInstancesViewer *civ = (ClassInstancesViewer*)token;
  66.  
  67.     if (id == NULL)
  68.     {
  69.         ASSERT(vmid != NULL);
  70.         id = (OBJID)civ->m_mgr->LookupID(vmid);
  71.     }
  72.  
  73.     BOOL result;
  74.  
  75.     if (id != NULL) 
  76.         result = (civ->AddTreeItemForID(civ->m_htiroot, id) != NULL);
  77.     else
  78.         result = (civ->AddTreeItemForObject(civ->m_htiroot, vmid) != NULL);
  79.  
  80.     if (result)
  81.         TreeView_Expand(civ->m_htree, civ->m_htiroot, TVE_EXPAND);
  82.  
  83.     return 1;
  84. }
  85.  
  86.  
  87. BOOL ClassInstancesViewer::Initialize (HeapMonitorManager *mgr, CLASSID cls)
  88. {
  89.     BOOL result;
  90.  
  91.     result = OVInitialize(mgr, "Class Instances");
  92.     if (result)
  93.     {
  94.         result = (m_htiroot = AddTreeItemForID(TVI_ROOT, cls)) != NULL;
  95.     }
  96.  
  97.     if (result)
  98.     {
  99.         result = mgr->FindClassInstances(cls, &PopulateInstancesCB, this);
  100.     }
  101.  
  102.     return result;
  103. }
  104.  
  105.