
Dialog box in a dialog box
There are a couple approaches. The easiest one is to simply have a function
void CMyDialog::ShowControls(BOOL mode)
{
UINT show = mode ? SW_SHOW : SW_HIDE;
c_StartButton.ShowWindow(show);
c_Result.ShowWindow(show);
c_Notification.ShowWIndow(show);
... etc.
}
where the c_ variables are control member variables representing the windows (see my essay
on Avoiding GetDlgItem on my MVP Tips site).
Another approach is to group the controls either within a group box or a static frame (the
static frame could be invisible), and then do
void CMyDialog::ShowControls(BOOL mode, CWnd * enclosing)
{
CRect r;
enclosing->GetWindowRect(&r);
ScreenToClient(&r);
for(CWnd * wnd = GetWindow(GW_CHILD); wnd != NULL; wnd = wnd->GetWindow(GW_HWNDNEXT))
{
CRect c;
UINT show = mode ? SW_SHOW : SW_HIDE;
wnd->GetWindowRect(&c);
ScreenToClient(&c);
CPoint pt(c.left, c.top);
if(r.PtInRect(c))
{
wnd->ShowWindow(show);
}
}
You can now disable a group of controls by passing in the window reference for the
enclosing window, e.g.,
ShowControls(FALSE, &c_Caption);
will disable all controls whose top left corner is contained entirely within the window
referenced by c_Caption.
Note that if the focus was on any control that has just been hidden, you should move it
(there was an earlier post on this topic, a trick I had forgotten)
joe
Quote:
>Hi,
>I want to hide/show a group of controls in a dialog box. For this I
>thought it would be nice to have several dialog child boxes and than I
>could hide or show that dialog easily.
>How can I create and show a dialog box in another dialog box ?
>Thanks in advance,
>Devrim.
Joseph M. Newcomer [MVP]
Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm