For my Task Manager Program I am using a listview in report mode to display the list of running processes. The problem is how do you add subitems? The function i am using only adds itmes in column 0 and not any other column. Here is the function:
I have set up the columns allright and created the list view without using resources (ie. at runtime). Also I have a function that gets the names of all of processes and returns the number (to fill up the listview), which I want to refresh every second, howver the PdhEnumObjectItems function caches the list of processes and will only retreive the same list of processes each time. How can this be changed? I know to use the PdhEnumObjects Function and set the bRefresh param to TRUE. But what about the other parameters? Here is the function I already have, notice it calls the above AddItem().Code:BOOL AddItem(char *item1,char *item2, char *item3, char *item4) { int i; LVITEM LvI; LvI.mask = LVIF_TEXT; LvI.iItem = 0; for (i=0;i<4;i++) { LvI.iSubItem = i; if (i == 0) LvI.pszText = item1; if (i == 1) LvI.pszText = item2; if (i == 2) LvI.pszText = item3; if (i == 3) LvI.pszText = item4; ListView_InsertItem(GetDlgItem(hwndMain, 3001), &LvI); } return 1; }
Code:int getProcesses() { int numProcesses = 0; PDH_STATUS pdhStatus = ERROR_SUCCESS; LPTSTR szCounterListBuffer = NULL; DWORD dwCounterListSize = 0; LPTSTR szInstanceListBuffer = NULL; DWORD dwInstanceListSize = 0; LPTSTR szThisInstance = NULL; // call the function to determine the required buffer size for the data pdhStatus = PdhEnumObjectItems(NULL,NULL,"Process",szCounterListBuffer, &dwCounterListSize,szInstanceListBuffer,&dwInstanceListSize, PERF_DETAIL_WIZARD,0); if (pdhStatus != ERROR_SUCCESS && pdhStatus != PDH_MORE_DATA) return 1; szCounterListBuffer = (LPTSTR)malloc (dwCounterListSize ); szInstanceListBuffer = (LPTSTR)malloc(dwInstanceListSize); if ((szCounterListBuffer == NULL) || (szInstanceListBuffer == NULL)) { //printf ("\nUnable to allocate buffers"); return 1; } pdhStatus = PdhEnumObjectItems(NULL, // reserved NULL, // local machine "Process", // object to enumerate szCounterListBuffer, // pass in NULL buffers &dwCounterListSize, // an 0 length to get szInstanceListBuffer, // required size &dwInstanceListSize, // of the buffers in chars PERF_DETAIL_WIZARD, // counter detail level 0); if (pdhStatus == ERROR_SUCCESS){ // walk the return instance list for (szThisInstance = szInstanceListBuffer; *szThisInstance != 0; szThisInstance += strlen(szThisInstance) + 1) { //SendDlgItemMessage(hwndMain,IDLIST,LB_SETITEMDATA,1,(LPARAM)"hi"); if (szThisInstance != "_Total") { AddItem(szThisInstance, szInstanceListBuffer, "item3", "item4"); numProcesses+=1; } } } if (szCounterListBuffer != NULL) free (szCounterListBuffer); if (szInstanceListBuffer != NULL) free (szInstanceListBuffer); return numProcesses; }



LinkBack URL
About LinkBacks



