The main objective is to implement a Button click to show the List below, creating a drawer-style menu tool.
This article aims to implement clicking on the toolbar to control the visibility of the List.

Reference:

Implementation of Hiding and Showing a Control in MFC
【MFC】Check if a control is hidden


In MFC, controls are searched and controlled using IDs, which is the same as the name in WPF and WinForm, operating by acquiring this control. The interface for controlling visibility is: ShowWindow(TRUE), and the interface for acquiring control state is: int bVisible = ((CWnd*)GetDlgItem(IDC_LIST1))->GetStyle() & WS_VISIBLE;


Main code:

  1. Initialize the List as hidden
1
2
3
4
5
6
7
8
9
10
11
12
//-----------------------------------------------------------------------------
void CMenuBarChildDlg::DoDataExchange (CDataExchange *pDX) {
CAcUiDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMenuBarChildDlg)
//}}AFX_DATA_MAP
//Add project check initialization here
CEdit* edit = (CEdit*)GetDlgItem(IDC_LIST1);
edit->ShowWindow(FALSE);

DDX_Control(pDX, IDC_LIST1, m_list);
}

  1. Display the specified List when the button is clicked
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void CMenuBarChildDlg::OnBnClickedButton1()
{
// TODO: Add control notification handler code here

CEdit* edit = (CEdit*)GetDlgItem(IDC_LIST1);
int bVisible = ((CWnd*)GetDlgItem(IDC_LIST1))->GetStyle() & WS_VISIBLE;

if(bVisible == 0)
{
edit->ShowWindow(TRUE);
}
else
{
edit->ShowWindow(FALSE);
}
}