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

📄 calendarinfo.cpp

📁 wince5.0下的计算器程序,对初学wince的朋友很有帮助,arm9平台下的
💻 CPP
字号:
// Calendarinfo.cpp : implementation file
//

#include "stdafx.h"
#include "AdbCalendar.h"
#include "Calendarinfo.h"

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

/////////////////////////////////////////////////////////////////////////////
// CCalendarinfo dialog


CCalendarinfo::CCalendarinfo(CWnd* pParent /*=NULL*/)
	: CDialog(CCalendarinfo::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCalendarinfo)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CCalendarinfo::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCalendarinfo)
	DDX_Control(pDX, IDC_CALTIME, m_caltime);
	DDX_Control(pDX, IDC_CALDATE, m_caldate);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CCalendarinfo, CDialog)
	//{{AFX_MSG_MAP(CCalendarinfo)
	ON_WM_ERASEBKGND()
	ON_BN_CLICKED(IDC_BUTADD, OnButadd)
	ON_BN_CLICKED(IDC_BUTDEL, OnButdel)
	ON_BN_CLICKED(IDC_BUTCANCEL, OnButcancel)
	ON_BN_CLICKED(IDC_CHALARM, OnChalarm)
	ON_NOTIFY(NM_CLICK, IDC_CALENDARLIST, OnClickCalendarlist)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCalendarinfo message handlers

BOOL CCalendarinfo::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	this->SetWindowPos(this,0,26,240,294,SWP_SHOWWINDOW );
//	CRect rc;
//	GetWindowRect(rc);
//	this->MoveWindow(rc.left,rc.top,240,294);

	m_crinfo.InitCalendarInof();
	InitContrl();

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

BOOL CCalendarinfo::OnEraseBkgnd(CDC* pDC) 
{
	// TODO: Add your message handler code here and/or call default
	CDC bkdc;
	CBitmap temp;
	temp.LoadBitmap(IDB_BKMAP1);
	bkdc.CreateCompatibleDC(pDC);
	CBitmap *pOldBitmap=bkdc.SelectObject(&temp);
	CRect rc;
	GetClientRect(rc);

	pDC->BitBlt(0,0,rc.Width(),rc.Height(),&bkdc,0,0,SRCCOPY);
	temp.Detach();
	temp.DeleteObject();
	return true;
//	return CDialog::OnEraseBkgnd(pDC);
}

void CCalendarinfo::OnButadd() 
{
	// TODO: Add your control notification handler code here

	if (!m_blsaves)
	{
		//当前是新日程
		m_butadd.SetWindowText(TEXT("完成"));
		ClearCalendarInfo();
		EnableConctrl(TRUE);
		m_blsaves=!m_blsaves;
	}
	else
	{
		if (SaveNewInfo())
		{
			m_butadd.SetWindowText(TEXT("新日程"));
			m_blsaves=!m_blsaves;
			EnableConctrl(FALSE);
			ShowLogInfo();
		}
	}
}

void CCalendarinfo::OnButdel() 
{
	// TODO: Add your control notification handler code here
	BOOL blgx=FALSE;
	CStatic *m_state=(CStatic *)GetDlgItem(IDC_STSHOWSE);
	CListCtrl *m_clist=(CListCtrl *)GetDlgItem(IDC_CALENDARLIST);

	m_state->ShowWindow(SW_SHOW);
	m_state->SetWindowText(TEXT("正在删除选择的日程信息"));
	CString str;
	int nid,nsel;
	for(int i=0;i<m_clist->GetItemCount();i++)
	{
		if (m_clist->GetCheck(i))
		{
			//钩选
			blgx=TRUE;
			str=m_clist->GetItemText(i,0);
			nid=_wtoi(str);
			if (nid<=0)
			{
				continue ;
			}
			m_crinfo.DelLog(nid);
		}
	}

	if (!blgx)
	{
		nsel=m_clist->GetNextItem(-1,LVIS_SELECTED);
		if (nsel!=-1)
		{
			str=m_clist->GetItemText(nsel,0);
			nid=_wtoi(str);
			m_crinfo.DelLog(nid);
		}
	}

	m_state->ShowWindow(SW_HIDE);
	ShowLogInfo();
}

void CCalendarinfo::OnButcancel() 
{
	// TODO: Add your control notification handler code here
	OnCancel();
}

void CCalendarinfo::ShowLogInfo()
{
	CListCtrl *m_clist=(CListCtrl *)GetDlgItem(IDC_CALENDARLIST);
	CRLog temp;
	CString str;
	m_clist->DeleteAllItems();
	int lognum=m_crinfo.GetLogNumCount();
	for (int i=0;i<lognum;i++)
	{
		ZeroMemory(&temp,sizeof(CRLog));
		if(m_crinfo.FindForIndex(temp,i))
		{
			//找到了,显示出来吧
			str=TEXT("");
			str.Format(TEXT("%d"),temp.LID);
			m_clist->InsertItem(m_clist->GetItemCount(),str,0);
			
			m_clist->SetItemText(m_clist->GetItemCount()-1,1,temp.rename);
			m_clist->SetItemText(m_clist->GetItemCount()-1,2,temp.redate);
			if (temp.bAlarm==0)
			{
				m_clist->SetItemText(m_clist->GetItemCount()-1,3,TEXT("0"));
			}
			else
			{
				m_clist->SetItemText(m_clist->GetItemCount()-1,3,TEXT("1"));
			}
			m_clist->SetItemText(m_clist->GetItemCount()-1,4,temp.retime);
			m_clist->SetItemText(m_clist->GetItemCount()-1,5,temp.reinfo);
		}

	}
}

BOOL CCalendarinfo::SaveNewInfo()
{
	CRLog temp;
	CEdit *m_emotif=(CEdit *)GetDlgItem(IDC_EMOTIF);
	CButton *m_chalarm=(CButton *)GetDlgItem(IDC_CHALARM);
	CEdit *m_einfo=(CEdit *)GetDlgItem(IDC_EINFO);

	ZeroMemory(&temp,sizeof(CRLog));
	CString str=TEXT("");

	temp.LID=m_crinfo.GetFreeID();
	m_emotif->GetWindowText(str);
	if (str.GetLength()<=0)
	{
		MessageBox(TEXT("没有录入日程主题\r\n请输入后保存"),TEXT("保存错误"),MB_OK);
		return FALSE;
	}
	lstrcpy(temp.rename,str);

	str=TEXT("");
	CTime tt;
	m_caldate.GetTime(tt);
	str.Format(TEXT("%04d-%02d-%02d"),tt.GetYear(),tt.GetMonth(),tt.GetDay());
	lstrcpy(temp.redate,str);

	if (m_chalarm->GetCheck()==0)
	{
		temp.bAlarm=0;
	}
	else if(m_chalarm->GetCheck()==1)
	{
		temp.bAlarm=1;
		str=TEXT("");
		m_caltime.GetTime(tt);
		str.Format(TEXT("%02d:%02d:%02d"),tt.GetHour(),tt.GetMinute(),tt.GetSecond());
		lstrcpy(temp.retime,str);
	}
	str=TEXT("");
	m_einfo->GetWindowText(str);
	if (str.GetLength()>100)
	{
		MessageBox(TEXT("日程内容超过100个字符\r\n请检查"),TEXT("保存错误"),MB_OK);
		return FALSE;
	}
	if (str.GetLength()>0)
	{
		lstrcpy(temp.reinfo,str);
	}
	return m_crinfo.AddLog(temp);
}

void CCalendarinfo::ClearCalendarInfo()
{
	CEdit *m_emotif=(CEdit *)GetDlgItem(IDC_EMOTIF);
	CButton *m_chalarm=(CButton *)GetDlgItem(IDC_CHALARM);
	CEdit *m_einfo=(CEdit *)GetDlgItem(IDC_EINFO);
	
	m_emotif->SetWindowText(TEXT(""));
	m_caldate.SetTime(&(CTime::GetCurrentTime()));
	m_chalarm->SetCheck(0);
	m_einfo->SetWindowText(TEXT(""));
}

void CCalendarinfo::OnOK()
{
	return ;
}

void CCalendarinfo::InitContrl()
{
	CRect rc,lrc,strc,erc;
	GetClientRect(rc);
	CListCtrl *m_clist=(CListCtrl *)GetDlgItem(IDC_CALENDARLIST);
	m_clist->SetExtendedStyle(m_clist->GetExtendedStyle() |LVS_EX_CHECKBOXES |LVS_EX_GRIDLINES |LVS_EX_FULLROWSELECT);
	m_clist->SetBkColor(CLR_NONE);
	m_clist->SetTextBkColor(CLR_NONE);
	lrc.left=5;
	lrc.top=30;
	lrc.right=rc.Width()-5;
	lrc.bottom=120;
	m_clist->MoveWindow(lrc);

	m_clist->InsertColumn(0,TEXT("ID"),LVCFMT_LEFT,18);
	m_clist->InsertColumn(1,TEXT("主题"),LVCFMT_LEFT,lrc.Width()-103);
	m_clist->InsertColumn(2,TEXT("日期"),LVCFMT_LEFT,80);
	m_clist->InsertColumn(3,TEXT("闹铃"),LVCFMT_LEFT,0);
	m_clist->InsertColumn(4,TEXT("时间"),LVCFMT_LEFT,0);
	m_clist->InsertColumn(5,TEXT("内容"),LVCFMT_LEFT,0);

	
	//**********
	ShowLogInfo();
	//***********

//	CButton *m_kj=(CButton *)GetDlgItem(IDC_STKJ);
	strc.left=lrc.left;
	strc.top=lrc.bottom+5;
	strc.right=lrc.right;
	strc.bottom=strc.top+125;
	m_butKJ.SubclassDlgItem(IDC_STKJ,this);
	m_butKJ.MoveWindow(strc);
	m_butKJ.SetJBBKColor(RGB(207,234,199),RGB(207,234,199));
//	m_kj->ShowWindow(SW_HIDE);

	m_stmotif.SubclassDlgItem(IDC_STMOTIF,this);
	erc.left=strc.left+10;
	erc.top=strc.top+10;
	erc.right=erc.left+45;
	erc.bottom=erc.top+20;
	m_stmotif.MoveWindow(erc);
	m_stmotif.SetWindowText(TEXT("主题"));
	m_stmotif.SetJAlign(1);
	m_stmotif.SetJBColor(RGB(207,234,199),RGB(0,0,0),RGB(0,0,0));
	m_stmotif.SetJBord(TRUE);

	CEdit *m_emotif=(CEdit *)GetDlgItem(IDC_EMOTIF);
	erc.left=erc.left+erc.Width()+10;
	erc.right=strc.Width()-5;
	erc.top+=2;
	erc.bottom-=2;
	m_emotif->MoveWindow(erc);
	m_emotif->EnableWindow(FALSE);

	m_stdate.SubclassDlgItem(IDC_STDATE,this);
	erc.left=strc.left+10;
	erc.top=strc.top+33;
	erc.right=erc.left+45;
	erc.bottom=erc.top+20;
	m_stdate.MoveWindow(erc);
	m_stdate.SetWindowText(TEXT("日期"));
	m_stdate.SetJAlign(1);
	m_stdate.SetJBColor(RGB(207,234,199),RGB(0,0,0),RGB(0,0,0));
	m_stdate.SetJBord(TRUE);

	erc.left=erc.left+erc.Width()+10;
	erc.right=strc.Width()-5;
	erc.top+=1;
	erc.bottom-=1;
	m_caldate.MoveWindow(erc);
	m_caldate.EnableWindow(FALSE);

	CButton *m_chalarm=(CButton *)GetDlgItem(IDC_CHALARM);
	erc.left=strc.left+10;
	erc.top=strc.top+62;
	erc.right=erc.left+45;
	erc.bottom=erc.top+16;
	m_chalarm->MoveWindow(erc);
	m_chalarm->SetWindowText(TEXT("闹铃"));
	m_chalarm->EnableWindow(FALSE);

	erc.left=erc.left+erc.Width()+10;
	erc.top-=2;
	erc.right=strc.Width()-5;
	erc.bottom=erc.top+21;
	m_caltime.MoveWindow(erc);
	m_caltime.EnableWindow(FALSE);

	m_stneir.SubclassDlgItem(IDC_STINFO,this);
	erc.left=strc.left+10;
	erc.top=strc.top+90;
	erc.right=erc.left+45;
	erc.bottom=erc.top+20;
	m_stneir.MoveWindow(erc);
	m_stneir.SetWindowText(TEXT("内容"));
	m_stneir.SetJAlign(1);
	m_stneir.SetJBColor(RGB(207,234,199),RGB(0,0,0),RGB(0,0,0));
	m_stneir.SetJBord(TRUE);

	CEdit *m_einfo=(CEdit *)GetDlgItem(IDC_EINFO);
	erc.left=erc.left+erc.Width()+10;
	erc.top-=4;
	erc.right=strc.Width()-5;
	erc.bottom+=8;

	m_einfo->MoveWindow(erc);
	m_einfo->EnableWindow(FALSE);

	erc.left=lrc.left;
	erc.top=rc.Height()-35;
	erc.right=erc.left+50;
	erc.bottom=erc.top+28;
	m_butadd.SubclassDlgItem(IDC_BUTADD,this);
	m_butadd.MoveWindow(erc);
	m_butadd.SetWindowText(TEXT("新日程"));
	m_blsaves=FALSE;

	erc.left=(rc.Width()-50)/2;
	erc.right=erc.left+50;
	m_butdel.SubclassDlgItem(IDC_BUTDEL,this);
	m_butdel.MoveWindow(erc);
	m_butdel.SetWindowText(TEXT("删除"));

	erc.left=rc.Width()-55;
	erc.right=erc.left+50;
	m_butcancel.SubclassDlgItem(IDC_BUTCANCEL,this);
	m_butcancel.MoveWindow(erc);
	m_butcancel.SetWindowText(TEXT("返回"));

	CStatic *m_state=(CStatic *)GetDlgItem(IDC_STSHOWSE);
	erc.left=strc.left;
	erc.top=strc.top;
	erc.right=strc.right;
	erc.bottom=rc.bottom;
//	m_ststate.SubclassDlgItem(IDC_STSHOWSE,this);
	m_state->MoveWindow(erc);
	m_state->ShowWindow(SW_HIDE);

}

void CCalendarinfo::EnableConctrl(BOOL nval)
{
	CEdit *m_emotif=(CEdit *)GetDlgItem(IDC_EMOTIF);
	CButton *m_chalarm=(CButton *)GetDlgItem(IDC_CHALARM);
	CEdit *m_einfo=(CEdit *)GetDlgItem(IDC_EINFO);

	m_emotif->EnableWindow(nval);
	m_chalarm->EnableWindow(nval);
	m_caltime.EnableWindow(nval);
	m_einfo->EnableWindow(nval);
	m_caldate.EnableWindow(nval);
}

void CCalendarinfo::OnChalarm() 
{
	// TODO: Add your control notification handler code here
	CButton *m_chalarm=(CButton *)GetDlgItem(IDC_CHALARM);
	if (m_chalarm->GetCheck()==0)
	{
		//未选择
		m_caltime.EnableWindow(FALSE);
	}
	else if (m_chalarm->GetCheck()==1)
	{
		m_caltime.EnableWindow(TRUE);
	}
}

void CCalendarinfo::OnClickCalendarlist(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	CListCtrl *m_clist=(CListCtrl *)GetDlgItem(IDC_CALENDARLIST);
	CEdit *m_emotif=(CEdit *)GetDlgItem(IDC_EMOTIF);
	CButton *m_chalarm=(CButton *)GetDlgItem(IDC_CHALARM);
	CEdit *m_einfo=(CEdit *)GetDlgItem(IDC_EINFO);
	int nsel=m_clist->GetNextItem(-1,LVIS_SELECTED);
	if (nsel==-1)
		return;
	CString str;
	str=m_clist->GetItemText(nsel,1);//主题
	m_emotif->SetWindowText(str);
	str=TEXT("");
	str=m_clist->GetItemText(nsel,2);//日期
	int gy,gm,gd;
	gy=_wtoi(str.Mid(0,4));
	gm=_wtoi(str.Mid(5,2));
	gd=_wtoi(str.Right(2));
	CTime dt(gy,gm,gd,1,1,1,0);
	m_caldate.SetTime(&dt);
	str=TEXT("");
	str=m_clist->GetItemText(nsel,3);//闹铃
	if (str.Compare(TEXT("0"))==0)
	{
		//未启用
		m_chalarm->SetCheck(0);
		m_caltime.EnableWindow(FALSE);
	}
	else
	{
		m_chalarm->SetCheck(1);
		str=m_clist->GetItemText(nsel,4);
		gy=_wtoi(str.Left(2));
		gm=_wtoi(str.Mid(3,2));
		gd=_wtoi(str.Right(2));
		CTime ttx(2007,7,21,gy,gm,gd,0);
		m_caltime.SetTime(&ttx);
		m_caltime.EnableWindow(FALSE);
	}

	str=TEXT("");
	str=m_clist->GetItemText(nsel,5);
	m_einfo->SetWindowText(str);
	*pResult = 0;
}

⌨️ 快捷键说明

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