gpt4 book ai didi

c++ - 以编程方式确定给定 processid 的应用程序状态

转载 作者:行者123 更新时间:2023-11-28 04:28:44 25 4
gpt4 key购买 nike

我正在使用 Enumprocesses( lpidProcess, cb, lpcbNeeded ) 来确定正在运行的 ProcessId。如何子集此列表以仅包含“应用程序”,即显示在“任务管理器应用程序”选项卡上的那些进程?

提前致谢。

最佳答案

根据 How does Task Manager categorize processes as App, Background Process, or Windows Process?在 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".

因此,给定一个进程 ID,您可以通过调用 EnumWindows() 检查它是否有任何可见的窗口,其中回调函数调用 GetWindowThreadProcessId() 来检查是否每个窗口都属于进程,IsWindowVisible() 检查每个窗口是否可见。

例如:

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;
}

关于c++ - 以编程方式确定给定 processid 的应用程序状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53547233/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com