Solved

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

Posted on 2006-06-29
1
243 Views
Last Modified: 2010-04-05
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
Comment
Question by:nikolaosk
1 Comment
 
LVL 26

Accepted Solution

by:
Russell Libby earned 250 total points
ID: 17013062
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi Yen format 3 45
How to build JSON File in Delphi 6 3 45
enhance the following code 3 37
Browsing a TTreeView in Delphi 5 9
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question