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

📄 diarydlg.cpp

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CDiaryDlg dialog

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

void CDiaryDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDiaryDlg)
	DDX_Control(pDX, IDC_EDIT_BODY, m_body);
	DDX_Control(pDX, IDC_DATETIMEPICKER1, m_date);
	DDX_Control(pDX, IDC_COMBO_WEEK, m_week);
	DDX_Control(pDX, IDC_COMBO_WEATHER, m_weather);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CDiaryDlg, CDialog)
	//{{AFX_MSG_MAP(CDiaryDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_COMMAND(ID_MENU_ABOUT, OnMenuAbout)
	ON_COMMAND(ID_MENU_NEW, OnMenuNew)
	ON_COMMAND(ID_MENU_SAVE, OnButtonSave)
	ON_COMMAND(ID_MENU_SHOWALL, OnButtonManger)
	ON_COMMAND(ID_MENU_EXIT, OnOK)
	ON_COMMAND(ID_ABOUT, OnMenuAbout)
	ON_COMMAND(ID_NEW, OnMenuNew)
	ON_COMMAND(ID_SAVE, OnButtonSave)
	ON_COMMAND(ID_SHOW, OnButtonManger)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDiaryDlg message handlers

BOOL CDiaryDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
    CDiaryApp *pApp = (CDiaryApp *)AfxGetApp();
	// 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_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(0);
	////@@@@@@@@@@@@@@@@@@@
    
	pApp->onRead();
	//@@@@@@@@@@@@@@@@@@@@
	//////////////创建工具栏///////////////
	if(!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_TOOLBAR_MAIN))
	{
        TRACE0("Failed to Create Dialog Toolbar\n");
        EndDialog(IDCANCEL);
	}

    CRect rcClientOld; // 久客户区RECT
    CRect rcClientNew; // 加入TOOLBAR后的CLIENT RECT
    GetClientRect(rcClientOld); // 
    // Called to reposition and resize control bars in the client area of a window
   // The reposQuery FLAG does not really traw the Toolbar. It only does the calculations.
   // And puts the new ClientRect values in rcClientNew so we can do the rest of the Math.
    //重新计算RECT大小
    RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0,reposQuery,rcClientNew);

   // All of the Child Windows (Controls) now need to be moved so the Tollbar does not cover them up.
   //所有的子窗口将被移动,以免被TOOLBAR覆盖
   // Offest to move all child controls after adding Tollbar
   //计算移动的距离
    CPoint ptOffset(rcClientNew.left-rcClientOld.left,
    rcClientNew.top-rcClientOld.top);

    CRect rcChild;
    CWnd* pwndChild = GetWindow(GW_CHILD); //得到子窗口
    while(pwndChild) // 处理所有子窗口
	{//移动所有子窗口
        pwndChild->GetWindowRect(rcChild);
        ScreenToClient(rcChild); 
        rcChild.OffsetRect(ptOffset); 
        pwndChild->MoveWindow(rcChild,FALSE); 
        pwndChild = pwndChild->GetNextWindow();
	}

    CRect rcWindow;
    GetWindowRect(rcWindow); // 得到对话框RECT
    rcWindow.right += rcClientOld.Width() - rcClientNew.Width(); // 修改对话框尺寸
    rcWindow.bottom += rcClientOld.Height() - rcClientNew.Height(); 
    MoveWindow(rcWindow,FALSE); // Redraw Window

    RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);
	//////////////////////////////////////
	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 CDiaryDlg::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 CDiaryDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CDiaryDlg::OnButtonSave() 
{
	CTime mm_date;
	memset(&mm_date, 0, sizeof(mm_date));
	CString mm_week, mm_weather, mm_body;
    CDiaryApp *pApp = (CDiaryApp *)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 CDiaryDlg::OnButtonManger() 
{
	POSITION pos;
	CAllDiary alldlg;
   //CString mm_date, mm_week, mm_weather, mm_body;
   CDiaryApp *pApp = (CDiaryApp *)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);
	}
}

void CDiaryDlg::OnMenuAbout() 
{
    CAbooutMe aboutdlg;
	aboutdlg.DoModal();
}

void CDiaryDlg::OnOK() 
{
	if(m_body.GetModify())
	{
		int flag = MessageBox("是否保存?", "提示", MB_ICONQUESTION|MB_YESNOCANCEL);
		if(IDYES == flag)
		{
             OnButtonSave();
			 CDialog::OnOK();
		}
		else if(IDNO == flag)
		{
			CDialog::OnOK();
		}
		else if(IDCANCEL == flag)
		{
		}
		
	}
	else
		CDialog::OnOK();
	
	
}

void CDiaryDlg::OnMenuNew() 
{
	CDiaryApp *pApp = (CDiaryApp *)AfxGetApp();
    pApp->is_old = FALSE;
	pApp->m_pos = NULL;
	m_body.SetWindowText("");
}

⌨️ 快捷键说明

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