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

📄 alldiary.cpp

📁 一个vc编写的日记
💻 CPP
字号:
// AllDiary.cpp : implementation file
//

#include "stdafx.h"
#include "Diary.h"
#include "AllDiary.h"


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

/////////////////////////////////////////////////////////////////////////////
// CAllDiary dialog


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


void CAllDiary::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAllDiary)
	DDX_Control(pDX, IDC_LIST_DIARY, m_list);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CAllDiary, CDialog)
	//{{AFX_MSG_MAP(CAllDiary)
	ON_BN_CLICKED(IDC_BUTTON_DEL, OnButtonDel)
	ON_BN_CLICKED(IDC_BUTTON_REMOVEALL, OnButtonRemoveall)
	ON_BN_CLICKED(ID_CANCEL, OnCancel)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAllDiary message handlers

BOOL CAllDiary::OnInitDialog() 
{
	CDialog::OnInitDialog();
	CDiaryApp *pApp = (CDiaryApp *)AfxGetApp();
    //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2
	m_list.SetBkColor(RGB(0,128,128));
	m_list.SetTextBkColor(RGB(0,128,128));
	m_list.SetTextColor(RGB(255,255,0));

	m_list.SetExtendedStyle( LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP );
	TCHAR szBuf[20];
	LV_COLUMN lvc;
	
	int i;
	for ( i = 0; i < 4; i++ )
	{
		//lvc.cx       = 48+14*i;
		switch(i)
		{
			case 0:
				wsprintf(szBuf, _T("日期"));
				lvc.cx = 100;
				break;
			case 1:
				wsprintf(szBuf, _T("星期") );
				lvc.cx = 50;
				break;
			case 2:
				wsprintf(szBuf, _T("天气") );
				lvc.cx = 30;
				break;
			case 3:
				wsprintf(szBuf, _T("内容") );
				lvc.cx = 200;
			break;
		}
		lvc.mask     = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
		lvc.fmt      = LVCFMT_LEFT;
		lvc.pszText  =szBuf;
		lvc.iSubItem = i;         
		//lvc.cx       = 48+14*i;
		m_list.InsertColumn( i, &lvc );
	}
	//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	WORD nCount;
	POSITION pos;
	CString my_date;
    //pApp->onRead();
    
	//UpdateData(TRUE);
    nCount = (WORD)pApp->m_diaryList.GetCount();
	pos = pApp->m_diaryList.GetHeadPosition();
	for(int k = 0; k < nCount && pos != NULL; k++)
	{
	   CMyDiary* pMyDiary = pApp->m_diaryList.GetNext(pos);
	   m_list.InsertItem(k,LPSTR_TEXTCALLBACK);
	   my_date = pApp->TimetoCString(pMyDiary->m_TDate);
	   m_list.SetItemText(k, 0, my_date);
	   m_list.SetItemText(k, 1, pMyDiary->m_strWeek);
	   m_list.SetItemText(k, 2, pMyDiary->m_strWeather);
	   m_list.SetItemText(k, 3, pMyDiary->m_strBody);
	}
	//UpdateData(FALSE);
	//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CAllDiary::OnButtonDel() 
{
    int nSel;
	POSITION pos;
	CDiaryApp *pApp = (CDiaryApp *)AfxGetApp();
	if(FindMyDiary(nSel, pos))
	{
        pApp->m_diaryList.RemoveAt(pos);
		m_list.DeleteItem(nSel);
		pApp->onSave();
	}
	else
	{
		MessageBox("错误","错误", MB_OK);
	}
}

int CAllDiary::FindMyDiary(int& nSel, POSITION& pos)
{
    CDiaryApp *pApp = (CDiaryApp *)AfxGetApp();
	POSITION pos1 = m_list.GetFirstSelectedItemPosition();
	if (pos1 == NULL)
	{
		MessageBox("请先选择所要删除的记录!","提示",MB_OK);
		return NULL;
	}
	else
	{
	   nSel = m_list.GetNextSelectedItem(pos1);
	}

	pos = pApp->m_diaryList.FindIndex(nSel);
	ASSERT(pos != NULL);
	return 1;
}

void CAllDiary::OnOK() 
{
	CDiaryApp *pApp = (CDiaryApp *)AfxGetApp();
    int nSel;
	POSITION pos;
	POSITION pos1 = m_list.GetFirstSelectedItemPosition();
	if (pos1 == NULL)
	{
		MessageBox("请先选择所要查看的记录!","提示",MB_OK);
		//return NULL;
	}
	else
	{
	   nSel = m_list.GetNextSelectedItem(pos1);
	   pos = pApp->m_diaryList.FindIndex(nSel);
	   //m_saver.m_nSel = nSel;
	   pApp->m_pos = pos;
	   pApp->is_old = TRUE;
	   CDialog::OnOK();
	}
	
}

void CAllDiary::OnCancel() 
{
	CDialog::OnCancel();	
}

void CAllDiary::OnButtonRemoveall() 
{
	CDiaryApp *pApp = (CDiaryApp *)AfxGetApp();
    pApp->m_diaryList.RemoveAll();
	m_list.DeleteAllItems();
	pApp->onSave();
}

⌨️ 快捷键说明

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