根据HWND获取进程名字
#include <string>
#include <windows.h>
#pragma comment(lib, "user32.lib")
#include <Tlhelp32.h>
#pragma comment(lib, "Kernel32.lib")
using namespace std;
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;
}#include <string>
#include <w