如何获得活动窗口的名字吗? [英] How to get name of active window?
本文介绍了如何获得活动窗口的名字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我面临着越来越积极的窗口名称的问题。
I've confronted with problem of getting active window's name.
当我用这个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".
但我要得到谷歌浏览器,这WINAPI功能我应该使用?
But I want to get "Google Chrome", which WINAPI function should I use?
推荐答案
在 C
code。使用以下WINAPI功能:
in a c
code use the following winapi functions:
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
);
在 C#
:
Int32 pid = win32.GetWindowProcessID(hwnd);
Process p = Process.GetProcessById(pid);
string appName = p.ProcessName;
这篇关于如何获得活动窗口的名字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文