mfc_memo - 8BitsCoding/RobotMentor GitHub Wiki
๊ธฐ๋ณธ์ ์ผ๋ก editctrl์ ์์ฑ์ค์ ์ ์๋์ ๊ฐ์ดํ๋ค.
- Multiline : ์ฌ๋ฌ์ค ์ ๋ ฅ์ ๋ฐ๊ฒ ๋ค.
- No Hide Selection : ๋๋๊ทธ ํ ํฌ์ปค์ค๋ฅผ ์์ด๋ ๋๋๊ทธํ ์ง์ ์ ๋ณด์ฌ์ฃผ๊ฒ ๋ค.
- Want Return : ๋ผ์ธ์ ๋๊ธธ๋ Ctrl+Enter๊ฐ ์๋๋ผ Enter๋ก ๋๊ธฐ๊ฒ ๋ค.
์ฐธ๊ณ , ๊ธฐ๋ณธ์ ์ผ๋ก Visual Studio ๊ธฐ๋ณธ ํ์ผ cpp, h ๋ฑ ์ UTF-8๋ก ์ธ์ฝ๋ฉ ๋์ด ์๋ค.
๋ฐ๋ผ์ ์ฝ๋ฉ ์ ์์ ์ ํ๋ก์ ํธ์์ ์ฌ์ฉํ๋ ์์คํค์ฝ๋, ์ ๋์ฝ๋ ๋ฑ์ ์ธ์ฝ๋ฉ๋ฐฉ์์ผ๋ก ๋ณ๊ฒฝ์ ํด ์ค์ผํ๋ค.
void CMFCApplication2Dlg::OnBnClickedOpenBtn()
{
wchar_t name_file[] = L"๋ชจ๋ ํ์ผ(*.*)|*.*|C++ ํ์ผ(*.cpp)|*.cpp|Header ํ์ผ(*.h)|*.h|ํ
์คํธ ํ์ผ(*.txt)|*.txt||";
CFileDialog ins_dlg(TRUE, L"cpp", L"*.cpp", OFN_HIDEREADONLY | OFN_NOCHANGEDIR, name_file, NULL);
// 1 - TRUE : ํ์ผ ์ด๊ธฐ ๋ํ์์ / FALSE : ํ์ผ ์ ์ฅ ๋ํ์์
// cpp : ํ์ผ ์ด๋ฆ์ ๊ธฐ๋ณธ์ง์
// OFN_NOCHANGEDIR - ์ํน ๋๋ ํฐ๋ฆฌ ์ ๋ณด๋ฅผ ๋ณํํ์ง ์๋๋ค.
// NULL - ๋ถ๋ชจ ์๋์ฐ ๋ฃ๋์๋ฆฌ
ins_dlg.m_ofn.nFilterIndex = 2;
// ๋ํดํธ ํ์ผ ํํฐ์ ์ ํ์ด ํํฐ์ ๋ ๋ฒ์งธ ์ธ์ C++ ํ์ผ(*.cpp)๋ก ์ง์
if (IDOK == ins_dlg.DoModal()) {
SetDlgItemText(IDC_PATH_EDIT, ins_dlg.GetPathName());
// ์ ์ฒด ๊ฒฝ๋ก๋ฅผ ์ถ๋ ฅ
FILE * p_file = NULL;
CString str;
if (0 == _wfopen_s(&p_file, ins_dlg.GetPathName(), L"rt")) {
char temp_str[1024];
int length;
wchar_t unicode_str[1024];
while (fgets(temp_str, 1024, p_file) != NULL) { // ํ ์ค ์ฉ ์ฝ์ด๋๊ฐ๋ค.
// UTF to ์ ๋์ฝ๋
length = MultiByteToWideChar(CP_UTF8, 0, temp_str, -1, NULL, 0);
MultiByteToWideChar(CP_UTF8, 0, temp_str, -1, unicode_str, length);
str += unicode_str;
}
str.Replace(L"\n", L"\r\n"); // ๊ฐํ๋ฌธ์ ์์
SetDlgItemText(IDC_NOTE_EDIT, str);
fclose(p_file);
}
}
}
void CMFCApplication2Dlg::OnBnClickedSaveBtn()
{
wchar_t name_file[] = L"๋ชจ๋ ํ์ผ(*.*)|*.*|C++ ํ์ผ(*.cpp)|*.cpp|Header ํ์ผ(*.h)|*.h|ํ
์คํธ ํ์ผ(*.txt)|*.txt||";
CFileDialog ins_dlg(FALSE, L"cpp", L"*.cpp", OFN_HIDEREADONLY | OFN_NOCHANGEDIR | OFN_OVERWRITEPROMPT, name_file, NULL);
ins_dlg.m_ofn.nFilterIndex = 2;
//OFN_OVERWRITEPROMPT : ์ ์ฅ ์ ํด๋น ํ์ผ์ด ์กด์ฌํ๋ฉด ์ ์ฅํ ์ง ๋ค์ ๋ฌป๊ธฐ
if (IDOK == ins_dlg.DoModal()) {
SetDlgItemText(IDC_PATH_EDIT, ins_dlg.GetPathName());
FILE * p_file = NULL;
CString str;
if (0 == _wfopen_s(&p_file, ins_dlg.GetPathName(), L"wt")) {
GetDlgItemText(IDC_NODE_EDIT, str);
str.Replace(L"\r\n", L"\n");
int length = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
char * p = new char[length];
WideCharToMultiByte(CP_ACP, 0, str, -1, p, length, NULL, NULL);
fwrite(p, length, 1, p_file);
delete[] p;
fclose(p_file);
}
}
}