Jump to content
  • Advertisement
Sign in to follow this  
shane1985

Deleting Windows Controls at Runtime

This topic is 5042 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does anyone know of a way to delete windows edit boxes, and static text boxes at runtime? I have tried the DestroyWindow() function, and it appears to delete the controls. However, when I add another control later in the program, the old one is still there (as a gray box). Does anyone have any ideas? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Could you please post some code? As far as I know, the window should be destroyed after DestroyWindow call.

Oxyd

Share this post


Link to post
Share on other sites
Well it is......sort of - but then when I create another control on top of it, parts of it are covered by the old control.

I'm not sure what code you want me to post.
Basically, I just go through the controls on the window and destroy all of them like this.

DestroyWindow(GetDlgItem(hDialog, IDC_WIDTH));
DestroyWindow(GetDlgItem(hDialog, IDC_HEIGHT));
DestroyWindow(GetDlgItem(hDialog, IDC_CALC));
DestroyWindow(GetDlgItem(hDialog, IDS_HEAD));

Could it be a problem in how I create the controls?

Share this post


Link to post
Share on other sites
Quote:
Original post by shane1985
Well it is......sort of - but then when I create another control on top of it, parts of it are covered by the old control.

I'm not sure what code you want me to post.
Basically, I just go through the controls on the window and destroy all of them like this.

DestroyWindow(GetDlgItem(hDialog, IDC_WIDTH));
DestroyWindow(GetDlgItem(hDialog, IDC_HEIGHT));
DestroyWindow(GetDlgItem(hDialog, IDC_CALC));
DestroyWindow(GetDlgItem(hDialog, IDS_HEAD));

Could it be a problem in how I create the controls?


Maybe [smile]

But I personally think, the problem is that you're messing with controls on dialog. Try not to specify the controls you delete later in the dialog resource and create them using CreateWindowEx in WM_INITDIALOG message.

EDIT: Oh - you posted your reply while I was writing this [smile] Could you please post the important parts of your dialog procedure? I mean - original controls creation, deletion and creation of new controls.

Btw - what about to hide them before deleting?

Oxyd

Share this post


Link to post
Share on other sites
If you know what controls you create and destroy at runtime, wouldn't it be sufficient to disable and hide the controls?


void SwapControls(int hide, int show) {
HWND hHide = GetDlgItem(hDialog, hide);
HWND hShow = GetDlgItem(hDialog, show);

ShowWindow(hHide, SW_HIDE);
EnableWindow(hHide, FALSE);

ShowWindow(hShow, SW_SHOW);
EnableWindow(hShow, TRUE);
UpdateWindow(hShow);
}



Share this post


Link to post
Share on other sites
Haha, that is how I'm doing it - not in WM_INITDIALOG, but I'm not using the resource editor either.

-I'll try that darookie

Share this post


Link to post
Share on other sites
Thanks rookie - that works fine. It will probably be easier this way too, since I plan to be switching back and forth between control sets.

Share this post


Link to post
Share on other sites
Actually it looks like the same thing is still happening. When I go to output text over where the controls were, much of it is covered by where the old control was.

Any other ideas?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!