How to list windows into array?

How to list windows into array?

I have no idea how to do it, could anyone point me direction?
your question is not specific enough...


store the handles into an array?...
closed account (S6k9GNh0)
@Nullable, that really isn't useful in this topic since most of the time, a program that uses more than one window either uses threads or a single process to make multiple windows as that is more effecient. Even if it didn't process walking wouldn't be useful enough to handle the windows themselves.

@rain, I'm not sure what you want. I could say, make a vector that increases on each window but I dunno what you want.
Last edited on
Like this?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <windows.h>

#define MAX_WINDOWS 1024

BOOL EnumWindowsProc(__in HWND hWnd, __in LPARAM lParam)
{
  static int  iWindowCount = 0;
  BOOL        bSuccess;

  __try {
    *(HWND*)(lParam + iWindowCount++) = hWnd;
    bSuccess = TRUE;
  }
  __except(EXCEPTION_EXECUTE_HANDLER) {
    bSuccess = FALSE;
  }
  return bSuccess;
}

int __cdecl wmain(__in int argc, __in_ecount_z_opt(argc) WCHAR* __wargv[], __in_z_opt WCHAR* __wenviron[])
{
  UNREFERENCED_PARAMETER(argc);
  UNREFERENCED_PARAMETER(__wargv);
  UNREFERENCED_PARAMETER(__wenviron);

  HWND  hWindows[MAX_WINDOWS];
  int   i;
  BOOL  bRet;

  bRet = EnumWindows((WNDENUMPROC)EnumWindowsProc, (LPARAM)hWindows);

  if(bRet)
  {
    // do stuff with hWindows
  }

  getwchar();
  return (bRet ? EXIT_SUCCESS : EXIT_FAILURE);
}
Topic archived. No new replies allowed.