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

📄 作品dlg.cpp

📁 visual c++ 实例编程
💻 CPP
字号:
// 作品Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "作品.h"
#include "作品Dlg.h"
#include "password.h"
#include "setpassword.h"
#include "oldpassword.h"
#include "versiondlg.h"
#include "help.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMyDlg dialog

CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMyDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMyDlg)
	m_editstr = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMyDlg)
	DDX_Control(pDX, IDC_cancel, m_cancel);
	DDX_Control(pDX, IDC_save, m_save);
	DDX_Control(pDX, IDC_EDIT1, m_edit);
	DDX_Control(pDX, IDC_MONTHVIEW, m_month);
	DDX_Text(pDX, IDC_EDIT1, m_editstr);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
	//{{AFX_MSG_MAP(CMyDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_left, Onleft)
	ON_BN_CLICKED(IDC_add, Onadd)
	ON_BN_CLICKED(IDC_save, Onsave)
	ON_BN_CLICKED(IDC_cancel, Oncancel)
	ON_WM_CREATE()
	ON_BN_CLICKED(IDC_BUTTON_password, OnBUTTONpassword)
	ON_COMMAND(ID_MENUITEM32771, OnMenu_left)
	ON_COMMAND(ID_MENUITEM32772, OnMenu_version)
	ON_COMMAND(ID_MENUITEM32773, OnMenu_password)
	ON_COMMAND(ID_MENUITEM32774, OnMenu_adddata)
	ON_COMMAND(ID_MENUITEM32775, OnMenu_help)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyDlg message handlers

BOOL CMyDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// 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	
	year=m_month.GetYear();
	month=m_month.GetMonth();
	day=m_month.GetDay();
	timedata.Format("%d年%d月%d日",year,month,day);
	m_editstr=timedata;
	UpdateData(false);
	if(filesave.Open(timedata+".sav",CFile::modeRead|CFile::typeText,NULL))
	{
		s=readfromfile();
		m_editstr=m_editstr+s;
		UpdateData(false);
	}
	s.TrimLeft();
	if(s!="")
	{
		AfxMessageBox("提醒:您今天有安排。");
	}
//	timedata=time.Format("%y%m%d");
//	AfxMessageBox(timedata);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// 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 CMyDlg::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 CMyDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}



void CMyDlg::Onleft() 
{
	if(save)	
		DestroyWindow();
	else 
		AfxMessageBox("你忘记存盘了!");
}

BEGIN_EVENTSINK_MAP(CMyDlg, CDialog)
    //{{AFX_EVENTSINK_MAP(CMyDlg)
	ON_EVENT(CMyDlg, IDC_MONTHVIEW, 1 /* DateClick */, OnDateClickMonthview, VTS_DATE)
	ON_EVENT(CMyDlg, IDC_MONTHVIEW, 2 /* DateDblClick */, OnDateDblClickMonthview, VTS_DATE)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void CMyDlg::OnDateClickMonthview(DATE DateClicked) 
{
	year=m_month.GetYear();
	month=m_month.GetMonth();
	day=m_month.GetDay();
	timedata.Format("%d年%d月%d日",year,month,day);
	m_editstr=timedata+"\r\n";
	UpdateData(false);
	if(filesave.Open(timedata+".sav",CFile::modeRead|CFile::typeText,NULL))
	{
		s=readfromfile();
		m_editstr=m_editstr+s;
		UpdateData(false);
	}
	else 
		;
}

void CMyDlg::Onadd() 
{
	m_save.EnableWindow(true);
	m_cancel.EnableWindow(true);
	if(filesave.Open(timedata+".sav",CFile::modeRead|CFile::typeText,NULL))
	{
		s=readfromfile();
		m_editstr=s;
		UpdateData(false);
	}
}

void CMyDlg::OnDateDblClickMonthview(DATE DateDblClicked) 
{
	CMyDlg::Onadd();	
}

void CMyDlg::Onsave() 
{	
	UpdateData(true);
	s=m_editstr;
	if(filesave.Open(timedata+".sav",CFile::modeCreate|CFile::modeWrite|CFile::typeText,NULL))
	{
		filesave.WriteString(s);
		m_save.EnableWindow(false);
		m_cancel.EnableWindow(false);
		save=true;
	}
	else
	{
		AfxMessageBox("Can't save the file. ");
		save=false;
	}
	filesave.Close();
}

void CMyDlg::Oncancel() 
{
	m_save.EnableWindow(false);
	m_cancel.EnableWindow(false);	
	save=true;
}





CString CMyDlg::readfromfile(void)
{
	CString s,all="\r\n";
	filesave.ReadString(s);	
	while(filesave.ReadString(s))
	{
		all=all+s+"\r\n";
	}
	filesave.Close();
	return all;
}

int CMyDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CDialog::OnCreate(lpCreateStruct) == -1)
		return -1;
	CStdioFile passwordfile;
	if(passwordfile.Open("std.dat",CFile::modeRead|CFile::typeText,NULL))
	{
		Cpassword pdlg;
		passwordfile.Close();
		pdlg.DoModal();
	}
	return 0;
}

void CMyDlg::OnBUTTONpassword() 
{
	CStdioFile passwordfile;
	if(passwordfile.Open("std.dat",CFile::modeRead,NULL))
	{
		passwordfile.Close();
		Coldpassword oldpassworddlg;
		if(oldpassworddlg.DoModal()==IDOK)
		{
			Csetpassword setpassworddlg;
			setpassworddlg.DoModal();
		}
	}
	else 
	{
		Csetpassword setpassworddlg;
		setpassworddlg.DoModal();
	}
}

void CMyDlg::OnMenu_left() 
{
	// TODO: Add your command handler code here
	CMyDlg::Onleft();
}

void CMyDlg::OnMenu_version() 
{
	// TODO: Add your command handler code here
	CVersiondlg versiondlg;
	versiondlg.DoModal();
}

void CMyDlg::OnMenu_password() 
{
	// TODO: Add your command handler code here
	CMyDlg::OnBUTTONpassword();
}

void CMyDlg::OnMenu_adddata() 
{
	// TODO: Add your command handler code here
	CMyDlg::Onadd();
}

void CMyDlg::OnMenu_help() 
{
	// TODO: Add your command handler code here
	Chelp helpdlg;
	helpdlg.DoModal();
}

⌨️ 快捷键说明

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