Win32: Task Windows
Task windows are defined as application windows that have a button on the taskbar and appear on the Windows Task Manager. Sometimes knowing how Windows determines task windows can help you create windows that are "invisible" to the taskbar.
The windows in the Task List (Alt+Tab) match these criteria:
- The window must be visible.
- The window must have no parent window (GetParent(hwnd)!=NULL).
- If the window has no owner, it must have the WS_EX_TOOLWINDOW style.
- If the window has an owner, it must not have the WS_EX_TOOLWINDOW style.
The windows in Task Manager match these criteria:
- The window must be visible.
- The window must have no parent window (GetParent(hwnd)!=NULL).
- The window cannot have an owner (GetWindowLong(hwnd,GWL_HWNDPARENT)!=0).
- If the window has the WS_EX_TOOLWINDOW style, the window's class name cannot be "Progman".
The following are criteria for task windows for Windows 3.1:
- The window must be visible.
- The window must have no parent window (GetParent(hwnd)==NULL).
The following are criteria for determining whether a window's button appears on the taskbar:
- The window must have the WS_VISIBLE style.
- If the window has the WS_EX_APPWINDOW style, the button unconditionally appears.
- The window must not have the WS_EX_TOOLWINDOW style.
- If the window has neither the WS_EX_APPWINDOW nor the WS_EX_TOOLWINDOW style, the window cannot have an owner.
In creating the task list, Task Manager iterates through all top-level windows in a GetWindow loop (risky, yes, but suitable for our purposes).
#define ITW_ALTTAB 1
#define ITW_TASKMGR 2
#define ITW_TASKMGR31 3
#define ITW_TASKBAR 4
BOOL IsTaskWindow(HWND hwnd, UINT uType){
TCHAR cn[256];
HWND hwndOwner=GetWindowLong(hwnd,GWL_HWNDPARENT);
GetClassName(hwnd,cn,256);
switch(uType){
case ITW_ALTTAB:
if(IsWindowVisible(hwnd))
if(!GetParent(hwnd))
if(!hwndOwner||(GetWindowLong(hwnd,GWL_EXSTYLE)&WS_EX_TOOLWINDOW))
if(!((GetWindowLong(hwnd,GWL_EXSTYLE)&WS_EX_TOOLWINDOW))
return TRUE;
case ITW_TASKBAR:
if(!(GetWindowLong(hwnd,GWL_STYLE)&WS_VISIBLE))
return FALSE;
if((GetWindowLong(hwnd,GWL_EXSTYLE)&WS_EX_APPWINDOW))
return TRUE;
if((GetWindowLong(hwnd,GWL_EXSTYLE)&WS_EX_TOOLWINDOW))
return FALSE;
if(!hwndOwner)
return TRUE;
case ITW_TASKMGR:
if(IsWindowVisible(hwnd))
if(!GetParent(hwnd))
if(!hwndOwner)
if(GetWindowLong(hwnd,GWL_EXSTYLE)&WS_EX_TOOLWINDOW){
if(lstrcmpi(cn,TEXT("Progman")))
return TRUE;
} else return TRUE;
case ITW_TASKMGR31:
if(IsWindowVisible(hwnd))
if(!GetParent(hwnd))
if(!hwndOwner)
return TRUE;
}
return FALSE;
}
BOOL EnumTaskWindows(UINT uType, WNDENUMPROC wep, LPARAM lParam){
HWND hwnd=GetTopWindow(NULL);
while(hwnd){
if(IsTaskWindow(hwnd,uType))
if(!wep(hwnd,lParam))
return TRUE;
hwnd=GetNextWindow(hwnd,GW_HWNDNEXT);
}
return TRUE;
}
