1

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?

0x90
  • 39,472
  • 36
  • 165
  • 245
  • Your best hope is some "GoogleChromeInternalClassName" (use `GetClassName` if it's good enough) – Anton Kovalenko Jan 26 '13 at 18:32
  • This is pretty much a non question. You need to specify what you want to get. Specify precisely that thing that you require. Windows and processes have all sorts of attributes. You need to decide which one you want. – David Heffernan Jan 26 '13 at 18:54
  • 1
    I want to get active application's name, don't know, which attribute it is. –  Jan 26 '13 at 18:58

1 Answers1

3

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.

Community
  • 1
  • 1
0x90
  • 39,472
  • 36
  • 165
  • 245
  • 2
    wrong language... and processname would be chrome.exe, not google chrome – thang Jan 26 '13 at 18:38
  • it is google chrome on my machine... update your chrome version and i uploaded a c code as well, thanks for the note. – 0x90 Jan 26 '13 at 18:45