Based on the use of drop-down box programming dialog

1. Create a new MFC application, named 04 comboBoxCtrl, selected based on the application type dialog box, select the Simplified Chinese language resources

2, open the Toolbox, add a drop-down box control in the dialog box

3, modify the display content

Right property, modify the Data, separated by semicolons

Results are as follows

4, modify the properties inside Type to Drop List, allows users can not edit

5, in accordance with the default ASCII code sorting, modify sort is not the sort of false

6, add a variable to the drop-down box control, modify access and variable names

7, in the OnInitDialog function can be carried out on the drop-down box as follows: add, delete, insert, set default options for acquiring the content of the specified index

  // drop-down box to add 
    m_cbx.AddString (TEXT ( " Monkey " )); 
    m_cbx.AddString (TEXT ( " Monkey " )); 
    m_cbx.AddString (TEXT ( " pig " )); 
    m_cbx.AddString (TEXT ( " Drifting " )); 

    // set the default options 
    m_cbx.SetCurSel ( 0 ); 

    // insert 
    m_cbx.InsertString ( 4 , TEXT ( " white Rabbit " )); 

    // delete 
    m_cbx.DeleteString ( 3 ); 

    // get the index number 1 the specific content 
    / *CString str;
    m_cbx.GetLBText(1, str);
    MessageBox(str);*/

8, add the control event

Right on the drop-down box control properties, find CBN_SELCHANGE, select <Add> OnCbnSelchangeCombo1 in Control Events, trigger event occurs when changing the contents of a control option

Write OnCbnSelchangeCombo1 function

void CMy04comboBoxCtrlDlg::OnCbnSelchangeCombo1()
{
    // TODO: Add your control notification handler code here
    //拿到索引位置
    int index = m_cbx.GetCurSel();

    CString str;
    m_cbx.GetLBText(index, str);
    MessageBox(str);
}

 

Guess you like

Origin www.cnblogs.com/yanchaoyi/p/12662622.html