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

  1. // refsview.cpp
  2. //
  3. // Created 10/08/98
  4. //
  5. // (C)Copyright 1998-1999 Microsoft Corporation, All rights reserved.
  6. //
  7.  
  8. #include "pch.hpp"
  9. #pragma hdrstop
  10.  
  11. #include "refsview.hpp"
  12. #include "hpmonmgr.hpp"
  13.  
  14.  
  15. LRESULT CALLBACK ObjectReferencesViewer::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 ObjectReferencesViewer::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[] = "References to ";
  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 ObjectReferencesViewer::PopulateReferencesCB (ID id, ObjectID vmid, PVOID token)
  64. {
  65.     ObjectReferencesViewer *orv = (ObjectReferencesViewer*)token;
  66.  
  67.     if (!id)
  68.     {
  69.         ASSERT(vmid);
  70.         id = (OBJID)orv->m_mgr->LookupID(vmid);
  71.     }
  72.  
  73.     BOOL result;
  74.  
  75.     if (id)
  76.         result = (orv->AddTreeItemForReferencedID(orv->m_htiroot, id) != NULL);
  77.     else
  78.         result = (orv->AddTreeItemForObject(orv->m_htiroot, vmid) != NULL);
  79.  
  80.     if (result)
  81.         TreeView_Expand(orv->m_htree, orv->m_htiroot, TVE_EXPAND);
  82.  
  83.     return 1;
  84. }
  85.  
  86.  
  87. BOOL ObjectReferencesViewer::Initialize (HeapMonitorManager *mgr, ObjectID vmid)
  88. {
  89.     BOOL result;
  90.  
  91.     result = OVInitialize(mgr, "Object References");
  92.     if (result)
  93.     {
  94.         OBJID id = (OBJID)m_mgr->LookupID(vmid);
  95.         
  96.         if (id)
  97.             result = (m_htiroot = AddTreeItemForID(TVI_ROOT, id)) != NULL;
  98.         else
  99.             result = (m_htiroot = AddTreeItemForObject(TVI_ROOT, vmid)) != NULL;
  100.     }
  101.  
  102.     if (result)
  103.     {
  104.         result = mgr->FindObjectReferences(vmid, &PopulateReferencesCB, this);
  105.     }
  106.  
  107.     return result;
  108. }
  109.  
  110.