Sign in to follow this  
dantheman1337

win32 delete child window

Recommended Posts

dantheman1337    103
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]

Share this post


Link to post
Share on other sites
[quote name='dantheman1337' timestamp='1339786793' post='4949629']
I solved it by deleting the parent window and making a new one every time I wanted to make a new button scheme.
[/quote]
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.

Share this post


Link to post
Share on other sites
dantheman1337    103
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.

Share this post


Link to post
Share on other sites
jwezorek    2663
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this