From: mfc on
Hi,

another small question: is there an option / method in c++ together
with MFC to create a panel (like in java) where all items of this area
(panel = rectangle) are included? So that you are able to hide all
these items if you hide this panel?

Here`s a small description of the "panel" in java
http://java.sun.com/docs/books/tutorial/uiswing/components/panel.html

(The JPanel class provides general-purpose containers for lightweight
components - like buttons and any other items from the tool menu in
VS)

best regards
Hans
From: Joseph M. Newcomer on
It is clumsy to do, but not all that bad.

Consider two possible approaches. One is to create an "invisible" panel, by creating a
static frame. Change its ID to something like IDC_PANEL and bind it to a variable.
Another is to use a "Group box" control, and bind it to a variable. In either case, the
variable will be called "c_Panel".

void CMyDialog::ShowPanel(UINT mode)
{
CRect r;
c_Panel.GetWindowRect(&r);
ScreenToClient(&r);

for(CWnd * w = GetWindow(GW_CHILD); w != NULL; w = w->GetWindow(GW_HWNDNEXT))
{ /* find child controls */
CRect wr;
w->GetWindowRect(&wr);
ScreenToClient(&wr);
if(r.PtInRect(CPoint(wr.left, wr.top))
w->ShowWindow(mode);
} /* find child controls */
} // CMyDialog::ShowPanel

Then you call it as ShowPanel(SW_SHOW) or ShowPanel(SW_HIDE);

I use PtInRect because it is easier, and it captures every window whose top left corner is
inside the area ("panel") I want to cover. You could also use IntersectRect but that
computes a new rectangle which is the intersection, which is completley pointless.

Hint: NEVER, EVER create a dialog in which one control is on top of another or in any way
encloses another (except for frame controls and group boxes). NEVER put an Edit control
on top of another Edit control, or a ListBox on top of an Edit control, etc. The dialog
becomes completely unmaintainable. It is worth expending effort to create mechanisms to
ensure this never, ever happens.
On Mon, 21 Jun 2010 11:19:45 -0700 (PDT), mfc <mfcprog(a)googlemail.com> wrote:

>Hi,
>
>another small question: is there an option / method in c++ together
>with MFC to create a panel (like in java) where all items of this area
>(panel = rectangle) are included? So that you are able to hide all
>these items if you hide this panel?
>
>Here`s a small description of the "panel" in java
>http://java.sun.com/docs/books/tutorial/uiswing/components/panel.html
>
>(The JPanel class provides general-purpose containers for lightweight
>components - like buttons and any other items from the tool menu in
>VS)
>
>best regards
>Hans
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Joseph M. Newcomer on
Another technique is to use a child dialog to hold all the controls; but that is getting
into some really advanced stuff, which you might want to avoid for now. Each child dialog
becomes a "panel", and if you hide the child dialog, all its controls are hidden, too. But
things start getting messy, because you want to handle the messages in the parent, which
means you have to hand-edit the handlers into the parent. Easy for Leonardo.
joe

On Mon, 21 Jun 2010 11:19:45 -0700 (PDT), mfc <mfcprog(a)googlemail.com> wrote:

>Hi,
>
>another small question: is there an option / method in c++ together
>with MFC to create a panel (like in java) where all items of this area
>(panel = rectangle) are included? So that you are able to hide all
>these items if you hide this panel?
>
>Here`s a small description of the "panel" in java
>http://java.sun.com/docs/books/tutorial/uiswing/components/panel.html
>
>(The JPanel class provides general-purpose containers for lightweight
>components - like buttons and any other items from the tool menu in
>VS)
>
>best regards
>Hans
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm