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

📄 listboxdlg.cpp

📁 c++编写的常用控件
💻 CPP
字号:
// ListBoxDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Ex_CommCtrls.h"
#include "ListBoxDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CListBoxDlg dialog


CListBoxDlg::CListBoxDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CListBoxDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CListBoxDlg)
	m_strName = _T("");
	m_nScore1 = 0;
	m_nScore2 = 0;
	m_nScore3 = 0;
	//}}AFX_DATA_INIT
}


void CListBoxDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CListBoxDlg)
	DDX_Control(pDX, IDC_LIST1, m_List);
	DDX_Text(pDX, IDC_STU_NAME, m_strName);
	DDV_MaxChars(pDX, m_strName, 20);
	DDX_Text(pDX, IDC_SCORE1, m_nScore1);
	DDV_MinMaxInt(pDX, m_nScore1, 0, 100);
	DDX_Text(pDX, IDC_SCORE2, m_nScore2);
	DDV_MinMaxInt(pDX, m_nScore2, 0, 100);
	DDX_Text(pDX, IDC_SCORE3, m_nScore3);
	DDV_MinMaxInt(pDX, m_nScore3, 0, 100);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CListBoxDlg, CDialog)
	//{{AFX_MSG_MAP(CListBoxDlg)
	ON_BN_CLICKED(IDC_DATA_ADD, OnDataAdd)
	ON_BN_CLICKED(IDC_DATA_DEL, OnDataDel)
	ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1)
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CListBoxDlg message handlers

void CListBoxDlg::OnDataAdd() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if(m_strName.IsEmpty())
	{
		MessageBox("姓名不能为空!");
		return;
	}
	m_strName.TrimLeft();
	m_strName.TrimRight();
	if((m_List.FindString(-1,m_strName))!=LB_ERR)
	{
		MessageBox("列表框中已有相同姓名,不能添加!");
		return;
	}
	int nIndex=m_List.AddString(m_strName);
	SCORE data;
	data.score1=m_nScore1;
	data.score2=m_nScore2;
	data.score3=m_nScore3;
	m_List.SetItemDataPtr(nIndex,new SCORE(data));
}

void CListBoxDlg::OnDataDel() 
{
	// TODO: Add your control notification handler code here
	int nIndex=m_List.GetCurSel();
	if (nIndex!=LB_ERR)
	{
		m_List.DeleteString(nIndex);
	    m_strName.Empty();
		m_nScore1=m_nScore2=m_nScore3=0;
		UpdateData(FALSE);
	}
	else MessageBox("当前没有选择项或列表框操作失败!");
}

void CListBoxDlg::OnSelchangeList1() 
{
	// TODO: Add your control notification handler code here
	int nIndex=m_List.GetCurSel();
	if(nIndex!=LB_ERR)
	{
		m_List.GetText(nIndex,m_strName);
		SCORE*data=(SCORE*)m_List.GetItemDataPtr(nIndex);
		m_nScore1=data->score1;
		m_nScore2=data->score2;
		m_nScore3=data->score3;
		UpdateData(FALSE);
	}	
}

void CListBoxDlg::OnDestroy() 
{
	for(int nIndex=m_List.GetCount()-1;nIndex>=0;nIndex--)
	{
		delete(SCORE*)m_List.GetItemDataPtr(nIndex);
	}
	CDialog::OnDestroy();
	
	// TODO: Add your message handler code here
	
}

⌨️ 快捷键说明

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