SDK operation list-View Control instance -- Process Traversal

Source: Internet
Author: User

Traverse the window to obtain the control handle

1 EnumChildWindows(hwndDlg, (WNDENUMPROC)EnumChildProc, NULL);

Callback Function

1 bool callback enumchildproc (hwnd, lparam) 2 {3 char strclsname [maxbyte] = {0}; 4 getclassname (hwnd, strclsname, maxbyte ); 5 If (strcmp (strclsname, "syslistview32") = 0) // find the list control 6 {7 insertcolumn (hwnd); // Add the Title 8 enumprogress (hwnd ); // Add content 9 return true; // end traversal 10} 11 12 Return false; // continue traversing the subwindow 13}

Add title

1 void insertcolumn (hwnd hlist) 2 {3 lv_column LVC = {0}; 4 5 LVC. mask = lvcf_text | lvcf_width; 6 LVC. psztext = "PID"; 7 LVC. cx = 80; 8 sendmessage (hlist, lvm_insertcolumn, 0, (long) & LVC); 9 LVC. psztext = "parent process PID"; 10 LVC. cx = 100; 11 sendmessage (hlist, lvm_insertcolumn, 1, (long) & LVC); 12 LVC. psztext = "image name"; 13 LVC. cx = 200; 14 sendmessage (hlist, lvm_insertcolumn, 2, (long) & LVC); 15}

Add content

1 bool enumprogress (hwnd hlist) 2 {3 bool Bret = false; 4 handle hprocesssnap = NULL; 5 6 hprocesssnap = createconlhelp32snapshot (th32cs_snapprocess, 0); 7 if (hprocesssnap = callback) 8 {9 return false; 10} 11 12 processentry32 pe32 = {0}; 13 pe32.dwsize = sizeof (processentry32); 14 if (process32first (hprocesssnap, & pe32 )) 15 {16 lvitem LVI = {0}; 17 LVI. mask = lvif_text; 18 char strtmp [maxbyte] = {0}; 19 do 20 {21 zeromemory (strtmp, maxbyte); 22 sprintf (strtmp, "% d", pe32.th32processid ); 23 LVI. iItem = 0; 24 LVI. isubitem = 0; // when the lvm_insertitem message is sent, the subitem must be 025 LVI. psztext = strtmp; 26 int nindx = sendmessage (hlist, lvm_insertitem, 0, (lparam) & LVI); // the return value is the index of item 27 28 zeromemory (strtmp, maxbyte ); 29 sprintf (strtmp, "% d", pe32.th32parentprocessid); 30 LVI. iItem = nindx; 31 LVI. isubitem = 1; 32 LVI. psztext = strtmp; 33 sendmessage (hlist, lvm_setitem, 0, (lparam) & LVI); 34 35 LVI. isubitem = 2; 36 LVI. iItem = nindx; 37 LVI. psztext = pe32.szexefile; 38 sendmessage (hlist, lvm_setitem, 0, (lparam) & LVI); 39} 40 while (process32next (hprocesssnap, & pe32); 41 Bret = true; 42} 43 else 44 {45 Bret = false; 46} 47 48 closehandle (hprocesssnap); 49 return Bret; 50}

 

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: info-contact@alibabacloud.com 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.