Solved

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

Posted on 2006-06-29
1
244 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: 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!

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

759 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