Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 255
  • Last Modified:

how to retrieve the captions of all open windows that belong to certain class+delphi

hi there

i need a function in delphi where i can pass as a parameter the name of a class e.g

ExploreWClass and CabinetWClass, and get a result back as a string of all the window captions that belong to this class.

for example

if two folder windows are open in my desktop

1) C:\Documents and Settings\user\Desktop\delphi
2) C:\Documents and Settings\user\Desktop\websites

i want the fuction to return me the following:

result=C:\Documents and Settings\user\Desktop\delphiC:\Documents and Settings\user\Desktop\websites

if 5 windows of a certain class are open i need as a result the concatenation of all these window captions

i have some code below. hope it helps

thanks

function Get_foldercaption(const thestring: WideString): WideString;
var
  foldercaption:cardinal;
  foldercaptiontext,foldercaptiontext1:array[0..255] of char;

begin
     
     //ExploreWClass and CabinetWClass should not be hardcoded like here but passed as parameters in the function
      foldercaption := FindWindow('ExploreWClass', nil);
      //foldercaption1 := FindWindow('CabinetWClass', nil);
      GetWindowText (foldercaption, foldercaptiontext, 256);
      Result := foldercaptiontext
     
End;
0
nikolaosk
Asked:
nikolaosk
1 Solution
 
Russell LibbySoftware Engineer, Advisory Commented:
type
  PEnumClass        =  ^TEnumClass;
  TEnumClass        =  packed record
     ClassName:     String;
     ResultList:    TStringList;
  end;

function EnumClassWindows(Window: HWND; lParam: PEnumClass): BOOL; stdcall;
var  lpBuffer:      Array [0..1024] of Char;
     dwSize:        DWORD;
begin

  dwSize:=GetClassName(Window, @lpBuffer, SizeOf(lpBuffer));
  if (dwSize > 0) then
  begin
     lpBuffer[dwSize]:=#0;
     if (StrIComp(@lpBuffer, PChar(lParam^.ClassName)) = 0) then
     begin
        dwSize:=GetWindowText(Window, @lpBuffer, SizeOf(lpBuffer));
        if (dwSize > 0) then
        begin
           lpBuffer[dwSize]:=#0;
           lParam^.ResultList.Add(lpBuffer);
        end;
     end;
  end;
  result:=True;
 
end;

function GetClassWindows(WindowClass: WideString): WideString;
var  lpEnum:        TEnumClass;
begin

  lpEnum.ResultList:=TStringList.Create;
  try
     lpEnum.ClassName:=WindowClass;
     if (Length(lpEnum.ClassName) > 0) then EnumWindows(@EnumClassWindows, Integer(@lpEnum));
     result:=StringReplace(lpEnum.ResultList.Text, #13#10, '', [rfReplaceAll]);
  finally
     lpEnum.ResultList.Free;
  end;

end;

  ShowMessage(GetClassWindows('CabinetWClass'));

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now