Solved

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

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now