Reputation:
I've confronted with problem of getting active window's name.
When I use this code:
HWND currentWindowHWND = GetForegroundWindow();
char title[100];
GetWindowTextA(currentWindowHWND, title, 100);
I get something like: "How to get active window's name? - Stack Overflow - Google Chrome".
But I want to get "Google Chrome", which WINAPI function should I use?
Upvotes: 1
Views: 3676
Reputation: 40982
in a c
code use 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 the process name in C++
In c#
:
Int32 pid = win32.GetWindowProcessID(hwnd);
Process p = Process.GetProcessById(pid);
string appName = p.ProcessName;
You should get the process name and not the window's title.
Upvotes: 3