Jump to content
  • Advertisement
Sign in to follow this  
Jedive

[WINAPI] Getting the desktop windows

This topic is 4813 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to get the list of currently opened windows on the desktop. I am doing it with EnumWindows(). The problem is that, instead of returning handles to the windows that I can see on the desktop, I get the handle of hundreds of windows. I guess that they are invisible windows or something created by the OS for different purposes. How can I get JUST the real Windows? I mean, I just want to get the windows that are listed on the taskbar.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
there are several different ways to generate a taskbar-like list of window handles, but the 2 easiest (for me anyway) is to 1) use EnumWindows and weed out the windows you're not interested in, or 2) create a system-wide hook via SetWindowsHookEx w/WH_SHELL that will be sent what goes on with the top-level windows re: creation, destruction, activation, etc. but you'll still have to generate an initial list of windows somehow.

the system-wide hook has the advantage of maintaining a consistent order of the windows ala the taskbar, whereas the EnumWindows list will change with time as the windows are moved around in z-order.

here's my code using EnumWindows to create a taskbar-like list of windows:


// ----------------------------------------------------------------------------
void System::GetTaskList(HWND hWndTop, hWndList& wndList)
{
// hWndList is just a std::vector of HWNDs

wndList.clear();
EnumWindows(EnumWndTaskProc, (LPARAM)&wndList);
}

// ----------------------------------------------------------------------------
BOOL CALLBACK System::EnumWndTaskProc(HWND hWnd, LPARAM lParam)
{
if( IsWindowVisible(hWnd) )
{
DWORD style = GetWindowLong(hWnd, GWL_STYLE);
DWORD exStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
bool show = false;

show = show || (exStyle & WS_EX_TOOLWINDOW) != WS_EX_TOOLWINDOW;
show = show || (style & WS_OVERLAPPEDWINDOW) == WS_OVERLAPPEDWINDOW;
show = show || (exStyle & WS_EX_APPWINDOW) == WS_EX_APPWINDOW;

if( show && (GetWindow(hWnd, GW_OWNER) == NULL) )
((hWndList*)lParam)->push_back(hWnd);
}

return TRUE;
}


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!