Window Name to ProcessID

Posts 1–10 of 10 · Page 1 of 1
Window Name to ProcessID
I'm looking for a method to take a window name, and convert it to a PID. Any help you have give would be appreciated. Thanks!

- CN
Window name meaning the caption or the executable?
Either one will work fine.
Caption:
[php]
DWORD GetProcessIDByCaption(char* name)
{
HWND hwnd = FindWindow(0,name);
if(!hwnd)
return NULL;

DWORD pid;
GetWindowThreadProcessId(hwnd,&pid);

return pid;
}

[/php]

Executable:
[php]
DWORD GetProcessIDByExecutable(char* name)
{
PROCESSENTRY32 Pe;
Pe.dwSize = sizeof( PROCESSENTRY32 );

HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPALL,NULL);

Process32First(snapshot,&Pe);
do {
if( !strcmp(Pe.szExeFile,name) )
return Pe.th32ProcessID;

} while(Process32Next(snapshot,&Pe));

return NULL;
}
[/php]
What the hell...i spent for ever writing a long ass code to find out void writes it in like 10 lines! LOL!
Quote Originally Posted by CoderNever View Post
What the hell...i spent for ever writing a long ass code to find out void writes it in like 10 lines! LOL!
I'm just cool like that.
dang, i am reading a book on winapi, and it's making no sense i don't know how u guys do it, i have already spent a year on the basics so i know the basics don't worry, it's just the whole winapi idea makes no sense.
Windows API is ftw.
what is "ftw"?
Quote Originally Posted by 258456 View Post
what is "ftw"?
Fuck Those Women.

edit by hell: no void... it's For The Win...
(lol fake edit)
Posts 1–10 of 10 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us