|
-
September 13th, 2008, 08:22 PM
#1
listing application windows
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
Last edited by Mitsukai; September 14th, 2008 at 02:47 AM.
-
September 13th, 2008, 09:48 PM
#2
Re: application?
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;
}
-
September 14th, 2008, 02:35 AM
#3
Re: application?
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;
}
-
September 14th, 2008, 05:38 AM
#4
Re: application?
 Originally Posted by Mitsukai
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...
-
September 14th, 2008, 12:28 PM
#5
Re: application?
 Originally Posted by Laurentis
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.
-
September 14th, 2008, 01:43 PM
#6
Re: application?
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
-
September 14th, 2008, 02:06 PM
#7
Re: application?
You can filter by Window styles as well.
Try adding the following to the filter
Code:
!( GetWindowLong( hWnd, GWL_STYLE ) & WS_CAPTION )
-
September 14th, 2008, 02:22 PM
#8
Re: application?
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..
Last edited by Mitsukai; September 14th, 2008 at 05:01 PM.
-
September 15th, 2008, 06:35 PM
#9
Re: application?
i have this code:
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
-
September 15th, 2008, 07:00 PM
#10
Re: application?
Comment out the icon code and check if you are getting the proper top level application windows first.
-
September 15th, 2008, 07:27 PM
#11
Re: application?
yes i do get the right top level applications. the text under the icons show that
-
September 15th, 2008, 07:36 PM
#12
Re: application?
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.
-
September 15th, 2008, 08:20 PM
#13
Re: application?
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..
-
September 15th, 2008, 09:51 PM
#14
Re: application?
ok fixed.
Code:
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
-
September 15th, 2008, 10:59 PM
#15
Re: application?
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|