📄 alldiary.cpp
字号:
// ALLDiary.cpp : implementation file
//
#include "stdafx.h"
#include "MyDiary.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, 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)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CALLDiary message handlers
BOOL CALLDiary::OnInitDialog()
{
CDialog::OnInitDialog();
CMyDiaryApp *pApp = (CMyDiaryApp *)AfxGetApp();
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];//tchar,16bit的符号,而char是8bit,CString is based on the tchar data type.
LV_COLUMN lvc;
int i;
for ( i = 0; i < 4; i++ )
{
switch(i)
{
case 0:
wsprintf(szBuf, _T("日期"));
//_T(_Text),Generic-Text Data Type,
//meaning converts following character or string to its Unicode counterpart
lvc.cx = 120;
break;
case 1:
wsprintf(szBuf, _T("星期") );
lvc.cx = 70;
break;
case 2:
wsprintf(szBuf, _T("天气") );
lvc.cx = 50;
break;
case 3:
wsprintf(szBuf, _T("内容") );
lvc.cx = 200;
break;
}
lvc.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
//The mask member specifies which column attributes to retrieve
lvc.fmt = LVCFMT_LEFT;
lvc.pszText =szBuf;
//If the mask member specifies the LVCF_TEXT value,
//the pszText member must contain the address of the buffer that receives the item text
lvc.iSubItem = i;
m_list.InsertColumn( i, &lvc );
}
WORD nCount;//word,16 bit无符号整数
POSITION pos;//position,A value used to denote the position of an element in a collection
CString my_date;
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);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CALLDiary::OnButtonDel()
{
// TODO: Add your control notification handler code here
int nSel;
POSITION pos;
CMyDiaryApp *pApp = (CMyDiaryApp *)AfxGetApp();
if(FindMyDiary(nSel, pos))
{
pApp->m_diaryList.RemoveAt(pos);//删除指定位置处的结点
m_list.DeleteItem(nSel);
pApp->onSave();
}
else
{
MessageBox("错误","错误", MB_OK);
}
}
void CALLDiary::OnButtonRemoveall()
{
// TODO: Add your control notification handler code here
CMyDiaryApp *pApp = (CMyDiaryApp *)AfxGetApp();
pApp->m_diaryList.RemoveAll();
m_list.DeleteAllItems();
pApp->onSave();
}
void CALLDiary::OnOK()
{
// TODO: Add extra validation here
CMyDiaryApp *pApp = (CMyDiaryApp *)AfxGetApp();
int nSel;
POSITION pos;
POSITION pos1 = m_list.GetFirstSelectedItemPosition();
//POSITION GetFirstSelectedItemPosition( ) const;
//Return Value
//A POSITION value that can be used for iteration or object pointer retrieval;
//NULL if no items are selected.
if (pos1 == NULL)
{
MessageBox("请先选择所要查看的记录!","提示",MB_OK);
}
else
{
nSel = m_list.GetNextSelectedItem(pos1);
//return the index of the next selected item in the list view control.
pos = pApp->m_diaryList.FindIndex(nSel);
//找到指定结点处的数据
pApp->m_pos = pos;
pApp->is_old = TRUE;
CDialog::OnOK();
}
}
void CALLDiary::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
int CALLDiary::FindMyDiary(int& nSel, POSITION& pos)
{
CMyDiaryApp *pApp = (CMyDiaryApp *)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;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -