Solved

Get list of all avaible windows with caption

Posted on 2004-04-15
7
345 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
[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
  • 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
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!

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

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 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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

730 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