im using enumwindows to search for application windows.
how can i tell if the window is an application window.
Like the windows that appear in task manager.
thanks
Printable View
im using enumwindows to search for application windows.
how can i tell if the window is an application window.
Like the windows that appear in task manager.
thanks
Pretty useless post title.
Code:BOOL CALLBACK EnumWindowsProc(HWND hwnd, DWORD lParam)
{
if (::GetWindow(hwnd, GW_OWNER ) || !::IsWindowVisible(hwnd))
{
// not a top level window or not visible, continue enumeration
return TRUE;
}
//
// Do something with the application hWnd
//
return TRUE;
}
thank you arjay... that was kinda simple.
i have two questions:
1. why does "Program Manager" window appear in the list?
2. how come i only get the valid icon from explorer.exe? (im sure it comes from GetClassLong)
Code:BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam)
{
if(::GetWindow(hWnd, GW_OWNER) || !::IsWindowVisible(hWnd))
return TRUE;
CFMain::CAppView* This = reinterpret_cast<CFMain::CAppView*>(lParam);
HICON hIcon = (HICON)::GetClassLong(hWnd, GCL_HICON);
int iX = This->ImageList.Add(hIcon);
if(iX > -1)
{
HICON hIconSm = (HICON)::GetClassLong(hWnd, GCL_HICONSM);
if(!hIconSm)
hIconSm = hIcon;
This->ImageListSmall.Add(hIconSm);
}
LPTSTR sText = NULL;
int iY = ::GetWindowTextLength(hWnd) + 1;
if(iY > 0)
{
sText = new TCHAR[iY];
::GetWindowText(hWnd, sText, iY);
}
This->InsertItem(reinterpret_cast<int>(hWnd), sText, iX);
if(sText)
delete[] sText;
return TRUE;
}
Because this method is wrong.Quote:
Originally Posted by Mitsukai
See win32 api forums where the right method has been posted hundreds of times...
How about you help a brother out and post the correct solution? Referring another forum without a link isn't much help. Thanks.Quote:
Originally Posted by Laurentis
The ***? ofcors i know something is wrong ya dik head, dats why i come to dese forums. U must be the smartest @ home. Thnx for yer help laurentis
You can filter by Window styles as well.
Try adding the following to the filter
Code:!( GetWindowLong( hWnd, GWL_STYLE ) & WS_CAPTION )
thats a good idea, i will try right away
hmm i got some other problems now so i cant test yet T_T
ok the "Program Manager" now is gone. by cleverly checking if the window has a caption... however what if the window has no WS_CAPTION and draws itself, it can still be an application window...
and somehow for some windows i cannot retrieve the icon and it displays the wrong icon..
i have this code:
somehow i dont get the right icon for every application... please help me X_XCode:if(::GetWindow(hWnd, GW_OWNER) || !::IsWindowVisible(hWnd) || !(::GetWindowLong(hWnd, GWL_STYLE) & WS_CAPTION))
return TRUE;
CView* This = reinterpret_cast<CView*>(lParam);
HICON hIcon = (HICON)::GetClassLong(hWnd, GCL_HICON);
HICON hIconSm = (HICON)::GetClassLong(hWnd, GCL_HICONSM);
if(!hIcon)
hIcon = hIconSm;
if(!hIconSm)
hIconSm = hIcon;
int iX = This->ImageList.Add(hIcon);
This->ImageListSmall.Add(hIconSm);
LPTSTR sText = NULL;
int iY = ::GetWindowTextLength(hWnd) + 1;
if(iY > 0)
{
sText = new TCHAR[iY];
::GetWindowText(hWnd, sText, iY);
}
This->InsertItem(reinterpret_cast<int>(hWnd), sText, iX);
if(sText)
delete[] sText;
return TRUE;
Comment out the icon code and check if you are getting the proper top level application windows first.
yes i do get the right top level applications. the text under the icons show that
The way you are adding and storing the icons seems a bit suspect.
Step through the code and make sure an icon is available for each application. The make sure the index into the image list that you store with the app is correct.
well i found out GetClassLong returns NULL for both GCL_HICON and HICONSM, i already thought of that... so there must be a diffrent way of getting the icons..
ok fixed.
now i need to either prevent from my own application appearing in the list or fix the icon from my own application.... somehow my own application icon does not work and the other applciation icons do work. maybe because i put HINSTANCE off my window class to the EXE instance, and im doing doing this inside a DLL. im not sureCode:CView* This = reinterpret_cast<CView*>(lParam);
if(::GetWindow(hWnd, GW_OWNER) || !::IsWindowVisible(hWnd) || !(::GetWindowLong(hWnd, GWL_STYLE) & WS_CAPTION))
return TRUE;
HICON hIcon = (HICON)::SendMessage(hWnd, WM_GETICON, ICON_BIG, 0);
if(!hIcon)
hIcon = (HICON)::GetClassLong(hWnd, GCL_HICON);
HICON hIconSm = (HICON)::SendMessage(hWnd, WM_GETICON, ICON_SMALL, 0);
if(!hIconSm)
hIconSm = (HICON)::GetClassLong(hWnd, GCL_HICONSM);
int iX = -1;
iX = This->ImageList.Add(hIcon ? hIcon : hIconSm);
This->ImageListSmall.Add(hIconSm ? hIconSm : hIcon);
LPTSTR sText = NULL;
int iY = ::GetWindowTextLength(hWnd) + 1;
if(iY > 0)
{
sText = new TCHAR[iY];
::GetWindowText(hWnd, sText, iY);
}
This->InsertItem(reinterpret_cast<int>(hWnd), sText, iX);
if(sText)
delete[] sText;
return TRUE;
Use GetWindowThreadProcessId api inside the callback. You can compare the process id from the current window with the one from your application and exclude it from the list if it matches.