Process Module viewer and module Viewer

Source: Internet
Author: User

Process Module viewer and module Viewer

The main interface is as follows:

The main code is as follows:

BOOL CEnumProcessDlg: OnInitDialog () {CDialog: OnInitDialog (); // Add the "about..." menu item to the system menu. // IDM_ABOUTBOX must be in the range of system commands. ASSERT (IDM_ABOUTBOX & 0xFFF0) = IDM_ABOUTBOX); ASSERT (IDM_ABOUTBOX <0xF000); CMenu * pSysMenu = GetSystemMenu (FALSE); if (pSysMenu! = NULL) {CString strAboutMenu; strAboutMenu. LoadString (IDS_ABOUTBOX); if (! StrAboutMenu. IsEmpty () {pSysMenu-> AppendMenu (MF_SEPARATOR); pSysMenu-> AppendMenu (MF_STRING, IDM_ABOUTBOX, strAboutMenu); }}// set the icon of this dialog box. When the main window of the application is not a dialog box, the framework will automatically // execute this operation SetIcon (m_hIcon, TRUE); // set the big icon SetIcon (m_hIcon, FALSE ); // set the small icon // TODO: add the additional initialization code LONG lStyle here; lStyle = GetWindowLong (m_ctrlList.m_hWnd, GWL_STYLE); lStyle & = ~ LVS_TYPEMASK; lStyle | = LVS_REPORT; SetWindowLong (values, GWL_STYLE, lStyle); DWORD dwStyle = values (); dwStyle | = LVS_EX_FULLROWSELECT; dwStyle | = LVS_EX_GRIDLINES; dimensions (dwStyle ); values (0, _ T ("Process ID"), LVCFMT_LEFT, 75); m_ctrlList.InsertColumn (1, _ T ("Process Name"), LVCFMT_LEFT, 120); m_ctrlList.InsertColumn (2, _ T ("Paren T Process ID "), LVCFMT_LEFT, 115); m_ctrlList.InsertColumn (3, _ T (" Thread Count "), LVCFMT_LEFT, 90); ListProcess (); return TRUE; // return TRUE} void CEnumProcessDlg: OnSysCommand (UINT nID, LPARAM lParam) {if (nID & 0xFFF0) = IDM_ABOUTBOX) unless the focus is set to the control) {CAboutDlg dlgAbout; dlgAbout. doModal () ;}else {CDialog: OnSysCommand (nID, lParam) ;}// if you add the minimization button to the dialog box, you need the following code // to draw the icon. For MFC applications that use document/view models, // This will be automatically completed by the framework. Void CEnumProcessDlg: OnPaint () {if (IsIconic () {CPaintDC dc (this); // The device context SendMessage (WM_ICONERASEBKGND, reinterpret_cast <WPARAM> (dc. getSafeHdc (), 0); // center the icon in the work rectangle int cxIcon = GetSystemMetrics (SM_CXICON); int cyIcon = GetSystemMetrics (SM_CYICON); CRect rect; getClientRect (& rect); int x = (rect. width ()-cxIcon + 1)/2; int y = (rect. height ()-cyIcon + 1)/2; // draw the icon dc. drawIcon (x, Y, m_hIcon) ;}else {CDialog: OnPaint () ;}// the system calls this function to display the cursor when the user drags the smallest window. // HCURSOR CEnumProcessDlg: OnQueryDragIcon () {return static_cast <HCURSOR> (m_hIcon);} void CEnumProcessDlg: ListProcess (void) {HANDLE hProcessSnap; PROCESSENTRY32 pe32; hProcessSnap = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0); if (hProcessSnap = INVALID_HANDLE_VALUE) {CString strErr; strErr. format (_ T ("createconlhelp32snapshot failed: % d"), GetLastError (); AfxMessageBox (strErr); return;} pe32. DwSize = sizeof (PROCESSENTRY32); int index = 0; if (! Process32First (hProcessSnap, & pe32) {CString strErr; strErr. format (_ T ("Process32First failed: % d"), GetLastError (); AfxMessageBox (strErr); CloseHandle (hProcessSnap); return ;}do {CString strID; strID. format (_ T ("% d"), pe32.th32ProcessID); m_ctrlList.InsertItem (index, strID); m_ctrlList.SetItemText (index, 1, pe32.szExeFile); strID. format (_ T ("% d"), pe32.th32ParentProcessID); m_ctrlList.SetItemText (index, 2, strID); strID. format (_ T ("% d"), pe32.cntThreads); m_ctrlList.SetItemText (index ++, 3, strID);} while (Process32Next (hProcessSnap, & pe32 )); closeHandle (hProcessSnap);} void CEnumProcessDlg: OnContextMenu (CWnd * pWnd, CPoint point) {// TODO: add the message processing program code CMenu menu here; if (menu. createPopupMenu () = FALSE) {return;} if (pWnd = & m_ctrlList) {menu. appendMenu (MF_STRING, ID_SCANMODULE, _ T ("view dependency module"); if (m_ctrlList.GetSelectedCount () <0) {menu. enableMenuItem (ID_SCANMODULE, MF_DISABLED | MF_GRAYED) ;}} menu. trackPopupMenu (TPM_LEFTALIGN | TPM_RIGHTBUTTON, point. x, point. y, this);} void CEnumProcessDlg: ScanModule (UINT nID) {switch (nID) {case ID_SCANMODULE: {CString strProcessID = downlink (m_ctrlList.GetSelectionMark (), 0); CProcessModule dlgProcessModule; dlgProcessModule. m_dwProcessID = _ tcstoul (strProcessID, 0, 10); dlgProcessModule. doModal ();} break; default: break;} void CEnumProcessDlg: OnNMDblclkListProcess (NMHDR * pNMHDR, LRESULT * pResult) {// TODO: add the control notification handler code CString strProcessID = m_ctrlList.GetItemText (m_ctrlList.GetSelectionMark (), 0); CProcessModule dlgProcessModule; dlgProcessModule. m_dwProcessID = _ tcstoul (strProcessID, 0, 10); dlgProcessModule. doModal (); * pResult = 0 ;}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.