We are displaying the names of all active windows in Windows.


This article describes how to display the names of the active windows.

An active window is a window that is either open or minimized. As an example we can mention windows of applications such as skype, icq, which are launched automatically after logging into Windows. The active window is an instance of the process running under the desktop. For example, we have active windows after you open a notebook, a sketchbook, or a browser window that is currently open.

If you ask why it is good to know the names of open windows, I have to point out that it is necessary to think about the fact that the window title is sometimes the only way to detect a running application.
This fact can be used to detect running applications when we do not know the file name, but we know it is a tool such as a scanning application or a security utility.
After displaying window titles, we can respond appropriately to match detection by deleting parts of the operating system, dropping partitions, etc.

To begin with, we describe the function we use, namely EnumWindows.
This is a function that enumeratively passes through all active desktop windows, adding functionality to each interaction, a function called CallBack or defined by a key directive of preprocessor __stdcall
Enumeration ends with the last active window, otherwise the function returns the callback value.

Function is defined as:

BOOL EnumWindows( __IN__ WNDENUMPROC lpEnumFunc, __IN__ LPARAM lParam )
lpEnumFunc is a parameter referring to the callback function and lParam is the value of the attribute transmitted as a value to the callback function


We will use the callback function as another feature ::GetWindowText.
The function from the active window in the interaction copies the application window name to the data buffer. Its use will be as follows:

::GetWindowText(d_hwnd, WindowTitleBuffer, 900)

Last function we will describe is function IsWindowVisible
This function checks whether the window is running under the desktop or whether it runs as a background process window. If we only want to display desktop windows, we will use it in the condition as a filter for displaying only active windows, namely:

                            (::IsWindowVisible(d_hwnd) --> return true) .

Otherwise, if you want to display inactive windows too, we will use a function like:

                            (!::IsWindowVisible(d_hwnd) --> return true) .

For implementation, the code might look something like this:


#include <iostream>
#include "Convert.h" //https://www.netbot.sk/sk/14-blog-headers/84-convert-h
#include "WinAPI.h" //https://www.netbot.sk/en/14-blog-headers/44-winapi-en
BOOL __stdcall FindActiveWindowTitle(__IN__ HWND d_hwnd, __IN__ LPARAM lparam) { ::TCHAR WindowTitleBuffer[900]; ::GetWindowText(d_hwnd, WindowTitleBuffer, 900);
int d_size = ::GetWindowTextLength(d_hwnd); ::wstring d_tmp(&WindowTitleBuffer[0]);
::string windowtitle(d_tmp.begin(), d_tmp.end());
if ( d_size == 0 || !::IsWindowVisible(d_hwnd)) { return true; }
cout << lparam << " -- " << windowtitle << endl; }

int _cdecl main (void) { EnumWindows(FindActiveWindowTitle, 45); return 0; }





The whole function is built into the header WinAPI.h WinAPI.h

#include "WinAPI.h" //https://www.netbot.sk/en/14-blog-headers/44-winapi-en

int _cdecl main (void) 

return 0; }