我遇到了获取活动窗口名称的问题。
当我使用此代码时:
HWND currentWindowHWND = GetForegroundWindow();
char title[100];
GetWindowTextA(currentWindowHWND, title, 100);
我得到的信息是:“如何获取活动窗口的名称?”?-堆栈溢出-Google Chrome”。
但是我想得到“Google Chrome”,我应该使用哪个WINAPI函数?
最佳答案
在c
代码中,使用以下winapi函数:
DWORD WINAPI GetModuleFileName(
_In_opt_ HMODULE hModule,
_Out_ LPTSTR lpFilename,
_In_ DWORD nSize
);
或
DWORD WINAPI GetModuleBaseName(
_In_ HANDLE hProcess,
_In_opt_ HMODULE hModule,
_Out_ LPTSTR lpBaseName,
_In_ DWORD nSize
);
How to get the process name in C++
在
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.