Win32: Message-Only Windows

Tue, 29 Jan 2008 04:33:50 +0000 - Author: Peter O.

Windows 2000 introduced a new kind of window called the "message-only window." Message-only windows cannot be enumerated using any function of the EnumWindows family, is invisible, has no size or position, and has no Z-order. A message-only window serves only for dispatching messages. A message-only window can be created by specifying HWND_MESSAGE for the hwndParent parameter of the CreateWindow or CreateWindowEx function. A window can be made a message-only window by setting its parent to HWND_MESSAGE. Calling GetParent on a message-only window returns HWND_MESSAGE.

To search message-only windows, call FindWindowEx with the first parameter as HWND_MESSAGE. You can use FindWindowEx to create a tested enumeration function for message-only windows:

BOOL EnumMessageOnlyWindows(WNDENUMPROC wep, LPARAM lParam){
 HWND hwnd=FindWindowEx(HWND_MESSAGE,NULL,NULL,NULL);
 if(hwnd){wep(hwnd,lParam);}
 while(hwnd){
  hwnd=GetNextWindow(hwnd,GW_HWNDNEXT);
  if(hwnd){wep(hwnd,lParam);}
 }
 return TRUE;
}

Each message-only window has a root ancestor, like the desktop. To find it, retrieve the first message only window with FindWindowEx and then use GetWindowLong(GWL_HWNDPARENT) to get the handle of the root.

Note It is possible to create message-only windows in Windows 98. The root of message-only windows in Windows 98 has a constant of 0x84. When any window is made the parent of this window handle, it becomes and behaves like a message-only window.


Discussion

Other Formats