在Visual C++中,我越來越用獲取ProcessName從Visual C++
::GetWindowText(wnd, str, 290);
strcpy(curr_wnd_txt, str);
的當前窗口的標題,但我怎樣才能獲得例如「Iexplore在」應用程序的進程名稱爲使用Internet Explorer「 Skype「窗口與瓦片」Skype - 用戶名「,」資源管理器「使用Windows資源管理器?
這是我的嘗試:
void CMainWndDlg::Monitor_ActiveWindowCaptions()
{
HWND hwnd;
DWORD process_id=0;
GetWindowThreadProcessId(hwnd, &process_id);
CString strEXEName = GetEXEName (process_id);
}
CString GetEXEName(DWORD dwProcessID)
{
DWORD aProcesses [1024], cbNeeded, cProcesses;
unsigned int i;
if (!EnumProcesses(aProcesses, sizeof(aProcesses), &cbNeeded))
return "";
cProcesses = cbNeeded/sizeof(DWORD);
TCHAR szEXEName[MAX_PATH];
for (i = 0; i < cProcesses; i++)
{
if (aProcesses [i] == dwProcessID)
{
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ, FALSE, dwProcessID);
if (NULL != hProcess)
{
HMODULE hMod;
DWORD cbNeeded;
if(EnumProcessModules(hProcess, &hMod,
sizeof(hMod), &cbNeeded))
{
GetModuleBaseName(hProcess, hMod, szEXEName,
sizeof(szEXEName)/sizeof(TCHAR));
return CString (szEXEName);
}
}
}
}
return "";
}
你不能。連微軟都沒有。只需啓動IE和任務管理器。在「任務」選項卡中顯示IE的標題(=網頁標題),在「進程」中顯示IExplore.exe。 – MSalters
多數民衆贊成我需要。如果我可以像iexplorer.exe那樣獲取進程,那麼我可以很容易地將它顯示爲iexplorer – user1441251