Click here to Skip to main content
15,902,635 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my code to check if the process name existed or not:
C++
bool isRunning (LPCSTR processname)
{
    HANDLE Snapshot;
    Snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

    if(Snapshot != INVALID_HANDLE_VALUE)
    {
        PROCESSENTRY32 ProcessEntry;
        BOOL           Succeed;
        ProcessEntry.dwSize = sizeof(PROCESSENTRY32);
        Succeed = Process32First(Snapshot, &ProcessEntry);

        while(Succeed)
        {
          if(lstrcmp(ProcessEntry.szExeFile,processname) == 0)
          {
           return true;
          }
      Succeed = Process32Next(Snapshot, &ProcessEntry);
    }

    CloseHandle(Snapshot);
    }
}


How could I use it or edit it to get the window title from its process name (for example "notepad.exe")? If it existed the program would return text like "New text document - Notepad" ... How could I do so ?
Posted

1 solution

You call EnumWindows to go through all top-level windows, and then get the process id for each to see if it's the same.

See this Stack Overflow question[^], found as the first result when googling "window handle from process".
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900