visual c++ - how to use window title to get process id,and process name -
i process id , process name via using window title develop environment visual c++ 2008
how it.
thanks
hwnd hw = findwindow(null, l"window title"); if (hw) { dword dwprocessid = 0; dword dwthreadid = getwindowthreadprocessid(hw, &dwprocessid); handle hprocess = openprocess(process_query_information, false, dwprocessid); if (hprocess) { wchar_t *szexename[1024] = {0}; if (queryfullprocessimagename(hprocess, 0, szexename, _countof(szexename)) { // ... } closehandle(hprocess); } }
you should use class argument (the 1 null in first line) if know it, less accidentally find other program's window happens have same title.
of course, class name not guaranteed unique between programs either, combination more reliable using title itself.
you can window class using spy++.
edit: queryfullprocessimagename requires vista, can swap line 1 uses getprocessimagefilename per drej's answer.
edit2: if you're not compiling unicode, remove "l" before "window title" , use char buffer instead of wchar_t.
Comments
Post a Comment