vc显示下拉框所选择的选项
BOOL CProgramexialakuangDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
CComboBox* a= ( CComboBox*)GetDlgItem(IDC_COMBO1);//创建组合框及选项
a->AddString("黑色");
a->AddString("红色");
a->AddString("兰色");
return TRUE; // return TRUE unless you set the focus to a control
}
void CProgramexialakuangDlg::OnButton1() //点击按钮对话框显示所选的选项,为什么总显示红色?
{
// TODO: Add your control notification handler code here
CComboBox* a=(CComboBox*)GetDlgItem(IDC_COMBO1);
if( a->SetCurSel(0))
{
AfxMessageBox(_T("黑色"));
}
else if(a->SetCurSel(1))
{
AfxMessageBox(_T("红色"));
}
else if(a->SetCurSel(2))
{
AfxMessageBox(_T("兰色"));
}
}