I want to get all the open windows on the desktop. How would I use EnumWindows()? I need the code that gets all open windows and sets them in a listbox. PLEASE HELP!
I want to get all the open windows on the desktop. How would I use EnumWindows()? I need the code that gets all open windows and sets them in a listbox. PLEASE HELP!
Website(s): http://www16.brinkster.com/trifaze/
E-mail: [email protected]
---------------------------------
C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
DirectX Version: 9.0b
DX SDK: DirectX 8.1 SDK
You need an EnumWindowsProc that'll get called for every window. If your storing the window names in a listbox you'll want to do something like this (this is pretty basic - you'll need to add some error checking) -
Then call EnumWindows with your listbox handle as the extra data from whatever event you want to trigger it -Code:BOOL CALLBACK EnumWinProc(HWND hWnd,LPARAM lParam) { HWND hListBox= (HWND)lParam; CHAR lpWinName[MAX_PATH]; GetWindowText(hWnd,lpWinName,MAX_PATH); if(strlen(lpWinName)) SendMessage(hListBox,LB_ADDSTRING, 0,(LPARAM)lpWinName); return TRUE; }
hListBox=GetDlgItem(hWnd,IDC_LIST1);
EnumWindows(EnumWinProc,(LPARAM)hListBox);
and your list box should contain the window titles. If you want to store the handles for all the windows you'll have to allocate memory in your EnumWindowsProc each time it's called, copy the handles and store the pointers somewhere (you could use LB_SETITEMDATA).
zen
ThankS!
Website(s): http://www16.brinkster.com/trifaze/
E-mail: [email protected]
---------------------------------
C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
DirectX Version: 9.0b
DX SDK: DirectX 8.1 SDK
Well, I need the created ListBox, too. cause I haven't figured it out yet. I tried:
lBox =CreateWindow(
"LISTBOX",
"",
WS_CHILD | WS_VISIBLE,
0,
0,
200,
200,
hwnd,
(HMENU)IDC_LIST1,
hInst,
NULL
);
BOOL CALLBACK EnumWinProc(HWND hWnd,LPARAM lParam);
{
lBox= (HWND)lParam;
CHAR lpWinName[MAX_PATH];
GetWindowText(hwnd,lpWinName,MAX_PATH);
if(strlen(lpWinName))
SendMessage(lBox,LB_ADDSTRING,
0,(LPARAM)lpWinName);
return TRUE;
}
lBox=GetDlgItem(hwnd,IDC_LIST1);
EnumWindows(EnumWindowsProc,(LPARAM)lBox);
but i get a linker error:
c:\my documents\enmwnd.o(.text+0x236):enmwnd.cpp: undefined reference to `EnumWindowsProc__FP6HWND__l@8'
Website(s): http://www16.brinkster.com/trifaze/
E-mail: [email protected]
---------------------------------
C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
DirectX Version: 9.0b
DX SDK: DirectX 8.1 SDK
EnumWindows() takes the pointer to your proc function (it's name), your proc function is called 'EnumWinProc' but your EnumWindows() call contains 'EnumWindowsProc'. You'll either have to change the callback functions name or put the correct name in the EnumWindows() call.
Also since you're creating the Listbox rather than putting it on a dialog with a resource editor, you already have it's handle from the CreateWindow() call so you shouldn't need to get it using GetDlgItem().
zen
The linker error is:
c:\my documents\enmwnd.o(.text+0x21e):enmwnd.cpp: undefined reference to `EnumWinProc__FP6HWND__l@8'
Code:
lBox =CreateWindow(
"LISTBOX",
"",
WS_CHILD | WS_VISIBLE,
0,
0,
200,
200,
hwnd,
(HMENU)IDC_LIST1,
hInst,
NULL
);
BOOL CALLBACK EnumWinProc(HWND hWnd,LPARAM lParam);
{
lBox= (HWND)lParam;
CHAR lpWinName[MAX_PATH];
GetWindowText(hwnd,lpWinName,MAX_PATH);
if(strlen(lpWinName))
SendMessage(lBox,LB_ADDSTRING,
0,(LPARAM)lpWinName);
return TRUE;
}
EnumWindows(EnumWinProc,(LPARAM)lBox);
Website(s): http://www16.brinkster.com/trifaze/
E-mail: [email protected]
---------------------------------
C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
DirectX Version: 9.0b
DX SDK: DirectX 8.1 SDK