📄 mydiarydlg.cpp
字号:
// MyDiaryDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MyDiary.h"
#include "MyDiaryDlg.h"
#include "DiaryStore.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDiaryDlg dialog
CMyDiaryDlg::CMyDiaryDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyDiaryDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMyDiaryDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMyDiaryDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDiaryDlg)
DDX_Control(pDX, IDC_CONTENT_EDIT, m_Body);
DDX_Control(pDX, IDC_DATETIMEPICKER1, m_Date);
DDX_Control(pDX, IDC_WEATHER_COMBO, m_Weather);
DDX_Control(pDX, IDC_DAY_COMBO, m_Day);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyDiaryDlg, CDialog)
//{{AFX_MSG_MAP(CMyDiaryDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_COMMAND(ID_EXIT, OnExit)
ON_COMMAND(ID_NEW_DIARY, OnNewDiary)
ON_COMMAND(ID_ABOUT, OnAbout)
ON_COMMAND(ID_STORE_DIARY, OnStoreDiary)
ON_EN_CHANGE(IDC_CONTENT_EDIT, OnChangeContentEdit)
ON_COMMAND(ID_SAVE_DIARY, OnSaveDiary)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDiaryDlg message handlers
BOOL CMyDiaryDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
//初始化星期
m_Day.AddString("星期天");
m_Day.AddString("星期一");
m_Day.AddString("星期二");
m_Day.AddString("星期三");
m_Day.AddString("星期四");
m_Day.AddString("星期五");
m_Day.AddString("星期六");
// m_Day.SetCurSel(0);
//初始化天气
m_Weather.AddString("阴");
m_Weather.AddString("晴");
m_Weather.AddString("雾");
m_Weather.AddString("雨");
m_Weather.SetCurSel(0);
//初始化日期
SYSTEMTIME systime;
memset(&systime,0,sizeof(systime));
m_Date.GetTime(&systime);
m_Day.SetCurSel(systime.wDayOfWeek);
//创建工具栏
if(!m_ToolBar.Create(this)||!m_ToolBar.LoadToolBar(IDR_TOOLBAR_MAIN))
{
return FALSE;
}
CRect rect;
GetDlgItem(IDC_TOOLBAR_STATIC)->GetWindowRect(&rect);
ScreenToClient(&rect);
m_ToolBar.MoveWindow(&rect);
//加载菜单栏
CMenu menu;
menu.LoadMenu(IDR_MENU_MAIN);
SetMenu(&menu);
menu.Detach();
//
CMyDiaryApp * pApp = (CMyDiaryApp *)AfxGetApp();
pApp->OnRead();
// m_sOld.Empty();
return TRUE; // return TRUE unless you set the focus to a control
}
void CMyDiaryDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CMyDiaryDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMyDiaryDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMyDiaryDlg::OnExit()
{
// TODO: Add your command handler code here
OnOK();
}
void CMyDiaryDlg::OnNewDiary()
{
// TODO: Add your command handler code here
if(m_Body.GetModify())
{
WORD msg;
msg = MessageBox("文件已经修改,是否保存保存!","Message",MB_OKCANCEL|MB_ICONWARNING);
if(msg == IDOK)
OnSaveDiary();
else
m_Body.SetWindowText("");
}
else
m_Body.SetWindowText("");
// UpdateData(FALSE);
}
void CMyDiaryDlg::OnAbout()
{
// TODO: Add your command handler code here
CAboutDlg dlg;
dlg.DoModal();
}
void CMyDiaryDlg::OnStoreDiary()
{
// TODO: Add your command handler code here
CDiaryStore dlg;
if(dlg.DoModal() == IDOK)
{
CDiary *ry = dlg.ry;
m_Body.SetWindowText(ry->m_txtBody);
m_Day.SetWindowText(ry->m_week);
m_Weather.SetWindowText(ry->m_weather);
SYSTEMTIME time;
memset(&time,0,sizeof(time));
time.wDay = ry->m_date.GetDay();
time.wYear = ry->m_date.GetYear();
time.wMonth = ry->m_date.GetMonth();
m_Date.SetTime(&time);
// UpdateData(FALSE);
m_Body.GetWindowText(m_sOld);
}
}
void CMyDiaryDlg::OnChangeContentEdit()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
CString m_sChange;
m_Body.GetWindowText(m_sChange);
// m_sChange.Compare(&m_sOld);
if(m_sOld == m_sChange)
return;
else
m_Body.SetModify(TRUE);
}
void CMyDiaryDlg::OnSaveDiary()
{
// TODO: Add your command handler code here
CTime mm_date;
memset(&mm_date,0,sizeof(mm_date));
CString mm_week,mm_weather,mm_txtBody;
m_Date.GetTime(mm_date);
m_Day.GetWindowText(mm_week);
m_Weather.GetWindowText(mm_weather);
m_Body.GetWindowText(mm_txtBody);
CMyDiaryApp *pApp = (CMyDiaryApp *)AfxGetApp();
if(mm_txtBody == "")
MessageBox("你还没有写呢!","提示信息",MB_OK);
else
{
CDiary * pDiary = new CDiary;
pDiary->m_date = mm_date;
pDiary->m_week = mm_week;
pDiary->m_weather = mm_weather;
pDiary->m_txtBody = mm_txtBody;
if(pApp->is_old)
{
POSITION pos;
pos = pApp->m_pos;
pApp->m_DiaryList.SetAt(pos,pDiary);
}
else
{
pApp->is_old = TRUE;
pApp->m_DiaryList.AddTail(pDiary);
pApp->m_pos = pApp->m_DiaryList.GetTailPosition();
}
pApp->OnSave();
}
m_Body.SetModify(FALSE);
}
void CMyDiaryDlg::OnShow(POSITION pos)
{
CMyDiaryApp * pApp = (CMyDiaryApp *)AfxGetApp();
CDiary * pd = (CDiary *)pApp->m_DiaryList.GetAt(pos);
CString str = pd->m_txtBody;
m_Body.SetWindowText(str);
// UpdateData(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -