GetWindowList version 1.1 Lines with a vertical bar (|) are changed from version 1.0 Overview ------------ GetWindowList is a function, written in C and exported in a dynamic link library, that creates and returns an array of window handles to active, | visible (including iconic) windows in your system. A mode parameter allows | you to control the types of windows the function returns. What you do with that list of window handles is up to you. The sample VB application, VBSWITCH, is a simple Task Switching program that demonstrates the use of the DLL function and several other interesting Windows techniques, including retrieving the window title from other active windows, and posting messages to them. Usage: (See sample application for complete implementation) ------ 'Place this in the Global.BAS code 'Remember it must live on one line... Declare Function GetWindowList Lib "Getwlst.dll" (hWndArray As Integer, | ByVal nArrayMax As Integer, ByVal nMode as Integer) As Integer | Global Const YOYO = 0 'Yer On Yer Own... | Global Const ALLVIS = 1 | Global Const TOPONLY = 2 | Global Const SAFEST = 3 'Place these in a declarations section Dim hWndArray(nRequested%) as Integer Dim nWndCnt as Integer ' The function call... nUBound = UBound(hWndArray) nWndCnt = GetWindowList( hWndArray, nUBound) Parameters: ----------- hWndArray: An array of integers. Your window handle list is returned in this array. nUBound: This can be any number less than or equal to the number of elements in the array. This tells the function when to stop filling the array with window handles and prevents wanton corruption of memory. | nMode: Is the mode specifying the volume of windows you want returned. | Mode explanation | ---------------- | YOYO(0) : Returns ALL (repeat, ALL) windows, including invisible, system, desktop | and the task which called the function (i.e. your VB app). | This mode is AKA How to Trash Windows Without Really Trying. You have | been warned. | Please note: You will probably see lots if "windows" in the list box | with a blank caption. I don't know what they are, nor where they come from. | It might provide an interesting starting leap for futher investigation, though | the leap may be straight off the edge and down. Again, you're straddling the | bleeding edge of calamity with this mode. | ALLVIS(1) : Returns all visible windows. It will return all popup windows for every running, | visible task. This includes modal and modeless dialog boxes, and any | active message boxes. | TOPONLY(2) : Returns visible TOP LEVEL windows only. (i.e. GetParent(hWnd) == NULL ) | SAFEST(3) : In SDK programming, calls to the MessageBox function take a window handle | parameter, which call be NULL, effectively making the message box a top level | window. This parameter filters out these "top level" message boxes. Return Value: ------------- An integer, the actual number of window handles found. Use this value, not nUBound, to traverse the list of window handles. Notes: ------ 1. Your hWndArray subscript must be less than 40. The DLL uses an internal static array to store the window handles before placing them in the VB array passed as a parameter. If you try to pass a number greater than 40, the DLL will simply bump you back to 40. 2. Do _not_ pass an nUBound parameter larger than the upper bound of the hWndArray. Doing so will crash your system if the actual number of active windows is greater than the number of elements in the array. 3. This function will not return the window handles of the following: The current task, the desktop, any hidden windows. | 4. If you insist on using YOYO mode (note that I _could_ have said 'If you | insist on being a YOYO,' but I didn't), make sure you set the UBound of your | window handle array quite high as you'll get back a lot more windows than | you might expect. Disclaimer ---------- The DLL itself is copyright by Todd Steinwart of Morris & Steinwart. It is provided free of charge for your use, and you may redistribute it without further consideration to Morris & Steinwart. The source for the DLL is not available. Morris & Steinwart makes no warranties, either express or implied, as to the fitness of this DLL and the functionality contained within. You use this package at your own risk. The source for VBSWITCH is hereby entered into the public domain. Credit ------ I owe a debt of gratitude to Jeffrey Richter and his book _Windows 3: A Developer's Guide_ (of course I paid B. Dalton Books almost 40 bucks for the book+disks, so overall I think we're even) for making several aspects of this little DLL quite trivial. His supplied "Voyeur" application made it quite easy to watch Windows from behind the scenes. I highly recommend this book for those who have graduated from "Petzold." It is written with the SDK programmer in mind, but many of the techniques can be used in VB. About Morris & Steinwart ------------------------ Gregg Morris (CIS 72447,1545) and Todd Steinwart (CIS 73647,1613) do consulting and contract work in the Windows arena, and specialize in C (SDK), SqlWindows, Visual Basic and Superbase programming. If you need extra hands for Windows development, drop us a line and we may be able to help. Distributed by Public (software) Library. For a catalog of more than 3000 disks of pd/shareware, call 1-800-2424-PSL or write Public (software) Library, P.O.Box 35705, Houston, TX 77235-5705.