Solved

Get list of all avaible windows with caption

Posted on 2004-04-15
7
347 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
Technology Partners: 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

Independent Software Vendors: 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!

Question has a verified solution.

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

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…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

726 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