Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / December 2004

Tip: Looking for answers? Try searching our database.

WindowEnumerator

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
carlmanaster - 27 Dec 2004 19:05 GMT
My application has regular document windows and floating windows above
them.  I want to iterate through all windows in z-order.  I would have
thought this capability would be built-in to the .net framework, but
everything I can find on the archives says no - you need to use
GetWindow(), thus:

[DllImport("user32", EntryPoint="GetWindow")]
private static extern int GetWindow(int hwnd, int wFlag);

And the most logical thing seems to me to be to create a class that
implements the IEnumerator interface.  I suspect I need an additional
external function - maybe GetTopWindow? to get a starting point; call
that in .Reset() and GetWindow() in .MoveNext().  Am I on the right
track?  Can anyone provide examples of how to call these functions, eg
what arguments to pass to them, how to coerce their result types into
System.Windows.Forms, how to tell when I've reached the end?  Thanks in
advance.

Peace,
--Carl
MuZZy - 27 Dec 2004 21:49 GMT
> My application has regular document windows and floating windows above
> them.  I want to iterate through all windows in z-order.  I would have
[quoted text clipped - 16 lines]
> Peace,
> --Carl

I'd start from looking at one of the examples on the inet, like this:

http://www.codeproject.com/csharp/popupkiller.asp

It shows working with different windows ona popup killer example.

Andrey
carlmanaster - 28 Dec 2004 19:24 GMT
I've got a class that seems to do the trick.  I started with Taylor
Wood's class, here:

<http://www.thecodeproject.com/csharp/windowhider.asp>

and pared it down to just what I wanted; it seems to be working fine.
Enjoy.

using System;
using System.Runtime.InteropServices;
using System.Collections;
using System.Windows.Forms;

namespace Whatever
{
/// <summary>
/// Collection of Forms visible in this application,
/// in current z-order (front to back)
/// </summary>
/// <example>
///    foreach (Form form in new WindowList())
///        {
///        // process forms as needed
///        }
/// </example>

public class WindowList : IEnumerable, IEnumerator
{
[DllImport("user32.dll")]
private static extern int EnumWindows(ewProc ewp, int lParam);

public delegate bool ewProc(int hWnd, int lParam);

private int currentIndex = -1;
private ArrayList windows = new ArrayList();

public WindowList()
{
EnumWindows(new ewProc(AddWindow), 0);
}

private bool AddWindow(int hWnd, int lParam)
{
Control form = Form.FromHandle((IntPtr)hWnd);
if (form != null && form.Visible)
windows.Add(form);
return true;
}

public IEnumerator GetEnumerator()
{
return (IEnumerator)this;
}
public bool MoveNext()
{
currentIndex++;
return currentIndex < windows.Count;
}
public void Reset()
{
currentIndex = -1;
}
public object Current
{
            get
                {
                return windows[currentIndex];
                }
            }
        }
    }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.