Wednesday, June 27, 2012

GET WINDOWS CAPTION

function EnumWindowsProc(Handle: HWND; LParam : DWord): bool; stdcall;
var
    WinStyles : DWord;
    TextLen : integer;
    TextStr : string;
    WinClassName: array[0..100] of char;
begin
    Result := true;
    {get the window styles value}
    WinStyles := GetWindowLong(Handle, GWL_STYLE);
    {check for a visible bit in windows style}
    if ((WinStyles and WS_VISIBLE) > 0) then begin // its a visible    window
    {get the length of the windows caption ...}
        TextLen := SendMessage(Handle, WM_GETTEXTLENGTH, 0, 0);
        {... and set the string appropriately}
        SetLength(TextStr, TextLen);
        {get the windows caption}
        SendMessage(Handle, WM_GETTEXT, TextLen + 1,
        integer(PChar(TextStr)));
        {get the windows class name}
        GetClassName(Handle, WinClassName, 100);
        {put "window_text (window_class)" in TMemo}
        {typecast the LParam you passed in EnumWindows to a TStrings for
        use}
        TStrings(LParam).Add(TextStr + ' (' + WinClassName + ')');
    end; {if ((WinStyles and WS_VISIBLE) > 0)}
end;

procedure TForm1.GetWindowsList;
begin
    Memo1.Clear;
    EnumWindows(@EnumWindowsProc,integer(Memo1.Lines));
end;

0 comments:

Post a Comment

 
Related Posts Plugin for WordPress, Blogger...