• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 574
  • Last Modified:

Dissappearing window in CTabCtrl

I'm creating a MFC dialog based application in VC6.  The dialog only contains one control; a CTabCtrl.  Each page of the tab control is linked to another dialog (with its own CDialog-derived class).  All the page dialogs are created in the main dialog with the tab control as the parent.  Each page dialog is then hidden and only the correct one is shown.  When a tab is changed, the current page is hidden and the new page is shown (usign ShowWindow(SW_HIDE) or ShowWindow(SW_SHOW)).

The above part all works and the pages are shown as expected.  The problem comes when any control on the page dialog has the focus and I press ENTER.  The page then dissapears.  It is not destroyed, since it reappears when I switch tabs and then back to the page where I was.  It is almost as if it is moved to below the tab control, or if some code redraws over my dialog page.  If, for example, a edit control has the focus and I press ENTER, the page dissapears.  If I type some characters, switch tabs and switch tabs again back to the original page, my page is shown again with the text typed in the edit control.

I've tried to set break points to all the message handlers I could think of without any success.  I can not find why the page is hidden.

Any ideas?
1 Solution
I guess the same happens when you press Esc. Overwrite OnOK and OnCancel in each dialog:

void CMyDlg::OnCancel()
//     CDialog::OnCancel();  // don't call base class implementation
void CMyDlg::OnOK()
//     CDialog::OnOK();
I guess this solves the problem Alex, but wouldn't be better to override the OnOK and OnCancel methods for the child dialogs instead of overriding the parent dialog's methods?

Afterall, using Enter and Esc to close dialogs is a pretty well established behavior for closing dialog boxes.
What do you think?

If you want to prohibit the CR close the dialog box when in an edit box (and only then), be sure to set the edit box's style to ES_WANTRETURN (either directly on init dialog or from the dialog editor propery pages).

By the way, why not moving to propery pages instead of tab controls if you are using just one big control (the tab ctrl) on your dialog?

cfmAuthor Commented:
AlexFM.  That solved it.  I did think of that as a possible problem, but only related to the parent dialog.  Never thought about implementing it for the page dialogs as well.  Anyway, it is working now.  Thanks

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now