AdaPower Logged in as Guest
Ada Tools and Resources

Ada 95 Reference Manual
Ada Source Code Treasury
Bindings and Packages
Ada FAQ


Join >
Home >
Articles >
Getting Started >
Ada FAQ >
Source Treasury >
Books & Tutorials >
Packages for Reuse >
Latest Additions >
Ada Projects >
Press Releases >
Ada Audio / Video >
Home Pages >
Links >
Contact >
About >
Login >
Back
Using EnumWindows (Kevin Radke)

with Win32;
with Win32.Windef;

package Callbacks is
  function EnumProc (hwnd   : Win32.Windef.HWND;
                     lParam : Win32.LPARAM) return Win32.BOOL;
  pragma convention (STDCALL, EnumProc);
end Callbacks;

with Win32;
with Win32.Windef;
with Win32.Winuser;
with Interfaces.C;
with Text_IO;

package body Callbacks is
  use type Win32.Int;
  
  -- The function will be called for each top level window
  function EnumProc (hwnd   : Win32.Windef.HWND;
                     lParam : Win32.LPARAM) return Win32.BOOL is
    nb :  Win32.INT := 0;
    buffer : Win32.Char_Array(1..200);
  begin
    nb := Win32.WinUser.GetClassName (hwnd,
                                      Win32.Addr(buffer),
                                      buffer'Length);
    if nb /= 0 then
      Text_IO.Put_Line ("ClassName = '" &
                        Interfaces.C.To_Ada(Win32.To_C(buffer)) &
                        "'");
    end if;
       
    return Win32.TRUE;
  end EnumProc;
end Callbacks;

with Win32;
with Win32.WinUser;
with Callbacks;

procedure Test_EnumWindows is
  res : Win32.BOOL := 0;
begin
  -- Let's start enumeration of the windows
  res := Win32.WinUser.EnumWindows
           (lpEnumFunc => Callbacks.EnumProc'Access,
            lParam     => Win32.LPARAM (0));
end Test_EnumWindows;


(c) 1998-2004 All Rights Reserved David Botton