MFC下拉框设置 下拉框不能工作
// step1Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "step1.h"
#include "step1Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CStep1Dlg dialog
CStep1Dlg::CStep1Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CStep1Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CStep1Dlg)
m_edit = _T("");
m_chk1 = FALSE;
m_chk2 = FALSE;
m_chk3 = FALSE;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CStep1Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CStep1Dlg)
DDX_Control(pDX, IDC_COMBO1, m_combo1);
DDX_Control(pDX, IDC_RADIO2, m_radfemale);
DDX_Control(pDX, IDC_RADIO1, m_radmale);
DDX_Text(pDX, IDC_EDIT1, m_edit);
DDV_MaxChars(pDX, m_edit, 4);
DDX_Check(pDX, IDC_CHECK1, m_chk1);
DDX_Check(pDX, IDC_CHECK2, m_chk2);
DDX_Check(pDX, IDC_CHECK3, m_chk3);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CStep1Dlg, CDialog)
//{{AFX_MSG_MAP(CStep1Dlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_EN_MAXTEXT(IDC_EDIT1, OnMaxtextEdit1)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStep1Dlg message handlers
BOOL CStep1Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
//m_edit.SetWindowText("welcome");
//m_edit.EnableWindow(false);
m_edit="123";
UpdateData(false);
m_combo1.AddString( "23");
m_combo1.InsertString(4, "24" );
m_combo1.SetCurSel(4);
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CStep1Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CStep1Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CStep1Dlg::OnMaxtextEdit1()
{
// TODO: Add your control notification handler code here
UpdateData(true);
AfxMessageBox(m_edit);
}
void CStep1Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
CString str;
if(m_radmale.GetCheck())
m_radmale.GetWindowText(str);
else
m_radfemale.GetWindowText(str);
UpdateData(true);
if(m_chk1) str+="、 游泳" ;
if(m_chk2) str+="、 跑步" ;
if(m_chk3) str+="、 打球" ;
MessageBox(str,"测试",MB_OKCANCEL);
}
void CStep1Dlg::OnRadio1()
{
m_radmale.SetCheck(true);
m_radfemale.SetCheck(false);
}
void CStep1Dlg::OnRadio2()
{
// TODO: Add your control notification handler code here
m_radmale.SetCheck(false);
m_radfemale.SetCheck(true);
}

//
#include "stdafx.h"
#include "step1.h"
#include "step1Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CStep1Dlg dialog
CStep1Dlg::CStep1Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CStep1Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CStep1Dlg)
m_edit = _T("");
m_chk1 = FALSE;
m_chk2 = FALSE;
m_chk3 = FALSE;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CStep1Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CStep1Dlg)
DDX_Control(pDX, IDC_COMBO1, m_combo1);
DDX_Control(pDX, IDC_RADIO2, m_radfemale);
DDX_Control(pDX, IDC_RADIO1, m_radmale);
DDX_Text(pDX, IDC_EDIT1, m_edit);
DDV_MaxChars(pDX, m_edit, 4);
DDX_Check(pDX, IDC_CHECK1, m_chk1);
DDX_Check(pDX, IDC_CHECK2, m_chk2);
DDX_Check(pDX, IDC_CHECK3, m_chk3);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CStep1Dlg, CDialog)
//{{AFX_MSG_MAP(CStep1Dlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_EN_MAXTEXT(IDC_EDIT1, OnMaxtextEdit1)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStep1Dlg message handlers
BOOL CStep1Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
//m_edit.SetWindowText("welcome");
//m_edit.EnableWindow(false);
m_edit="123";
UpdateData(false);
m_combo1.AddString( "23");
m_combo1.InsertString(4, "24" );
m_combo1.SetCurSel(4);
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CStep1Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CStep1Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CStep1Dlg::OnMaxtextEdit1()
{
// TODO: Add your control notification handler code here
UpdateData(true);
AfxMessageBox(m_edit);
}
void CStep1Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
CString str;
if(m_radmale.GetCheck())
m_radmale.GetWindowText(str);
else
m_radfemale.GetWindowText(str);
UpdateData(true);
if(m_chk1) str+="、 游泳" ;
if(m_chk2) str+="、 跑步" ;
if(m_chk3) str+="、 打球" ;
MessageBox(str,"测试",MB_OKCANCEL);
}
void CStep1Dlg::OnRadio1()
{
m_radmale.SetCheck(true);
m_radfemale.SetCheck(false);
}
void CStep1Dlg::OnRadio2()
{
// TODO: Add your control notification handler code here
m_radmale.SetCheck(false);
m_radfemale.SetCheck(true);
}

...全文
相关推荐
MFC中在ListControl下进行下拉框操作
动态创建下拉框方案, 实现listcontrol与COmboBox组合
MFC中复选下拉框控件的设计与实现
MFC(Microsoft Foundation Classes)作为Windows平台下C++开发的经典框架,为GUI应用程序提供了高度封装的类库支持。其中,CComboBox类是实现下拉选择功能的核心控件之一,但原生控件仅支持单选文本项,无法满足多选需求。复选下拉框作为一种复合型UI组件,在配置管理、权限设置、数据筛选等场景中具有广泛应用价值。本章将系统介绍MFC的消息映射机制、控件自绘原理以及GDI绘图基础,重点剖析CComboBox。
mfc在工具栏上通过CComboboxEx扩展组合框实现的下拉框,有文字和图形
由mfc单文档建立的一个小工程,用于在其工具栏上加入扩展组合框,实现cad等画图工具的宽度选择及颜色选择等,可在其基础上进行扩展。
MFC下拉框的例子,初学者适用
MFC下拉框的例子,刚学的时候找这种例子都找不到,和大家分享!
基于MFC实现list列表通过下拉框改变数据
基于MFC实现list列表通过下拉框改变数据


