Skip to content
Alexander Sklar edited this page Jan 4, 2024 · 1 revision

WIL Windowing helpers assist with various functions related to windowing.

Usage

The windowing helpers can be used by including the correct header file:

#include <wil/windowing.h>

Enumerating windows

WIL provides helpers around the EnumWindows, EnumThreadWindows and EnumChildWindows APIs:

These helpers are wil::for_each_window, wil::for_each_thread_window, and wil::for_each_child_window. They also have nothrow versions.

    // lambda can return a bool
    wil::for_each_window_nothrow([](HWND hwnd) {
        return true;
    });

    // or not return anything
    wil::for_each_window_nothrow([](HWND hwnd) {
    });

    // or return an HRESULT and we'll stop if it's not S_OK
    wil::for_each_window_nothrow([](HWND hwnd) {
        return S_FALSE;
    });

These lambdas can be mutable. In the throwing case, any exception thrown by the lambda is captured and rethrown.