Главная страница | назад





Article #20123: Retrieving all Windows

Question: How can I know exactly how many windows are open?
Answer: You can use EnumWindows and EnumChildWindows to do this. The
following code sample will illistrate how to do this.
/*****************************************************************************

* BOOL EnumWindows(
* WNDENUMPROC lpEnumFunc, // pointer to callback function
* LPARAM lParam // application-defined value
* );
*
* ->Parameters
*
* -->lpEnumFunc
* Points to an application-defined callback function. For more information,
* see the EnumWindowsProc callback function.
*
* -->lParam
* Specifies a 32-bit, application-defined value to be passed to the callback
* function.
*
* BOOL EnumChildWindows(
* HWND hWndParent, // handle to parent window
* WNDENUMPROC lpEnumFunc, // pointer to callback function
* LPARAM lParam // application-defined value
* );
*
* ->Parameters
*
* -->hWndParent
* Identifies the parent window whose child windows are to be enumerated.
*
* -->lpEnumFunc
* Points to an application-defined callback function. For more information
* about the callback function, see the EnumChildProc callback function.
*
* -->lParam
* Specifies a 32-bit, application-defined value to be passed to the callback
* function.
*******************************************************************************/

#include"iostream"
#include "conio.h"
#include "winuser.h"
#pragma hdrstop
#include "condefs.h"


//---------------------------------------------------------------------------
#pragma argsused
using namespace std;

int iWindows = 0;

BOOL CALLBACK EnumChildWinProc (HWND hwnd, LPARAM lParam){
iWindows++;
return true;
}

BOOL CALLBACK EnumWinProc (HWND hwnd, LPARAM lParam){
iWindows++;
EnumChildWindows (hwnd, EnumChildWinProc, 0);
return true;
}

int main(int argc, char* argv[])
{
EnumWindows(EnumWinProc, 0);
cout << "Current Number of Windows: " << iWindows << endl;
getch ();
return 0;
}

Last Modified: 23-NOV-99