Solved

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

Posted on 2006-06-29
1
240 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Strange code, can use it, but i cant figure out what it does. 3 60
FMX enumerated colours 2 99
Working with hours 3 57
Dev express lookupcombo 3 27
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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