win32 delete child window

Started by
5 comments, last by jwezorek 11 years, 10 months ago
I have a button in my C++ application. The button is a child of my main window. How do I delete the button, without deleting the window? DestroyWindow() doesn't seem to work on child windows.

The code for the button is right here:

[source lang="cpp"]hWndButton=CreateWindowEx(NULL,
"BUTTON",
"OK",
WS_TABSTOP|WS_VISIBLE|WS_CHILD|BS_DEFPUSHBUTTON,
50,
220,
100,
24,
hWnd,
(HMENU)IDC_MAIN_BUTTON,
GetModuleHandle(NULL),
NULL);[/source]
Advertisement
I solved it by deleting the parent window and making a new one every time I wanted to make a new button scheme.
DestroyWindow() does work on child windows. You were probably doing something else wrong.

I solved it by deleting the parent window and making a new one every time I wanted to make a new button scheme.

This is overkill, isn't it? I'd consider it more of a stopgap hack until you can get the proper method working.

As has been said before, recheck DestroyWindow to make sure you were doing things right.
Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.
I used the destroywindow command and my buttons would still exist.

DestoryWindow(hWndButton);

However, my application is a graphics/character modeler/animator. It takes literally half a second to close the window and open it with new GUI. I don't see a big problem at the moment. I'll try to use the DestroyWindow comman some more and see what I find.
What do you know, it works now. Hmm, I must have been doing something wrong, or stupid.
Are you sure that it didn't just look like the child wasn't getting deleted because nothing issued a repaint? Maybe you just needed to invalidate the parent ... DestroyWindow definitely works on child windows.

This topic is closed to new replies.

Advertisement