The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Neil on February 20, 2010, 03:48:20 PM

Title: Destroying windows
Post by: Neil on February 20, 2010, 03:48:20 PM
In a previous post I dynamically created 10 superclassed Edit boxes, now I'm implementing a CANCEL button. I've come up with this piece of code - which could be turned into a loop :-


        invoke DestroyWindow, hwndEdit
        invoke DestroyWindow, hwndEdit+4
        invoke DestroyWindow, hwndEdit+8
        invoke DestroyWindow, hwndEdit+12
        invoke DestroyWindow, hwndEdit+16
        invoke DestroyWindow, hwndEdit+20
        invoke DestroyWindow, hwndEdit+24
        invoke DestroyWindow, hwndEdit+28
        invoke DestroyWindow, hwndEdit+32
        invoke DestroyWindow, hwndEdit+36


This works, but is this the correct way to do it or is there an easier way?
Title: Re: Destroying windows
Post by: oex on February 20, 2010, 03:58:12 PM
This way looks pretty easy but a more fun way is to take a hammer to the hard drive. That way you can put your mind at rest it *guarentees* no more will be created!
Title: Re: Destroying windows
Post by: Nordwind64 on February 20, 2010, 04:05:24 PM
Destroying the parent will destroy all childs...
Title: Re: Destroying windows
Post by: jj2007 on February 20, 2010, 04:18:20 PM
Nordwind is right:
MSDN: (http://msdn.microsoft.com/en-us/library/ms632682%28VS.85%29.aspx) If the specified window is a parent or owner window, DestroyWindow automatically destroys the associated child or owned windows when it destroys the parent or owner window.

  mov esi, offset hwndEdit
  .Repeat
lodsd
test eax, eax
.Break .if Zero?
invoke DestroyWindow, eax
  .Until 0

This will do the job in case you want to re-create the controls, but make sure you left an empty slot.
Title: Re: Destroying windows
Post by: Neil on February 20, 2010, 04:25:13 PM
Thanks jj, that's a nice piece of code :8) I am just destroying the controls which could be recreated once again, so that code is perfect for my needs & is a lot more elegant than mine.