I'm using Enumprocesses( lpidProcess, cb, lpcbNeeded ) to determine running ProcessIds. How do I subset this list to contain only "Applications", those processes that display on the Task Manager Applications tab?
Thanks in advance.
I'm using Enumprocesses( lpidProcess, cb, lpcbNeeded ) to determine running ProcessIds. How do I subset this list to contain only "Applications", those processes that display on the Task Manager Applications tab?
Thanks in advance.
Per How does Task Manager categorize processes as App, Background Process, or Windows Process? on MSDN:
If the process has a visible window, then Task Manager calls it an "App".
If the process is marked as critical, then Task Manager calls it a "Windows Process".
Otherwise, Task Manager calls it a "Background Process".
So, given a process ID, you can check if it has any visible windows by calling EnumWindows()
, where the callback function calls GetWindowThreadProcessId()
to check if each window belongs to the process, and IsWindowVisible()
to check if each window is visible.
For example:
struct myFindInfo
{
DWORD processID;
bool found;
};
static BOOL CALLBACK findVisibleWindowProc(HWND hwnd, LPARAM lParam)
{
myFindInfo *fi = reinterpret_cast<myFindInfo*>(lParam);
DWORD pid;
GetWindowThreadProcessId(hwnd, &pid);
if ((pid == fi->processID) && IsWindowVisible(hwnd))
{
fi->found = true;
return FALSE;
}
return TRUE;
}
bool isApplicationProcess(DWORD processID)
{
findInfo fi;
fi.processID = processID;
fi.found = false;
EnumWindows(&findVisibleWindowProc, reinterpret_cast<LPARAM>(&fi));
return fi.found;
}