Una alternativa, si no quieres modificar TODOS los formularios de la aplicación para añadirles código, como ha indicado [ecfisa], por ejemplo porque tu aplicación tiene 200 formularios, es realizar un hook sobre el mensaje de creación de ventanas.
En este
código de Rodrigo, por ejemplo, se instala el gancho utilizando
WH_CBT.
Siguiendo esa misma idea, puedes colocar en el formulario principal el siguiente código:
Código Delphi
[-]
function GetWindowClassName(Handle: THandle): String;
var
Buffer: array[0..MAX_PATH] of WideChar;
begin
GetClassName(Handle, @Buffer, MAX_PATH);
Result := String(Buffer);
end;
function CBT_FUNC(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
const
ClassNameBufferSize = 1024;
var
LHWND : HWND;
classname:string;
begin
Result := CallNextHookEx(hhk, nCode, wParam, lParam);
if nCode<0 then exit;
if nCode = HCBT_CREATEWND then begin
LHWND := HWND(wParam);
if (LHWND>0) then begin
classname := GetWindowClassName(wParam);
OutputDebugString(PChar(FormatDateTime('hh:mm:ss', now) + ' - ' + ClassName));
end;
end;
end;
Procedure InitHook();
begin
hhk := SetWindowsHookEx(WH_CBT, @CBT_FUNC, hInstance, GetCurrentThreadId);
if hhk=0 then RaiseLastOSError;
end;
Procedure FinHook();
begin
if (hhk <> 0) then
UnhookWindowsHookEx(hhk);
end;
initialization
InitHook();
finalization
FinHook();
Cuando se creea el fomrulario principal se crea el hook. Y cada vez que se crea un formulario se llamará a la función
CBT_FUNC.
Ahi se hacen unas comprobaciones y se accede a la clase del formulario.
El resultado en este ejemplo se visualiza en los eventos utilizando
OutputDebugString. Para visualizarlos puedes usar la ventana
"Event Log" desde el IDE o alguna herramienta tipo
DebugView, si ejecutas desde fuera.
Si desde tu aplicación abres estos formularios:
Deberías ver un Log como este: