⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlglistbox.cpp

📁 hen zhongyao de xuexiziliao 稀飯哦
💻 CPP
字号:
// DlgListBox.cpp : implementation file
//

#include "stdafx.h"
#include "Ex5.h"
#include "DlgListBox.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDlgListBox dialog


CDlgListBox::CDlgListBox(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgListBox::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgListBox)
	m_strEdit1 = _T("");
	//}}AFX_DATA_INIT
}


void CDlgListBox::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgListBox)
	DDX_Control(pDX, IDC_LIST1, m_List1);
	DDX_Text(pDX, IDC_EDIT1, m_strEdit1);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgListBox, CDialog)
	//{{AFX_MSG_MAP(CDlgListBox)
	ON_BN_CLICKED(IDC_Del, OnDel)
	ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgListBox message handlers

void CDlgListBox::OnOK() 
{
	// TODO: Add extra validation here
	UpdateData();
	if(m_strEdit1.IsEmpty())
	{
		MessageBox("编辑框不能为空");
		return;
	}
	if((m_List1.FindString(-1,m_strEdit1))!=LB_ERR)
	{
		MessageBox("列表框中已有相同姓名,不能添加!");
		return;
	}
	int nIndex=m_List1.AddString(m_strEdit1);

//	CDialog::OnOK();
}

void CDlgListBox::OnDel() 
{
	// TODO: Add your control notification handler code here
	int nIndex=m_List1.GetCurSel();
	if(nIndex!=LB_ERR)
	{
		m_List1.DeleteString(nIndex);
		m_strEdit1.Empty();
		UpdateData(FALSE);
	}
	else
		MessageBox("当前没有选择项或列表框操作失败!");
}

void CDlgListBox::OnSelchangeList1() 
{
	// TODO: Add your control notification handler code here
	int nIndex=m_List1.GetCurSel();
	{
		m_List1.GetText(nIndex,m_strEdit1);
		UpdateData(false);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -