Saturday, April 21, 2012

List all the processes running on your system using win32 API

Make sure to link the libpsapi.a library if you are using code blocks  

This program uses the following windows API functions and structures
  •  CreateToolhelp32Snapshot
  •  GetProcessMemoryInfo
  •  Process32First
  •  Process32Next
  •  PROCESSENTRY32 
  •  PROCESS_MEMORY_COUNTERS

The program list all the running processes including the PID and mem allocated for each process.


#include <iostream>
#include <windows.h>
#include <TlHelp32.h>
#include <Psapi.h>

using namespace std;

void listAllRunningProcess();

int main()
{
    listAllRunningProcess();
    return 0;
}
void listAllRunningProcess()
{
    PROCESSENTRY32 pe32;
    PROCESS_MEMORY_COUNTERS pmc;
    HANDLE hprocess;

    hprocess = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    GetProcessMemoryInfo(hprocess, &pmc, sizeof(pmc));

    Process32First(hprocess, &pe32);
    pe32.dwSize = sizeof(PROCESSENTRY32);

    while(Process32Next(hprocess, &pe32))
    {
        cout << pe32.szExeFile << "------>"<<  pe32.th32ProcessID<<"---->>"<< pe32.th32ParentProcessID;
        cout <<"----------->"<< pmc.PeakWorkingSetSize<<  endl;
    }
}

How to create Custom push button in QT5

To be honest this is not my work its an exact copy from this link. http://mcmtechtips.blogspot.com/2012/03/shape-qpushbutton-in-your-own-st...