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

📄 noterdlg.cpp

📁 电子笔记
💻 CPP
字号:
// noterDlg.cpp : implementation file
//

#include "stdafx.h"
#include "noter.h"
#include "noterDlg.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()

/////////////////////////////////////////////////////////////////////////////
// CNoterDlg dialog

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

void CNoterDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CNoterDlg)
	DDX_Text(pDX, IDC_EDIT_BORED, m_bored);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CNoterDlg, CDialog)
	//{{AFX_MSG_MAP(CNoterDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_AUTHDATE, OnButtonAuthdate)
	ON_BN_CLICKED(IDC_BUTTON_CONTENT, OnButtonContent)
	ON_BN_CLICKED(IDC_BUTTON_SAVE, OnButtonSave)
	ON_BN_CLICKED(IDC_BUTTON_TITLE, OnButtonTitle)
	ON_BN_CLICKED(IDC_BUTTON_HLINE, OnButtonHline)
	ON_BN_CLICKED(IDC_BUTTON_OPENNOTE, OnButtonOpennote)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNoterDlg message handlers

BOOL CNoterDlg::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
	modified=false;
	filenew=true;
	flength=0;
	fhead=_T("<html><head><title>读书笔记</title><meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\"></head><body bgcolor=\"#FFFFFF\" text=\"#000000\">");
	ftail=_T("</body></html>");

	int headleng=fhead.GetLength();
	for(int hadd=0;hadd<headleng;hadd++)
	{
		datepool[flength]=fhead.GetAt(hadd);
		flength++;
	}

	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

void CNoterDlg::OnButtonAuthdate() 
{
	UpdateData(TRUE);
	CString fauthdate=_T("<p><font color=\"#669966\">") + m_bored + _T("</font></p>");
		
	int authdateleng=fauthdate.GetLength();
	for(int hadd=0;hadd<authdateleng;hadd++)
	{
		datepool[flength]=fauthdate.GetAt(hadd);
		flength++;
	}
	
	m_bored.Empty();
	GetDlgItem(IDC_EDIT_BORED)->SetFocus();
	UpdateData(FALSE);
	modified=true;
	
	
}

void CNoterDlg::OnButtonContent() 
{
	UpdateData(TRUE);
	CString fbody= _T("<p>") + m_bored + _T("</p>");
		
	int bodyleng=fbody.GetLength();
	for(int hadd=0;hadd<bodyleng;hadd++)
	{
		datepool[flength]=fbody.GetAt(hadd);
		flength++;
	}
	
	m_bored.Empty();	
	GetDlgItem(IDC_EDIT_BORED)->SetFocus();
	UpdateData(FALSE);
	modified=true;

}

void CNoterDlg::OnButtonSave() 
{
	int tailleng=ftail.GetLength();
	for(int tadd=0;tadd<tailleng;tadd++)
	{
		datepool[flength]=ftail.GetAt(tadd);
		flength++;
	}

	if(filenew)
	{
        CString hfilter=_T( "Html Files (*.htm;*.html)|*.htm; *.html|All Files (*.*)|*.*||");
        CFileDialog  sfd(FALSE,"htm","note",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,hfilter);
        if(sfd.DoModal()==IDOK)
		{
	         CString sfpn=sfd.GetPathName();
	         CFile hfnote;
	         hfnote.Open( sfpn, CFile::modeCreate | CFile::modeWrite );
	         hfnote.WriteHuge(datepool,flength);
	         hfnote.Close();
	         CleanMem();
	         AfxMessageBox("笔记已保存,内容已清空。");
		}
        else
	         flength-=tailleng;
	}
	else
	{
	     CFile hfnote;
	     hfnote.Open( oldfn, CFile::modeCreate | CFile::modeWrite );
	     hfnote.WriteHuge(datepool,flength);
	     hfnote.Close();
	     CleanMem();
	     AfxMessageBox("笔记已保存,内容已清空。");
	}

 	m_bored.Empty();
	GetDlgItem(IDC_EDIT_BORED)->SetFocus();
	UpdateData(FALSE);
}

void CNoterDlg::OnButtonTitle() 
{
	UpdateData(TRUE);
	CString ftitle=_T("<hr><p><font color=\"#FF0000\"><b><font size=\"5\">") + m_bored + _T("</font></b></font></p>");
		
	int titleleng=ftitle.GetLength();
	for(int hadd=0;hadd<titleleng;hadd++)
	{
		datepool[flength]=ftitle.GetAt(hadd);
		flength++;
	}
	
	m_bored.Empty();
	GetDlgItem(IDC_EDIT_BORED)->SetFocus();
	UpdateData(FALSE);
	modified=true;
	
	
}

void CNoterDlg::OnCancel() 
{
	if(modified)
	{
		int isave=AfxMessageBox("是否保存读书笔记?",MB_YESNOCANCEL );
		if(isave==IDYES)
		{
            OnButtonSave();
			CDialog::OnCancel();

		}
		else if(isave==IDNO)
		{
            CDialog::OnCancel();
		}
		else
		{
            return;
		}		
	}

	else
	   CDialog::OnCancel();

}

void CNoterDlg::CleanMem()
{
	filenew=true;
	modified=false;
    flength=fhead.GetLength();
	m_bored.Empty();
	UpdateData(FALSE);
   
}

void CNoterDlg::OnButtonHline() 
{
	CString fhline= _T("<hr>");
		
	int hlineleng=fhline.GetLength();
	for(int hadd=0;hadd<hlineleng;hadd++)
	{
		datepool[flength]=fhline.GetAt(hadd);
		flength++;
	}
	GetDlgItem(IDC_EDIT_BORED)->SetFocus();		
	UpdateData(FALSE);
	modified=true;

}

void CNoterDlg::OnButtonOpennote() 
{
    CString hfilter=_T( "Html Files (*.htm;*.html)|*.htm; *.html|All Files (*.*)|*.*||");
    CFileDialog  sfd(TRUE,"htm",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,hfilter);
        if(sfd.DoModal()==IDOK)
		{
	         CString sfpn=sfd.GetPathName();
	         CFile hfnote;
	         hfnote.Open( sfpn, CFile::modeRead);
			 flength=hfnote.GetLength();
			 if(flength>=500000)
			 {
                 AfxMessageBox(_T("原笔记已经太大,不能继续添加!已建新笔记!"));
                 CleanMem();
				 hfnote.Close();
				 return;
			 }
			 hfnote.SeekToBegin();
	         hfnote.ReadHuge(datepool,flength);
	         hfnote.Close();
			 flength=flength-ftail.GetLength();
			 filenew=false;
			 oldfn=sfpn;
		}
  	
}

⌨️ 快捷键说明

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