Applications: Creating a simple UI application from scratch, Process Viewer, Part 2Applications: Creating a simple UI application from scratch, Process Viewer, Part 2

In this series of posts lets go about creating a simple process viewer, as promised earlier. This post is basically based around a post by Bruce Eitman. We use Toolhelp32 api’s to get information about the running processes and other info too, like the process id, number of threads running in the process’s context etc. I recommend reading Bruce’s post before proceeding here. That will save me time from explaining the backend stuff and I can concentrate on the UI.



Ok, so lets go about creating the UI. Create a program similar to the one I had created in my previous post. This dialog contains a List view control and a group box, shown below:


Set the "View" property of the list view control as Report, "No Column Header" to false. I have set the ID to IDC_LISTVIEW_PROCESSES. Create 3 static text controls to hold the Process id, No of threads and the load address. Add these three static controls into a group box, name the group box "Process Info". Remember to create the three static text controls before creating the group box. I was trying the other way around, by creating the group box first, the text controls would not show up, they were hidden behind the group box. Invoke this dialog from WinMain and check that the dialog is showing up correctly. Here is the WinMain function:


int WinMain(HINSTANCE hInst,

            HINSTANCE hPrevInst,

            LPTSTR lpCmdLine,

            int nCmdShow)

{



    INITCOMMONCONTROLSEX icex;



    g_hInst = hInst;



    memset(&icex, 0, sizeof(icex));

    icex.dwSize = sizeof(INITCOMMONCONTROLSEX);

    icex.dwICC = ICC_LISTVIEW_CLASSES;



    InitCommonControlsEx(&icex);



    //MessageBox(NULL, L"Hi", L"Info", MB_OK);

    DialogBox(hInst, MAKEINTRESOURCE(IDD_PPC_PROCVIEWER), NULL, ProcessViewerDlgProc);



    return 0;

}

InitCommonControlsEx() is used to register specific common controls classes from the common control dynamic-link library. In this case a List View control. And then there’s the call to DialogBox() which shows up our UI.

About ProcessViewerDlgProc, for now, you could use the same skeleton dialog proc from my previous post.



Well, that is all for now. In the next post, we see how to initialise the List View control headers, get the information about the process and populate the list view control with the process names.

Leave a Reply

Your email address will not be published. Required fields are marked *