mfc_binary_view_1 - 8BitsCoding/RobotMentor GitHub Wiki


// Dlg.h
CFont m_font;
BOOL CMFCApplication1Dlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// 이 λŒ€ν™” μƒμžμ˜ μ•„μ΄μ½˜μ„ μ„€μ •ν•©λ‹ˆλ‹€.  μ‘μš© ν”„λ‘œκ·Έλž¨μ˜ μ£Ό 창이 λŒ€ν™” μƒμžκ°€ 아닐 κ²½μš°μ—λŠ”
	//  ν”„λ ˆμž„μ›Œν¬κ°€ 이 μž‘μ—…μ„ μžλ™μœΌλ‘œ μˆ˜ν–‰ν•©λ‹ˆλ‹€.
	SetIcon(m_hIcon, TRUE);			// 큰 μ•„μ΄μ½˜μ„ μ„€μ •ν•©λ‹ˆλ‹€.
	SetIcon(m_hIcon, FALSE);		// μž‘μ€ μ•„μ΄μ½˜μ„ μ„€μ •ν•©λ‹ˆλ‹€.

	// TODO: 여기에 μΆ”κ°€ μ΄ˆκΈ°ν™” μž‘μ—…μ„ μΆ”κ°€ν•©λ‹ˆλ‹€.
	m_font.CreatePointFont(128, L"꡴림체");
	m_bin_data_list.SetFont(&m_font);

	return TRUE;  // 포컀슀λ₯Ό μ»¨νŠΈλ‘€μ— μ„€μ •ν•˜μ§€ μ•ŠμœΌλ©΄ TRUEλ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.
}
void CMFCApplication1Dlg::OnBnClickedSelectBtn()
{
	CFileDialog ins_dlg(TRUE);
	// TRUE : νŒŒμΌμ—΄κΈ°
	// FALSE : λ‹€λ₯Έμ΄λ¦„μœΌλ‘œ μ €μž₯

	if (IDOK == ins_dlg.DoModal()) {
		SetDlgItemText(IDC_PATH_STATIC, ins_dlg.GetPathName());
		m_bin_data_list.ResetContent();

		FILE * p_file = NULL;
		if (_wfopen_s(&p_file, ins_dlg.GetPathName(), L"rb") == 0) {
			unsigned char temp[24];
			//CString total_str, str;
			wchar_t str[128];

			int len = 24, line = 0, str_len;
			while (len == 24) {
				len = fread(temp, 1, 24, p_file);		// freadλŠ” μ‹€μ œλ‘œ 읽은 λ°”μ΄νŠΈλ§ŒνΌ 리턴됨
				if (len > 0) {
					//total_str.Empty();
					str_len = swprintf_s(str, 128, L"%06d : ", line++);
					//total_str.Format(L"%06d : ", line++);
					for (int i = 0; i < 24; i++) {
						str_len += swprintf_s(str + str_len, 128 - str_len, L"%02X ", temp[i]);
					}
					m_bin_data_list.InsertString(-1, str);
				}
			}
			
			/*
			// CString Style
			unsigned char temp[24];
			CString total_str, str;

			int len = 24, line = 0;
			while (len == 24) {
				len = fread(temp, 1, 24, p_file);		// freadλŠ” μ‹€μ œλ‘œ 읽은 λ°”μ΄νŠΈλ§ŒνΌ 리턴됨
				if (len > 0) {
					//total_str.Empty();
					total_str.Format(L"%06d : ", line++);
					for (int i = 0; i < 24; i++) {
						str.Format(L"%02X ", temp[i]);
						total_str += str;
					}
					m_bin_data_list.InsertString(-1, total_str);
				}
			}
			*/
			
			fclose(p_file);
		}
	}
}