您的位置:首页 > 编程语言 > PHP开发

由hwnd得到进程名 :GetProcessNameByHandle(HWND nlHandle)

2014-05-08 15:34 771 查看
wstring GetProcessNameByHandle(HWND nlHandle)

{
wstring loStrRet=L"";
//得到该进程的进程id
DWORD ldwProID;
GetWindowThreadProcessId(nlHandle,&ldwProID);
if(0==ldwProID)
return L"";
HANDLE handle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(handle==(HANDLE)-1) 
{

//AfxMessageBox(L"CreateToolhelp32Snapshot error");
return false;
}
PROCESSENTRY32 procinfo;
procinfo.dwSize = sizeof(PROCESSENTRY32);
BOOL more=::Process32First(handle,&procinfo);
while(more)
{
if(procinfo.th32ProcessID==ldwProID)
{
loStrRet=procinfo.szExeFile;
CloseHandle(handle);
return loStrRet;
}
more=Process32Next(handle,&procinfo); 
}
CloseHandle(handle);
return loStrRet;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐