Solved

Get list of all avaible windows with caption

Posted on 2004-04-15
7
339 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
Comment Utility
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
Comment Utility

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

Expert Comment

by:Ivanov_G
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 2

Author Comment

by:StTwister
Comment Utility
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
Comment Utility

   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
Comment Utility
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
Comment Utility
Never mind. I found it
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

728 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

9 Experts available now in Live!

Get 1:1 Help Now