Listing 3: Client program that demonstrates the use of child_window_sequence in an STL-compliant fashion.

#include <stlsoft_simple_algorithms.h>
#include <winstl_window_functionals.h>
#include <winstl_string_access.h>

struct trace_text
  : public std::unary_function<HWND, void>
{
  void operator ()(HWND hwnd)
  {
    // Print out the window handle, and the caption.
    printf("0x%08x: \"%s\"\n", hwnd,
           static_cast<char const*>(winstl::c_str_ptr(hwnd)));
  }
};
int main()
{
  child_window_sequence wnds(::GetDesktopWindow());
  // (i) Use in explicit loop
  child_window_sequence::const_iterator begin(wnds.begin());
  child_window_sequence::const_iterator end(wnds.end());
  for(; begin != end; ++begin)
  {
    if(is_visible()(*begin))
    {
      trace_text()(*begin);
    }
  }
  // (ii) Use via algorithm
  stlsoft::for_each_if( wnds.begin(), wnds.end(), trace_text(), is_visible());
}