notepad - yamaumima/hello.github.io GitHub Wiki

BOOL CNotePadDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	m_edit.SubclassDlgItem(IDC_TEXT,this);
	// 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
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CNotePadDlg::OnFileOpen() 
{
	LPCSTR szFilter = "ๆ–‡ๆœฌๆ–‡ไปถ (*.txt)|*.txt|ๆ‰€ๆœ‰ๆ–‡ไปถ (*.*)|*.*||";

	CFileDialog dlg(TRUE,NULL,"*.txt",OFN_HIDEREADONLY ,szFilter);
	if(dlg.DoModal()==IDCANCEL)
		return;
	CFile file;
	file.Open(dlg.GetPathName(),CFile::modeRead|CFile::shareDenyNone);
	CFileStatus stat;
	file.GetStatus(stat);
	char *pText = new char[stat.m_size + 1];
	int nRet = file.Read(pText,stat.m_size);
	pText[nRet] = 0;//'\0';
	SetDlgItemText(IDC_TEXT,pText);
	delete []pText;
}

void CNotePadDlg::OnFormatFont() 
{
	LOGFONT lf={0};
	if(m_font.GetSafeHandle())
		m_font.GetLogFont(&lf);
	CFontDialog dlg(&lf);
	if(IDCANCEL == dlg.DoModal())
		return;
	dlg.GetCurrentFont(&lf);
	m_font.DeleteObject();
	m_font.CreateFontIndirect(&lf);
	m_edit.SetFont(&m_font);

}