?
Solved

Get list of all avaible windows with caption

Posted on 2004-04-15
7
Medium Priority
?
350 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 100 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month7 days, 19 hours left to enroll

765 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