🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.ms-windows.programmer.misc
Article #1840

Re: how to find parentless non-child windows?

#1840
From: John Grant
Date: Wed, 23 Dec 1992 23:27
56 lines
2384 bytes
I found a solution to my problem and I thought I'd post it here since
it was a bit obscure.

If you recall, I was creating several parentless non-child windows with:
 	CreateWindow("xxx",NULL,
 			WS_OVERLAPPED  | WS_CAPTION    |
 			WS_SYSMENU     | WS_THICKFRAME |
 			WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
 			CW_USEDEFAULT,CW_USEDEFAULT,
 			CW_USEDEFAULT,CW_USEDEFAULT,
 			NULL,           //note - no parent
 			NULL,                           
			hinstance,(LPVOID)xxx);

I wanted them parentless so they wouldn't remain in front of the main
window.

When I closed the main window, these sub-windows disappeared, but when
I put a breakpoint at WM_DESTROY, it never got there (I guess Windows
destroyed them, but not through WM_DESTROY).  Anyway, they all used
resources that I wanted to free up before closing them.  I needed a
way to find all of these windows so I could send them WM_DESTROY.

Several people sent suggestions regarding EnumWindows and some said
I should keep a linked list of the HWND.  As simple as the linked
list code is, it just seemed to add yet more complexity to an already
complex app, so I looked for another solution.  Rick Kimmel came up
with the best ideas, so here is the (our) solution:

In the main window:
	  case WM_DESTROY:	DestroyOtherWindow(hwnd,"xxx");
				PostQuitMessage(0);
				break;

void DestroyOtherWindows(HWND hwndmain,char *classname)
{
HWND hwnd;
char buffer[50];

	hwnd=GetWindow(hwndmain,GW_HWNDFIRST);
	while(hwnd){
	  GetClassName(hwnd,buffer,sizeof(buffer));
	  if(strcmp(buffer,classname)==0){
	    if(GetWindowWord(hwnd,    GWW_HINSTANCE)==
	       GetWindowWord(hwndmain,GWW_HINSTANCE)){
	      		SendMessage(hwnd,WM_DESTROY,0,0);
	    }
	  }
	  hwnd=GetWindow(hwnd,GW_HWNDNEXT);
	}
	return;
}
-- 
John A. Grant						jagrant@emr1.emr.ca
Airborne Geophysics
Geological Survey of Canada, Ottawa
Technical Details
Message-ID: <1992Dec23.232710.13783@emr1.emr.ca>
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!swrinde!sdd.hp.com!cs.utexas.edu!torn!nott!emr1!jagrant
References: <1992Dec19.022439.8466@emr1.emr.ca> <723@lax.lax.pe-nelson.com>

Show Full Headers
Complete Article Headers
Newsgroups: comp.os.ms-windows.programmer.misc
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!swrinde!sdd.hp.com!cs.utexas.edu!torn!nott!emr1!jagrant
From: jagrant@emr1.emr.ca (John Grant)
Subject: Re: how to find parentless non-child windows?
Message-ID: <1992Dec23.232710.13783@emr1.emr.ca>
Organization: Energy, Mines, and Resources, Ottawa
References: <1992Dec19.022439.8466@emr1.emr.ca> <723@lax.lax.pe-nelson.com>
Date: Wed, 23 Dec 1992 23:27:10 GMT
Lines: 56