c++mfccontrolsgroupbox

How to refresh a Groupbox control in MFC (C++)


I created a Groupbox in my MFC view class. But failed in refresh it while Restore Down from Maxmize as well as Maxmize from Restore Down.

The failed refresh Groupbox control as below pic:

I create the Groupbox in View::OnCreate:

int Cmfc_gui_test3View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
...
CRect mybox( 0, 0,350, 1000);

pmyGroupBox->Create(_T("Test GroupBox"), WS_CHILD | WS_VISIBLE | BS_CENTER | BS_GROUPBOX|WS_BORDER, mybox, this, IDG_GROUPBOX1);
...
}

And I am using pmyGroupbox->ShowWindow(SW_HIDE) and pmyGroupbox->ShowWindow(SW_SHOW) in OnPaint method. I also tested pmyGroupbox->ShowWindow(SW_RESTORE) but no lucky. The control always failed in refreshing itself. Hope someone can help me. Thanks in advance.


Solution

  • This question (Can a MFC dialog resource be attached to a CChildView?) should provide useful information.

    You need to use the CFormView class if you want to create a form that has controls on it, like combo boxes.

    There are some other useful articles on this subject:

    Q98598: HOWTO: Use CFormView in SDI and MDI Applications

    The linked article provides sample code and instructions. The summary reads:

    SUMMARY

    The CFormView class provides a convenient method to place controls into a view that is based on a dialog box template. The general procedure to use a CFormView is described in the documentation for the class and is illustrated in the VIEWEX and CHKBOOK sample applications provided with Microsoft Foundation Classes (MFC) versions 2.x and above. However, these applications do not demonstrate making the initial size of the frame window to be the same as the initial size of the form.

    The following section lists the steps required to support creating a single document interface (SDI) or multiple document interface (MDI) application based on a CFormView, sizing the initial frame window around the form, changing the style of the frame, and closing an MDI document using a button in the form.

    The instructions are for older versions of Visual Studio so you might have to tweak a little.