Click to See Complete Forum and Search --> : application?
Mitsukai
September 13th, 2008, 08:22 PM
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
Arjay
September 13th, 2008, 09:48 PM
Pretty useless post title.
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;
}
Mitsukai
September 14th, 2008, 02:35 AM
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)
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;
}
Laurentis
September 14th, 2008, 05:38 AM
1. why does "Program Manager" window appear in the list?
Because this method is wrong.
See win32 api forums where the right method has been posted hundreds of times...
Arjay
September 14th, 2008, 12:28 PM
Because this method is wrong.
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.
Mitsukai
September 14th, 2008, 01:43 PM
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
Arjay
September 14th, 2008, 02:06 PM
You can filter by Window styles as well.
Try adding the following to the filter
!( GetWindowLong( hWnd, GWL_STYLE ) & WS_CAPTION )
Mitsukai
September 14th, 2008, 02:22 PM
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..
Mitsukai
September 15th, 2008, 06:35 PM
i have this code:
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;
somehow i dont get the right icon for every application... please help me X_X
Arjay
September 15th, 2008, 07:00 PM
Comment out the icon code and check if you are getting the proper top level application windows first.
Mitsukai
September 15th, 2008, 07:27 PM
yes i do get the right top level applications. the text under the icons show that
Arjay
September 15th, 2008, 07:36 PM
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.
Mitsukai
September 15th, 2008, 08:20 PM
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..
Mitsukai
September 15th, 2008, 09:51 PM
ok fixed.
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;
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 sure
Arjay
September 15th, 2008, 10:59 PM
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.
Mitsukai
September 16th, 2008, 10:39 AM
ok this is my final code:
i dint add the ProccessId check yet tho.
completly resolved. thanks for your help arjay!
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 = GView.ImageList.Add(hIcon ? hIcon : hIconSm);
if(iX < 0)
return TRUE;
GView.ImageListSmall.Add(hIconSm ? hIconSm : hIcon);
LPTSTR sText = NULL;
int iY = ::GetWindowTextLength(hWnd) + 1;
if(iY > 1)
{
sText = new TCHAR[iY];
::GetWindowText(hWnd, sText, iY);
}
iY = GView.InsertItem(sText, iX);
if(iY >= 0)
if(::IsHungAppWindow(hWnd))
GView.SetItem(iY, 1, "Hanging");
else
GView.SetItem(iY, 1, "Running");
if(sText)
delete[] sText;
return TRUE;
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.