News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Destroying windows

Started by Neil, February 20, 2010, 03:48:20 PM

Previous topic - Next topic

Neil

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?

oex

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!
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

Nordwind64

Destroying the parent will destroy all childs...
Greetings, Nordwind.
Windows 7 (64Bit), JWASM/PoLink

jj2007

Nordwind is right:
MSDN: 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.

Neil

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.