我如何从其进程名称获取窗口标题? [英] How Could I Get the Window Title from Its Process Name?
本文介绍了我如何从其进程名称获取窗口标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码,用于检查进程名称是否存在:
This is my code to check if the process name existed or not:
bool isRunning (LPCSTR processname)
{
HANDLE Snapshot;
Snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(Snapshot != INVALID_HANDLE_VALUE)
{
PROCESSENTRY32 ProcessEntry;
BOOL Succeed;
ProcessEntry.dwSize = sizeof(PROCESSENTRY32);
Succeed = Process32First(Snapshot, &ProcessEntry);
while(Succeed)
{
if(lstrcmp(ProcessEntry.szExeFile,processname) == 0)
{
return true;
}
Succeed = Process32Next(Snapshot, &ProcessEntry);
}
CloseHandle(Snapshot);
}
}
如何使用它或编辑它以从其进程名称获取窗口标题(例如notepad.exe)?如果它存在,程序将返回新文本文档 - 记事本之类的文本...我怎么能这样做?
How could I use it or edit it to get the window title from its process name (for example "notepad.exe")? If it existed the program would return text like "New text document - Notepad" ... How could I do so ?
推荐答案
你打电话给EnumWindows
遍历所有顶级窗口,然后获取每个顶级窗口的进程ID以查看它是否相同。
参见< a href =http://stackoverflow.com/questions/1888863/how-to-get-main-window-handle-from-process-id>此Stack Overflow问题 [ ^ ],作为google搜索时的第一个结果进程窗口句柄。
You callEnumWindows
to go through all top-level windows, and then get the process id for each to see if it's the same.
See this Stack Overflow question[^], found as the first result when googling "window handle from process".
这篇关于我如何从其进程名称获取窗口标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文