How to get the name of the active window?

I ran into the problem of getting the active window name.

When I use this code:

HWND currentWindowHWND = GetForegroundWindow();
char title[100];
GetWindowTextA(currentWindowHWND, title, 100);

I get something like: "How do I get the active window name? - Stack overflow - Google Chrome."

But I want to get "Google Chrome", which WINAPI function to use?

+1
source share
1 answer

in the code, cuse the following winapi functions:

DWORD WINAPI GetModuleFileName(
  _In_opt_  HMODULE hModule,
  _Out_     LPTSTR lpFilename,
  _In_      DWORD nSize
);

or

DWORD WINAPI GetModuleBaseName(
  _In_      HANDLE hProcess,
  _In_opt_  HMODULE hModule,
  _Out_     LPTSTR lpBaseName,
  _In_      DWORD nSize
);

How to get process name in C ++


In c#:

Int32 pid = win32.GetWindowProcessID(hwnd);
Process p = Process.GetProcessById(pid);
string appName = p.ProcessName;

You should get the name of the process, not the window title.

+3
source

Source: https://habr.com/ru/post/1530266/


All Articles