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

📄 active.cpp

📁 一个非常简单地址簿程序
💻 CPP
字号:
// Active.cpp : implementation file
//

#include "stdafx.h"
#include "MyAL.h"
#include "Active.h"
#include "ActiveSet.h"

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

/////////////////////////////////////////////////////////////////////////////
// CActive dialog


CActive::CActive(CWnd* pParent /*=NULL*/)
	: CDialog(CActive::IDD, pParent)
{
	//{{AFX_DATA_INIT(CActive)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_bIsAdd = FALSE;
	m_bIsEdit = FALSE;
}


void CActive::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CActive)
	DDX_Control(pDX, IDC_ACTIVELIST, m_ActiveList);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CActive, CDialog)
	//{{AFX_MSG_MAP(CActive)
	ON_BN_CLICKED(IDC_ADDACTIVE, OnAddactive)
	ON_BN_CLICKED(IDC_EDIT, OnEdit)
	ON_NOTIFY(NM_CLICK, IDC_ACTIVELIST, OnClickActivelist)
	ON_BN_CLICKED(IDC_DEL, OnDel)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CActive message handlers

BOOL CActive::OnInitDialog() 
{
	CDialog::OnInitDialog();
	m_ActiveList.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
	m_ActiveList.SetHeadings(_T("内容摘要,125;日期,96;活动类型,70"));
	
	int nItem = m_activeArray.GetSize();
	for(int i=0;i<nItem;i++)
	{
		int nYear = m_activeArray[i].m_Date.GetYear();
		int nMonth = m_activeArray[i].m_Date.GetMonth();
		int nDay = m_activeArray[i].m_Date.GetDay();
		CString strDate;
		strDate.Format("%d年%d月%d日",nYear,nMonth,nDay);

		m_ActiveList.AddItem(m_activeArray[i].m_Summary,strDate,m_activeArray[i].m_Type);
	}

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CActive::OnAddactive() 
{	
	dlg.m_bIsAdd = TRUE;
	if(dlg.DoModal()==IDOK)
	{
		m_Active.m_ID = m_activeArray.GetSize();
		m_Active.m_Date = dlg.m_OleActiveDate;
		m_Active.m_Type = dlg.m_strType;
		m_Active.m_Clew = dlg.m_bClew;
		m_Active.m_Summary = dlg.m_strSummary;

		m_activeArray.Add(m_Active);
		
		int i = m_activeArray.GetUpperBound();
		
		int nYear = m_activeArray[i].m_Date.GetYear();
		int nMonth = m_activeArray[i].m_Date.GetMonth();
		int nDay = m_activeArray[i].m_Date.GetDay();
		CString strDate;
		strDate.Format("%d年%d月%d日",nYear,nMonth,nDay);
		
		m_ActiveList.AddItem(m_activeArray[i].m_Summary,strDate,m_activeArray[i].m_Type);
	}
	dlg.m_bIsAdd = FALSE;
}

void CActive::OnEdit() 
{
	int i,nState;		
	int nItemCount=m_ActiveList.GetItemCount();
	
	for(i=nItemCount-1;i>=0;i--)
	{
		nState=m_ActiveList.GetItemState(i,LVIS_SELECTED);
		if(nState!=0)
		{
			break;
		}
	}

	dlg.m_bClew = m_activeArray[i].m_Clew;
	dlg.m_OleActiveDate = m_activeArray[i].m_Date;
	dlg.m_strSummary = m_activeArray[i].m_Summary;
	dlg.m_strType = m_activeArray[i].m_Type;
	
	if(dlg.DoModal()==IDOK)
	{
		m_activeArray[i].m_Date = dlg.m_OleActiveDate;
		m_activeArray[i].m_Type = dlg.m_strType;
		m_activeArray[i].m_Clew = dlg.m_bClew;
		m_activeArray[i].m_Summary = dlg.m_strSummary;

		m_ActiveList.SetItemText(i,0,m_activeArray[i].m_Summary);
		
		int nYear = m_activeArray[i].m_Date.GetYear();
		int nMonth = m_activeArray[i].m_Date.GetMonth();
		int nDay = m_activeArray[i].m_Date.GetDay();
		CString strDate;
		strDate.Format("%d年%d月%d日",nYear,nMonth,nDay);
		m_ActiveList.SetItemText(i,1,strDate);

		m_ActiveList.SetItemText(i,2,m_activeArray[i].m_Type);

		TRACE("%d",m_activeArray[i].m_Clew);
	}
}

void CActive::OnDel() 
{
	int i,nState;		
	int nItemCount=m_ActiveList.GetItemCount();
	
	for(i=nItemCount-1;i>=0;i--)
	{
		nState=m_ActiveList.GetItemState(i,LVIS_SELECTED);
		if(nState!=0)
		{
			m_activeArray.RemoveAt(i);
			m_ActiveList.DeleteItem(i);
		}
	}

	if(m_ActiveList.GetItemCount()==0)
	{
		CWnd* pEdit = GetDlgItem(IDC_EDIT);
		CWnd* pDel = GetDlgItem(IDC_DEL);
		pEdit->EnableWindow(FALSE);
		pDel->EnableWindow(FALSE);
	}
}

void CActive::OnClickActivelist(NMHDR* pNMHDR, LRESULT* pResult) 
{
	CWnd* pEdit = GetDlgItem(IDC_EDIT);
	CWnd* pDel = GetDlgItem(IDC_DEL);
	
	int nItemSelected=m_ActiveList.GetSelectedCount();

	if(nItemSelected>0)
	{
		pEdit->EnableWindow(TRUE);
		pDel->EnableWindow(TRUE);
	}
	else
	{
		pEdit->EnableWindow(FALSE);
		pDel->EnableWindow(FALSE);
	}
	
	*pResult = 0;
}

void CActive::OnOK() 
{
}

void CActive::OnCancel() 
{
}

⌨️ 快捷键说明

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