Sign in to follow this  

Deleting Windows Controls at Runtime

This topic is 4860 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
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
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
Posting the code? [smile]

I looked at one of my programs that also replaced controls during runtime, and I used the hide/show method. And it worked. There is probably something wrong with your implementation.

Oxyd

Share this post


Link to post
Share on other sites
Yeah, I'm sure - haha.
Alright, here's an example:

CreateWindow(
"EDIT", "",
WS_CHILD | WS_TABSTOP,
int(.6 * WIDTH), int(.3 * HEIGHT), int(.08 * WIDTH), int(.04
* HEIGHT),
hDialog,
(HMENU)IDC_HEIGHT,
hInstance, NULL);

I create an edit box like this when a specific menu option is selected. Then if the user selects a different menu option, the following code is called.

HWND hide = GetDlgItem(hDialog, IDC_HEIGHT);
ShowWindow(hide, SW_HIDE);
EnableWindow(hide, FALSE);

After this, I do some TextOut() in the same area as the controls were, and that text is not displayed, but instead has a box of the default window color around it.


Share this post


Link to post
Share on other sites
Yeah, I know - static classes of windows, and edit classes.
But anyway, I think I got it to work this time.
It looks like it was a combination of things, mainly with the way I was handling the WM_PAINT messages.

Thanks for all your help!
-Shane

Share this post


Link to post
Share on other sites

This topic is 4860 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.

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