Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

[c#.net 2.0] EnumWindows?

Well, it's been a long time since I've been here, and since then I migrated from VB.net (2.0) to C#.net, which I enjoy programming in much more...
However, I can't yet implement this callback function (whatever it is, I couldn't find any working method to use it) EnumWindows to get all active applications (like in the Applications tab of the Windows Taskmanager) and add them to a Listbox control.
So if my Listbox control were lbWindows, and the array for the handles would be handlesArray, how would I do it? :confused:
[551 byte] By [geertvdijk] at [2007-11-11 9:42:01]
# 1 Re: [c#.net 2.0] EnumWindows?
Did you try Google? http://www.google.com/search?q=c%23+enumwindows
Phil Weber at 2007-11-11 21:45:32 >
# 2 Re: [c#.net 2.0] EnumWindows?
Did you try Google? http://www.google.com/search?q=c%23+enumwindows
I most certainly did, I just didn't find anything I understood, including MSDN pages...
geertvdijk at 2007-11-11 21:46:38 >
# 3 Re: [c#.net 2.0] EnumWindows?
Please take a look at this sample and tell us what you don't understand: http://www.codeproject.com/csharp/runninginstanceie.asp
Phil Weber at 2007-11-11 21:47:32 >
# 4 Re: [c#.net 2.0] EnumWindows?
First thing:
How do I add the handles from the windows it finds in an array?
I can't do that from within the static, at least, I cant...
Second thing:
How do I check it are windows it lists, and nothing else?
I read something about that in MSDN tho, so I'll dive that up myself...
geertvdijk at 2007-11-11 21:48:30 >
# 5 Re: [c#.net 2.0] EnumWindows?
I'm not sure I understand your questions. Are you asking how to add the window handles to an array, or how to add the contents of an array to a listbox? Why are using an array at all? Why not simply add the window information directly to a listbox, as shown in the example?

As its name implies, EnumWindows enumerates windows, so everything it returns is by definition a window. Are you asking how to ensure that only top-level windows are added to the list?
Phil Weber at 2007-11-11 21:49:34 >
# 6 Re: [c#.net 2.0] EnumWindows?
I'm not sure I understand your questions. Are you asking how to add the window handles to an array, or how to add the contents of an array to a listbox? Why are using an array at all? Why not simply add the window information directly to a listbox, as shown in the example?

As its name implies, EnumWindows enumerates windows, so everything it returns is by definition a window. Are you asking how to ensure that only top-level windows are added to the list?
I'm not sure, but basically, when I use the function, I get a list with all kinds of stuff, that also look like controls... However, now that I thought about it, it may also be MDI childs or whatsoever... I'm not quite sure... But in that case, I should indeed only get top-level windows...
And I store it in an array because I already have got some code that gets the window preview with PrintWindow() with the handle, so I think an array or list would be useful, since I do not only want to list it all...
geertvdijk at 2007-11-11 21:50:38 >
# 7 Re: [c#.net 2.0] EnumWindows?
Well, nevermind, I've got it now, using a List (similar/equal to arraylist?) and a listbox, and some code which I somehow found through google after another deep search. I'm gonna clean up the code tomorrow, and add an alt-tab 'catcher' to it, and publish it open source somewhere... My goal is to make it better than the WinXP alttab powertoy, so I'll need other peoples coding as well. Thanks for the work tho.
geertvdijk at 2007-11-11 21:51:34 >