2011-8-9 19:13:18

来源:互联网 发布:山田凉介 知乎 编辑:程序博客网 时间:2024/05/08 07:39
 

 


2011-8-9 19:13:18


void CTraceToolDlg::OnBnClickedRefresh()
{
 Cleanup();
 m_bDeleting = TRUE;
 m_tree.DeleteAllItems();
 m_bDeleting = FALSE;
 InitVariables();
 UpdateData(FALSE);
 PopulateTree();
}

在点击刷新按钮后的操作


枚举出所有的树

void CTraceToolDlg::PopulateTree()
{
 CArray< DWORD > aidProcesses;

 GetProcessIds( aidProcesses );

 for( int iProcess = 0; iProcess < aidProcesses.GetSize(); iProcess++ )
 {
  DWORD idProcess = aidProcesses[iProcess];

  DWORD_PTR dwProcess = AtlTraceOpenProcess( idProcess );
  if( dwProcess != 0 )
  {
   AtlTraceSnapshotProcess( dwProcess );

   ATLTRACEPROCESSINFO info;
   AtlTraceGetProcessInfo( dwProcess, &info );
   
   const int MAX_TEXT_SIZE = 256;
   TCHAR szText[MAX_TEXT_SIZE];
   USES_CONVERSION_EX;
       
   CW2T pszName(info.szName);
   LPTSTR lpszName = pszName;
   _sntprintf_s(szText, MAX_TEXT_SIZE, _TRUNCATE, _T( "%s:0x%08x" ), lpszName, idProcess );
   szText[MAX_TEXT_SIZE - 1] = 0;
   
   
    //向树中插入一项
 
 
   HTREEITEM hProcessItem = m_tree.InsertItem( szText );

   PROCESSSETTINGS *pPS = NULL;
   pPS = new PROCESSSETTINGS;   
   pPS->bModified = FALSE;
   pPS->dwProcess = dwProcess;
   pPS->ps.nLevel = info.settings.nLevel;
   pPS->ps.bEnabled = info.settings.bEnabled;
   pPS->ps.bFuncAndCategoryNames = info.settings.bFuncAndCategoryNames;
   pPS->ps.bFileNameAndLineNo = info.settings.bFileNameAndLineNo;
   m_tree.SetItemData( hProcessItem, reinterpret_cast<DWORD_PTR>(pPS) );


//现在还需要遍历一下模块

   for( int iModule = 0; iModule < info.nModules; iModule++ )
   {
    ATLTRACEMODULEINFO module;
    AtlTraceGetModuleInfo( dwProcess, iModule, &module );

    CW2T pszModuleName(module.szName);
    LPTSTR lpszModuleName = pszModuleName;
#ifndef _UNICODE
    if(lpszModuleName == NULL)
     lpszModuleName = _T("");
#endif
    HTREEITEM hModuleItem = m_tree.InsertItem( lpszModuleName, hProcessItem );
    DWORD_PTR dwModule = module.dwModule;

    TRACESETTINGS *pTS = NULL;
    pTS = new TRACESETTINGS;
    ENSURE(pTS); /* prefast noise */
    pTS->bModified = FALSE;
    pTS->dwHandle = dwModule;
    pTS->ts.nLevel = module.settings.nLevel;
    pTS->ts.eStatus = module.settings.eStatus;
    m_tree.SetItemData( hModuleItem, reinterpret_cast<DWORD_PTR>(pTS) );

//遍历模块 模块的所有类别

    for( int iCategory = 0; iCategory < module.nCategories; iCategory++ )
    {
     ATLTRACECATEGORYINFO category;
     AtlTraceGetCategoryInfo( dwProcess, dwModule, iCategory, &category );
     DWORD_PTR dwCategory = category.dwCategory;
     
     CW2T pszCategoryName(category.szName);
     LPTSTR lpszCategoryName = pszCategoryName;
#ifndef _UNICODE
     if(lpszCategoryName == NULL)
      lpszCategoryName = _T("");
#endif
     HTREEITEM hCategoryItem = m_tree.InsertItem( lpszCategoryName, hModuleItem );

     TRACESETTINGS *pTS2 = NULL;
     pTS2 = new TRACESETTINGS;
     ENSURE(pTS2); /* prefast noise */
     pTS2->bModified = FALSE;
     pTS2->dwHandle = dwCategory;
     pTS2->ts.nLevel = category.settings.nLevel;
     pTS2->ts.eStatus = category.settings.eStatus;
     m_tree.SetItemData( hCategoryItem, reinterpret_cast<DWORD_PTR>(pTS2) );
    }
   }
  }
 }
}


race.cpp(348) : WinMsg: PumpMessage: hwnd=0x000504C0, msg = WM_PAINT (0x00000000, 0x00000000)
afxtrace.cpp(348) : WinMsg: PumpMessage: hwnd=0x000504C0, msg = WM_PAINT (0x00000000, 0x00000000)
afxtrace.cpp(348) : WinMsg: PumpMessage: hwnd=0x000504C0, msg = WM_TIMER (0x00000001, 0x00000000)
afxtrace.cpp(348) : WinMsg: PumpMessage: hwnd=0x00460DEE, msg = WM_TIMER (0x00000002, 0x00000000)
afxtrace.cpp(348) : WinMsg: PumpMessage: hwnd=0x00460DEE, msg = WM_PAINT (0x00000000, 0x00000000)
afxtrace.cpp(360) : WinMsg: WndProc: hwnd=0x000504B4, msg = 0x0000 (0x00000000, 0x00000000)
afxtrace.cpp(348) : WinMsg: PumpMessage: hwnd=0x000504C0, msg = WM_PAINT (0x00000000, 0x00000000)
afxtrace.cpp(348) : WinMsg: PumpMessage: hwnd=0x000504C0, msg = WM_PAINT (0x00000000, 0x00000000)

原创粉丝点击