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.

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 on other sites
Could you please post some code? As far as I know, the window should be destroyed after DestroyWindow call.

Oxyd

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));

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

Share on other sites
Maybe, it oculd be that you have the positions defined? (Dialog)

Share on other sites
Well actually I wasn't using the resource editor for this - I am creating the controls in code.

Share on other sites
Quote:
 Original post by shane1985Well 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 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 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 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 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 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 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,
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 on other sites
Try using "static" control, instead of drawing the text yourself.

Oxyd

Share on other sites
Making the window a static class?

Share on other sites
Uh - there are "EDIT" controls and there are "STATIC" controls.

Oxyd

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.

-Shane

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.

Create an account

Register a new account

• Forum Statistics

• Total Topics
628764
• Total Posts
2984564

• 13
• 9
• 25
• 12
• 9