I just learned SDK programming, I want to edit a SDK-compiled process manager, but I haven't written online. I have written it yourself. Insufficient,
Please expert guidance, thank you!
Below is the code:
Before compiling, add ComctL32.lib psapi.lib in Project Setting -> Link-> Object / Library Module.
Process.cpp:
#include
Dialogbox (NULL, (LPCTSTSTSTSTSTDD_DIALOG, NULL, (DLGPROC) TEST);
Return 1;}
LRESULT CALLBACK Test (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {switch (message) {case WM_INITDIALOG: Init (hDlg); return TRUE; case WM_COMMAND: switch (LOWORD (wParam)) {case IDCANCEL: EndDialog (hDlg , 0); KillTimer (HDLG, 1000); Return True; Break; Case IDok: RETURN (EndProcess (HDLG)); Break; Case IdRefresh: RefreshProcess (HDLG); Return True; Break;
}} Return False;}
/ ************************************************** *********************** / / * Refresh Process Entry Parameters Dialog Handle * / / * * // ********* *********************************************************** ************ /
void RefreshProcess (HWND hDlg) {HANDLE hSnapshot, h_Process; PROCESSENTRY32 pe; char lpszAdd [255]; int nIndex; DWORD Memory; LVITEM Lv; PROCESS_MEMORY_COUNTERS PMC; pe.dwSize = sizeof (pe); hSnapshot = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0) Process32first (HSnapshot, & PE); sprintf (lpszadd, "% s", pe.szexefile); lv.mask = lvif_text; lv.iitem = 0; lv.isubitem = 0; lv.psztext = lpszadd; senddlgitemmessage (HDLG, IDC_LISTVIEW, LVM_DELETEALLITEMS, 0, 0); SendDlgItemMessage (hDlg, IDC_LISTVIEW, LVM_INSERTITEM, 0, (LPARAM) & Lv); sprintf (lpszAdd, "% i", pe.th32ProcessID); Lv.iSubItem = 1; SendDlgItemMessage (hDlg, IDC_LISTVIEW , LVM_SETITEM, 0, (LPARAM) & lv); Sprintf (LPSZADD, "% I", PE.PCPRICLASSBASE); lv.isubitem = 2; senddlgitemmessage (HDLG, Idc_ListView, LVM_SETITEM, 0, (LPARAM) & lv); // system Process's memory is always 20K memory = 20; sprintf (lpszadd, "% 2i k", memory); lv.isubitem = 3; senddlgitemmessage (HDLG, IDC_ListView, LVM_SETITETITETEM, 0, (LPARAM) & lv); while (Process32Next HSnapshot, & PE) {sprintf (LPSZADD, "% s", pe.szexefile; lv.isubitem = 0; NINDEX = SenddlgiteMmessage (HDLG, IDC_ListView, LVM_INSERTITEM, 0, (LPARAM) & lv); if (Nindex! = 1) {lv.iitem = nindex; lv.isubitem = 1; sprintf (lpszadd, "% i", pe.th32processid); senddlgitemmessage (HDLG, IDC_ListView, LVM_SETITETITEM, 0, (LPARAM) & lv); lv.isubitem = 2 Sprintf (LPSZADD, "% I", pe.pcpriclassbase; SenddlgiteMmessage (HDLG, IDC_ListView, LVM_SETITETIM, 0, (LPARAM) & lv); h_process =
OpenProcess (PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pe.th32ProcessID); // get the process memory size GetProcessMemoryInfo (h_Process, & PMC, sizeof (PMC)); Memory = PMC.WorkingSetSize / 1024; sprintf (lpszAdd, "% i K", Memory ); Lv.isubitem = 3; senddlgitemmessage (HDLG, IDC_ListView, LVM_SETITETETETETETETETETETITVIEW, LVM_SETITETEM, 0, (LPARAM) & lv);}}} / * / **************************** *********************************************************** ** // * Initialization function, primarily used to add list controls * // *************************************************** ************************************************ /
Bool init (hwnd hdlg) {lvcolumn lv; static char * sztext [] = {"Image Name", "PID", "Priority", "Memory Us"}; static int CX [] = {100, 100, 80, 120}; INT i = 0; for (i = 0; i <4; i ) {lv.mask = LVCF_Text | LVCF_WIDTH; if (i <2) lv.fmt = LVCFMT_LEFT; ELSE LV.FMT = LVCFMT_Right; lv.cx = CX [i]; lv.pszText = szText [i]; SendDlgItemMessage (hDlg, IDC_LISTVIEW, LVM_INSERTCOLUMN, (WPARAM) i, (LPARAM) & lv);} SendDlgItemMessage (hDlg, IDC_LISTVIEW, LVM_SETEXTENDEDLISTVIEWSTYLE, (WPARAM) LVS_EX_FULLROWSELECT, (LPARAM) LVS_EX_FULLROWSELECT RefreshProcess (HDLG); Return True;}
/ ************************************************** ***************** * End the process function, used to end the selected process in the list view * // ******* *********************************************************** *************** /
BOOL EndProcess (HWND hDlg) {int hProcess = SendDlgItemMessage (hDlg, IDC_LISTVIEW, LVM_GETNEXTITEM, -1, (LPARAM) MAKELPARAM ((UINT) LVNI_SELECTED, 0)); if (hProcess = -1!) {LVITEM Lv; char Buffer [ 256]; HANDLE h_process; DWORD ProcessId; BOOL iRet; memset (Buffer, 0, sizeof (Buffer)); Lv.iSubItem = 1; Lv.pszText = Buffer; Lv.cchTextMax = sizeof (Buffer); SendDlgItemMessage (hDlg, IDC_LISTVIEW , LVM_GETITEMTEXT, (WPARAM) hProcess, (LPARAM) & Lv); ProcessId = atol (Buffer); h_process = OpenProcess (PROCESS_TERMINATE, NULL, ProcessId); if (h_process == NULL) {MessageBox (hDlg, "The process can not access" "Error", MB_OK; RETURN FALSE;} Else {IF (MSSAGEBOX (HDLG, "End this process?", "Warning", MB_OKCANCEL) == iDok) {itt = TerminateProcess (h_process, 0); if (! IRET) {MessageBox (HDLG, "End Process Failure", "Error", MB_OK; Return True;} else {MessageBox (HDLG, "success", "success", mb_ok); returnaf false;}} else r ETURN FALSE;}} else {return false;}}
Process.rc:
// Microsoft Developer Studio generated resource script.//#include "resource.h"
#define apstudio_readonly_symbols ///// generated from the textinclude 2 resource.//#clude "afxres.h"
/ # undef apstudio_readonly_symbols
/// Chinese (p.r.c.) Resources
#if! defined (AFX_RESOURCE_DLL) || Defined (AFX_TARG_CHS) #ifdef _win32language lang_chinese, SUBLANG_CHINESE_SIMPLIFIED # Pragma code_page (936) #ENDIF / / _WIN32
///// Dialog //
IDD_DIALOG DIALOG DISCARDABLE 0, 0, 213, 262STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENUCAPTION "Dialog" FONT 10, "Times New Roman" BEGIN DEFPUSHBUTTON "refresh", IDREFRESH, 17,230,39,14 PUSHBUTTON "End Process", IDOK, 89,228,39 14 Control "List1", IDC_ListView, "SyslistView32", LVS_REPORT | WS_BORDER | WS_TABSTOP, 17, 9, 176, 212 Pushbutton "Exit", IDCANCEL, 159, 228, 39, 14END ///// designInfo //
#ifdef apstudio_invokedguidelines designInfo Discardable Begin IDD_Dialog, Dialog Begin Leftmargin, 7 Rightmargin, 206 Topmargin, 7 Bottommargin, 255 Endend # endif // apstudio_invoked
#ifdef apstudio_invoked ///// Textinclude //
1 Textinclude Discardable Begin "Resource.h / 0" end
2 Textinclude Discardable Begin "#include" "AfXRES.H" "/ r / n" "/ 0" end
3 textinclude discardable begin "/ r / n" "/ 0" end
#ENDIF // APSTUDIO_INVOKED
#ENDIF // Chinese (p.r.c.) Resources /
#ifndef apstudio_invoked ///// generated from the textinclude 3 resource.//
/ # endif // not APSTUDIO_INVOKED
Resource.h:
// {{no_dependencies}}} // microsoft developer studio generated incrude file.// used by process.rc // # Define IDd_dialog 101 # define idc_listview 1000 # define idRefresh 1001
// Next default values for new objects // #ifdef APSTUDIO_INVOKED # ifndef APSTUDIO_READONLY_SYMBOLS # define _APS_NEXT_RESOURCE_VALUE 102 # define _APS_NEXT_COMMAND_VALUE 40001 # define _APS_NEXT_CONTROL_VALUE 1003 # define _APS_NEXT_SYMED_VALUE 101 # endif # endif