📄 moduleview.cpp
字号:
// ModuleView.cpp : 实现文件
//
#include "stdafx.h"
#include "PortMon.h"
#include "PortMonDoc.h"
#include "ProcHelp.h"
#include "mainfrm.h"
#include ".\moduleview.h"
// CModuleView
IMPLEMENT_DYNCREATE(CModuleView, CViewExt)
CModuleView::CModuleView() : CViewExt(IDV_MODULE)
{
}
CModuleView::~CModuleView()
{
}
BEGIN_MESSAGE_MAP(CModuleView, CViewExt)
END_MESSAGE_MAP()
// CModuleView 诊断
#ifdef _DEBUG
void CModuleView::AssertValid() const
{
CViewExt::AssertValid();
}
void CModuleView::Dump(CDumpContext& dc) const
{
CViewExt::Dump(dc);
}
CPortMonDoc* CModuleView::GetDocument() const // 非调试版本是内联的
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPortMonDoc)));
return (CPortMonDoc*)m_pDocument;
}
#endif //_DEBUG
// CModuleView 消息处理程序
void CModuleView::OnUpdate(CView* /*pSender*/, LPARAM /*lHint*/, CObject* /*pHint*/)
{
// show current selected process modules
ShowSelProcInfo();
// get parent process info
CPortMonDoc *pDoc = GetDocument();
CString sTemp = pDoc->GetSelParentName();
CMainFrame *pFrame = (CMainFrame *)AfxGetMainWnd();
pFrame->SetStatusBarInfo( sTemp );
}
void CModuleView::OnInitialUpdate()
{
CViewExt::OnInitialUpdate();
// TODO: 在此添加专用代码和/或调用基类
m_wndListExt.InsertColumn(0, "模块", LVCFMT_LEFT, 80);
m_wndListExt.InsertColumn(1, "大小", LVCFMT_LEFT, 80);
m_wndListExt.InsertColumn(2, "调用", LVCFMT_LEFT, 80);
m_wndListExt.InsertColumn(3, "基地址", LVCFMT_LEFT, 80);
m_wndListExt.InsertColumn(4, "模块名", LVCFMT_LEFT, 300);
}
void CModuleView::ShowSelProcInfo()
{
m_wndListExt.SetRedraw(FALSE); // shut off redraw
m_wndListExt.DeleteAllItems();
CPortMonDoc *pDoc = GetDocument();
DWORD dwProcID = pDoc->GetSelProcID();
if( dwProcID == 0 )
{
m_wndListExt.SetRedraw(TRUE); // turn on redraw
m_wndListExt.Invalidate();
return;
}
// turn on debug privilege
CProcessHelp::EnableDebugPrivilege(TRUE);
// using toolhelp snapshot
CProcessHelp procHelp( TH32CS_SNAPMODULE, dwProcID );
MODULEENTRY32 me32 = {0};
me32.dwSize = sizeof(MODULEENTRY32);
CString sTemp;
int nItem = 0;
if( procHelp.ModuleFirst(&me32) )
{
while( procHelp.ModuleNext(&me32) )
{
// module ID
sTemp.Format( "%u", nItem );
m_wndListExt.InsertItem( nItem, sTemp );
// module size
sTemp.Format( "%u", me32.modBaseSize );
m_wndListExt.SetItemText( nItem, 1, sTemp );
// module usage
if( me32.ProccntUsage == 65535 )
{
sTemp = _T("系统");
}
else
{
sTemp.Format( "%u", me32.ProccntUsage );
}
m_wndListExt.SetItemText( nItem, 2, sTemp );
// base address
sTemp.Format( "%p", me32.modBaseAddr );
m_wndListExt.SetItemText( nItem, 3, sTemp );
// module path name
sTemp = me32.szExePath;
m_wndListExt.SetItemText( nItem, 4, sTemp );
nItem++;
}
}
// turn off debug privilege
CProcessHelp::EnableDebugPrivilege(FALSE);
m_wndListExt.SetRedraw(TRUE); // turn on redraw
// this function will redraw the list
m_wndListExt.AutoSizeColumns();
}
BOOL CModuleView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: 在此添加专用代码和/或调用基类
cs.style = (cs.style & ~LVS_TYPEMASK) | LVS_REPORT;
cs.style |= LVS_AUTOARRANGE;
return CViewExt::PreCreateWindow(cs);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -