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

📄 mydiarydlg.cpp

📁 实现简单的日记本的程序
💻 CPP
字号:
// MyDiaryDlg.cpp : implementation file
//

#include "stdafx.h"
#include "MyDiary.h"
#include "MyDiaryDlg.h"
#include "ALLDiary.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_EDIT, m_body);
	DDX_Control(pDX, IDC_DATETIMEPICKER, m_date);
	DDX_Control(pDX, IDC_COMBO_WEEK, m_week);
	DDX_Control(pDX, IDC_COMBO_WEATHER, m_weather);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMyDiaryDlg, CDialog)
	//{{AFX_MSG_MAP(CMyDiaryDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_COMMAND(ID_MENU_EXIT, OnOK)
	ON_COMMAND(ID_MENU_NEW, OnMenuNew)
	ON_COMMAND(ID_MENU_SAVE, OnMenuSave)
	ON_COMMAND(ID_MENU_SHOWALL, OnMenuShowall)
	//}}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_bttWnd.Create(this);
	m_bttWnd.SetWidth(500);
	m_bttWnd.SetBkColor(RGB(213,253,224));
	m_bttWnd.SetFrameColor(RGB(0,106,53));
	m_bttWnd.AddTool(GetDlgItem(IDC_EDIT),"写下你的每一天,为明天加油!");

    //初始化日期,星期,天气
	m_week.AddString("星期日");
	m_week.AddString("星期一");
	m_week.AddString("星期二");
	m_week.AddString("星期三");
	m_week.AddString("星期四");
	m_week.AddString("星期五");
	m_week.AddString("星期六");

   SYSTEMTIME sysTime;
   memset(&sysTime, 0, sizeof(sysTime));
   m_date.GetTime(&sysTime);
   m_week.SetCurSel(sysTime.wDayOfWeek);


	//weather
	m_weather.AddString("晴");
	m_weather.AddString("阴");
	m_weather.AddString("风");
	m_weather.AddString("雨");
	m_weather.AddString("雾");
	m_weather.AddString("雪");
	m_weather.SetCurSel(1);
	
    
	CMyDiaryApp *pApp = (CMyDiaryApp *)AfxGetApp();
	pApp->onRead();
	
	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::OnOK() 
{
	// TODO: Add your command handler code here
	if(m_body.GetModify())
	{
		int flag = MessageBox("是否保存?", "提示", MB_ICONQUESTION|MB_YESNOCANCEL);
		if(IDYES == flag)
		{
             CMyDiaryApp *pApp = (CMyDiaryApp *)AfxGetApp();
	         pApp->onSave();
			 CDialog::OnOK();
		}
		else if(IDNO == flag)
		{
			CDialog::OnOK();
		}
		else if(IDCANCEL == flag)
		{
		}
		
	}
	else
		CDialog::OnOK();
}

void CMyDiaryDlg::OnMenuNew() 
{
	// TODO: Add your command handler code here
	CMyDiaryApp *pApp = (CMyDiaryApp *)AfxGetApp();
    pApp->is_old = FALSE;
	pApp->m_pos = NULL;
	m_body.SetWindowText("");
}

void CMyDiaryDlg::OnMenuSave() 
{
	// TODO: Add your command handler code here
	CTime mm_date;
	memset(&mm_date, 0, sizeof(mm_date));
	CString mm_week, mm_weather, mm_body;
    CMyDiaryApp *pApp = (CMyDiaryApp *)AfxGetApp();

	m_date.GetTime(mm_date);
	m_week.GetWindowText(mm_week);
	m_weather.GetWindowText(mm_weather);
	m_body.GetWindowText(mm_body);
	if(mm_body == "")
	{
		MessageBox("你还没有写呢!", "提示", MB_OK);
    }
	else
	{
       CMyDiary* pMyDiary = new CMyDiary;
	
	   pMyDiary->m_TDate = mm_date;
	   pMyDiary->m_strWeek = mm_week;
	   pMyDiary->m_strWeather = mm_weather;
	   pMyDiary->m_strBody = mm_body;
	   if(pApp->is_old)
	   {
		   POSITION pos;
		   pos = pApp->m_pos;
           pApp->m_diaryList.SetAt(pos, pMyDiary);//设置指定位置处结点的值
	   }
	   else
	   {
    	   pApp->m_diaryList.AddTail(pMyDiary);
		   pApp->m_pos = pApp->m_diaryList.GetTailPosition();
		   pApp->is_old = TRUE;
	   }
	
	   pApp->onSave();
	}
	m_body.SetModify(FALSE);
}

void CMyDiaryDlg::OnMenuShowall() 
{
	// TODO: Add your command handler code here
	POSITION pos;
	CALLDiary alldlg;
   //CString mm_date, mm_week, mm_weather, mm_body;
   CMyDiaryApp *pApp = (CMyDiaryApp *)AfxGetApp();
   if(IDOK == alldlg.DoModal())
   {
      pos = pApp->m_pos;
	  CMyDiary* pMyDiary = pApp->m_diaryList.GetAt(pos);
      m_date.SetTime(&pMyDiary->m_TDate);
	  m_week.SetWindowText(pMyDiary->m_strWeek);
	  m_weather.SetWindowText(pMyDiary->m_strWeather);
	  m_body.SetWindowText(pMyDiary->m_strBody);
	}
}

BOOL CMyDiaryDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	m_bttWnd.RelayEvent(pMsg);
	return CDialog::PreTranslateMessage(pMsg);
}

⌨️ 快捷键说明

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