home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / os / mswindo / programm / misc / 4462 < prev    next >
Encoding:
Internet Message Format  |  1992-12-23  |  3.9 KB

  1. Path: sparky!uunet!lax.pe-nelson.com!lax!twbrown
  2. From: twbrown@PE-Nelson.COM (Tom W. Brown)
  3. Newsgroups: comp.os.ms-windows.programmer.misc
  4. Subject: Re: how to find parentless non-child windows?
  5. Message-ID: <723@lax.lax.pe-nelson.com>
  6. Date: 21 Dec 92 19:00:31 GMT
  7. References: <1992Dec19.022439.8466@emr1.emr.ca>
  8. Sender: news@lax.pe-nelson.com
  9. Organization: PE-Nelson
  10. Lines: 85
  11.  
  12. In article <1992Dec19.022439.8466@emr1.emr.ca>, jagrant@emr1.emr.ca (John Grant) writes:
  13. |> My app behaves a bit like a MDI app, but not quite.  From the main
  14. |> window, several other parentless non-child windows can be created as
  15. |> follows:
  16. |>     CreateWindow("xxx",NULL,
  17. |>             WS_OVERLAPPED  | WS_CAPTION    |
  18. |>             WS_SYSMENU     | WS_THICKFRAME |
  19. |>             WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
  20. |>             CW_USEDEFAULT,CW_USEDEFAULT,
  21. |>             CW_USEDEFAULT,CW_USEDEFAULT,
  22. |>             NULL,           //note - no parent
  23. |>             NULL,                           
  24. |>             hinstance,(LPVOID)xxx);
  25. |> 
  26. |> Note: they have *no parent* and they are *not* WS_CHILD.
  27. |> 
  28. |> When I close the application from the main window, these secondary
  29. |> windows do not receive WM_DESTROY (I breakpointed WM_DESTROY and
  30. |> it never gets there).  I guess the main window only sends WM_DESTROY
  31. |> messages to them if they have a parent and/or if they are WS_CHILD?
  32. |> Is that right?
  33.  
  34. Yes, well, only if they can trace ancestry to your main window -- they
  35. certainly don't have to have WS_CHILD style and giving a window WS_CHILD
  36. style without also giving it a parent won't cause it to be destroyed
  37. automatically (granted, it doesn't make a lot of sense to do this).
  38.  
  39. Remember WS_CHILD is a _style_, it indicates how the window should be
  40. handled in terms of clipping within the bounds of a parent.  It does not
  41. establish a parent/child window relationship.  The two are really
  42. independent.
  43.  
  44.  
  45. |> 
  46. |> So, when I process WM_DESTROY for the main window, I want to find
  47. |> all of the secondary windows and shut them down too (so they can
  48. |> de-allocate their resources).  I tried doing this when I get
  49. |> WM_DESTROY for the main window:
  50. |> 
  51. |>   void DestroySecondaryWindows(void){
  52. |>   HWND hwnd;
  53. |>     while((hwnd=FindWindow("xxx",NULL)){
  54. |>       SendMessage(hwnd,WM_DESTROY,0,0);
  55. |>     }
  56. |>     return;
  57. |>   }
  58. |> 
  59. |> Well, close but not quite.  The secondary window receives several
  60. |> WM_DESTROY messages, even though I am using 'Send' instead of 'Post'.
  61. |> I guess I need to wait until each window is destroyed before I
  62. |> try to 'find' another one?  If so, how?  
  63.  
  64. Try "DestroyWindow(hwnd)" instead of sending a destroy message -- this still
  65. may suffer from the timing problem, I don't know.
  66.  
  67. You may want to simply keep the handles for these windows in your app, in
  68. a static HWND array, or somewhere.  Then you could simply loop through and
  69. destroy them without having to "Find" them and worry about the timing in
  70. the above loop.  I really can't think of a good reason not to do this.
  71.  
  72. You may also want to consider making them parented windows (but not WS_CHILD
  73. windows) in order to have them automatically deleted when the application
  74. is closed.
  75.  
  76. The last option I can think of would be to enumerate the windows (EnumWindows
  77. instead of FindWindow), use GetClassName() on each to see if it belongs
  78. to class "xxx", and use DestroyWindow() on those that are.
  79.  
  80.  
  81. |> 
  82. |> I had a glance at GetWindow, but I'm a bit confused by it - should
  83. |> I be using GetWindow instead of FindWindow?  The problem is that the
  84. |> secondary windows have *no parent*.
  85.  
  86. No, as you've discovered, GetWindow relies on a parent/child relationship
  87. between windows and doesn't work for the same reason that the secondary
  88. windows don't go away when you close the main window.
  89.  
  90.  
  91.  
  92. ----------------------------------------------------------------------------
  93. Tom Brown               |  "She turned me into a newt...
  94. PE Nelson Systems       |                                  ... I got better"
  95. twbrown@pe-nelson.com   |                    Monty Python and the Holy Grail
  96. ----------------------------------------------------------------------------
  97.