Solved

Get list of all avaible windows with caption

Posted on 2004-04-15
7
342 Views
Last Modified: 2010-04-05
Hey experts....

I want to list on a list box all available windows and their caption... I'll also want to know how to set focus for a selected window, enable or disable it

PS: i am using delphi 4

Thanks
0
Comment
Question by:StTwister
  • 4
  • 3
7 Comments
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10834182
Here is example I found on EE :

EnumerateWindows is function that is passes with all Windows handles. Inside you can check if the windows is visible, etc, whatever you want. This procedure is called on FormClick ...

function EnumerateWindows(hWnd: HWND; lParam: LPARAM): BOOL; stdcall;
begin
  if IsWindowVisible(hWnd) then begin
    if not IsIconic(hWnd) then begin
      ShowWindow(hWnd, SW_MINIMIZE);
    end;
  end;
end;

procedure TForm1.FormClick(Sender: TObject);
begin
  EnumWindows(@EnumerateWindows, 0);
end;
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10834200

   use
     GetWindowText(hWnd, .....
   to get the Caption of the window inside EnumerateWindows...
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10834336
procedure TForm1.Button2Click(Sender: TObject);
var
  Wnd : hWnd;
  Buff: ARRAY [0..127] OF Char;
begin
  ListBox1.Clear;
  Wnd := GetWindow(Handle, gw_HWndFirst);
  while Wnd <> 0 do
    begin
      if (Wnd <> Application.Handle) and IsWindowVisible(Wnd) and
         (GetWindow(Wnd, gw_Owner) = 0) and
         (GetWindowText(Wnd, buff, sizeof(buff)) <> 0) then
        begin
          GetWindowText(Wnd, buff, sizeof(buff));
          ListBox1.Items.Add(StrPas(buff));
        end;
      Wnd := GetWindow(Wnd, gw_hWndNext);
    end;
  ListBox1.ItemIndex := 0;
end;
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 2

Author Comment

by:StTwister
ID: 10836941
Thanks a lot... that works like magic...

But i still don't know how to set focus, disable and enable a window using its handle. Hope u can help me

Thanks
0
 
LVL 12

Accepted Solution

by:
Ivanov_G earned 25 total points
ID: 10839922

   take a look at these functions in Windows SDK Help :

   BOOL SetForegroundWindow(
                                    HWND hWnd       // handle of window to bring to foreground
                                             );

   BOOL EnableWindow(  HWND hWnd,      // handle to window
                                    BOOL bEnable       // flag for enabling or disabling input
                                  );

   BOOL IsWindowEnabled(
                                    HWND hWnd       // handle of window to test
                                      );

   Or the other way to do it is via WM_ messages :

    for example
    SendMessage(hWnd, WM_NCACTIVATE, 0, 0);
0
 
LVL 2

Author Comment

by:StTwister
ID: 10845799
Ok Ivanov_G, i'll give u the points. But can u please tell me if u know how to disable the X button of a window. I'll realy appreciate that. Thanks a lot
0
 
LVL 2

Author Comment

by:StTwister
ID: 10845868
Never mind. I found it
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
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…

838 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