home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / os / mswindo / programm / misc / 4464 < prev    next >
Encoding:
Text File  |  1992-12-23  |  2.3 KB  |  67 lines

  1. Newsgroups: comp.os.ms-windows.programmer.misc
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!swrinde!sdd.hp.com!cs.utexas.edu!torn!nott!emr1!jagrant
  3. From: jagrant@emr1.emr.ca (John Grant)
  4. Subject: Re: how to find parentless non-child windows?
  5. Message-ID: <1992Dec23.232710.13783@emr1.emr.ca>
  6. Organization: Energy, Mines, and Resources, Ottawa
  7. References: <1992Dec19.022439.8466@emr1.emr.ca> <723@lax.lax.pe-nelson.com>
  8. Date: Wed, 23 Dec 1992 23:27:10 GMT
  9. Lines: 56
  10.  
  11. I found a solution to my problem and I thought I'd post it here since
  12. it was a bit obscure.
  13.  
  14. If you recall, I was creating several parentless non-child windows with:
  15.      CreateWindow("xxx",NULL,
  16.              WS_OVERLAPPED  | WS_CAPTION    |
  17.              WS_SYSMENU     | WS_THICKFRAME |
  18.              WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
  19.              CW_USEDEFAULT,CW_USEDEFAULT,
  20.              CW_USEDEFAULT,CW_USEDEFAULT,
  21.              NULL,           //note - no parent
  22.              NULL,                           
  23.             hinstance,(LPVOID)xxx);
  24.  
  25. I wanted them parentless so they wouldn't remain in front of the main
  26. window.
  27.  
  28. When I closed the main window, these sub-windows disappeared, but when
  29. I put a breakpoint at WM_DESTROY, it never got there (I guess Windows
  30. destroyed them, but not through WM_DESTROY).  Anyway, they all used
  31. resources that I wanted to free up before closing them.  I needed a
  32. way to find all of these windows so I could send them WM_DESTROY.
  33.  
  34. Several people sent suggestions regarding EnumWindows and some said
  35. I should keep a linked list of the HWND.  As simple as the linked
  36. list code is, it just seemed to add yet more complexity to an already
  37. complex app, so I looked for another solution.  Rick Kimmel came up
  38. with the best ideas, so here is the (our) solution:
  39.  
  40. In the main window:
  41.       case WM_DESTROY:    DestroyOtherWindow(hwnd,"xxx");
  42.                 PostQuitMessage(0);
  43.                 break;
  44.  
  45. void DestroyOtherWindows(HWND hwndmain,char *classname)
  46. {
  47. HWND hwnd;
  48. char buffer[50];
  49.  
  50.     hwnd=GetWindow(hwndmain,GW_HWNDFIRST);
  51.     while(hwnd){
  52.       GetClassName(hwnd,buffer,sizeof(buffer));
  53.       if(strcmp(buffer,classname)==0){
  54.         if(GetWindowWord(hwnd,    GWW_HINSTANCE)==
  55.            GetWindowWord(hwndmain,GWW_HINSTANCE)){
  56.                   SendMessage(hwnd,WM_DESTROY,0,0);
  57.         }
  58.       }
  59.       hwnd=GetWindow(hwnd,GW_HWNDNEXT);
  60.     }
  61.     return;
  62. }
  63. -- 
  64. John A. Grant                        jagrant@emr1.emr.ca
  65. Airborne Geophysics
  66. Geological Survey of Canada, Ottawa
  67.