?? pagee.cpp
字號(hào):
// PageE.cpp : implementation file
//
#include "stdafx.h"
#include "dlg.h"
#include "PageE.h"
#include "common.h"
#include "RScode.cpp"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern Mapping errors,erasures;
extern int parityNum;
extern CString msg;
extern unsigned char message[msgLEN], code[codeLEN];
/////////////////////////////////////////////////////////////////////////////
// CPageE dialog
CPageE::CPageE(CWnd* pParent /*=NULL*/)
: CDialog(CPageE::IDD, pParent)
{
//{{AFX_DATA_INIT(CPageE)
//}}AFX_DATA_INIT
checked1 = FALSE;
checked2 = FALSE;
}
void CPageE::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPageE)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPageE, CDialog)
//{{AFX_MSG_MAP(CPageE)
ON_BN_CLICKED(IDC_BUTTON_ADD1, OnButtonAdd1)
ON_BN_CLICKED(IDC_BUTTON_DEL1, OnButtonDel1)
ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
ON_BN_CLICKED(IDC_BUTTON_ADD2, OnButtonAdd2)
ON_BN_CLICKED(IDC_BUTTON_DEL2, OnButtonDel2)
ON_BN_CLICKED(IDC_CHECK2, OnCheck2)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPageE message handlers
BOOL CPageE::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CRect rc(0, 0, 0, 0);
GetParent()->GetClientRect(&rc);
((CTabCtrl*)GetParent())->AdjustRect(false, &rc);
MoveWindow(&rc);
ShowText();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CPageE::OnButtonAdd1()
{
// TODO: Add your control notification handler code here
if (!checked1) {
return;
}
CListBox * pLB=(CListBox*)this->GetDlgItem(IDC_LIST1);
CEdit * pEd_pos=(CEdit *)this->GetDlgItem(IDC_EDIT_P1);
CEdit * pEd_data=(CEdit *)this->GetDlgItem(IDC_EDIT_D1);
CString str1, str2;
pEd_pos->GetWindowText(str1);
int key = atoi(LPCTSTR(str1));
if (errors.exist(key)) {
this->MessageBox("This error has already been imported.", NULL, MB_ICONEXCLAMATION | MB_ICONWARNING);
return;
}
if (key > msg.GetLength() || key <= 0) {
this->MessageBox("This error position is abnormal.", NULL, MB_ICONEXCLAMATION | MB_ICONWARNING);
return;
}
pEd_data->GetWindowText(str2);
int value = atoi(LPCTSTR(str2));
if (value<0 || value>255) {
this->MessageBox("DATA must between 0 and 255.", NULL, MB_ICONEXCLAMATION | MB_ICONWARNING);
return;
}
char* str = (char*)calloc(10, sizeof(char));
_itoa(value, str, 16);
str2 = CString(str);
if (!str1.IsEmpty() && !str2.IsEmpty()) {
pLB->AddString(str1+": 0x"+str2);
}
free(str);
errors.add(key, value);
}
void CPageE::OnButtonDel1()
{
// TODO: Add your control notification handler code here
if (checked1) {
CListBox * pLB=(CListBox*)this->GetDlgItem(IDC_LIST1);
int index = pLB->GetCurSel();
pLB->DeleteString(index);
errors.remove(index);
}
}
void CPageE::OnCheck1()
{
// TODO: Add your control notification handler code here
CEdit * pEd_pos=(CEdit *)this->GetDlgItem(IDC_EDIT_P1);
CEdit * pEd_data=(CEdit *)this->GetDlgItem(IDC_EDIT_D1);
CListBox * pLB=(CListBox*)this->GetDlgItem(IDC_LIST1);
CString temp;
temp.Empty();
if (pLB->IsWindowEnabled()) {
int count = pLB->GetCount();
while (count > 0) {
pLB->DeleteString(--count);
}
pEd_pos->EnableWindow(FALSE);
pEd_data->EnableWindow(FALSE);
pLB->EnableWindow(FALSE);
errors.clear();
checked1 = FALSE;
}else {
pEd_pos->SetWindowText(temp);
pEd_data->SetWindowText(temp);
pEd_pos->EnableWindow();
pEd_data->EnableWindow();
pLB->EnableWindow();
checked1 = TRUE;
}
}
void CPageE::OnButtonAdd2()
{
// TODO: Add your control notification handler code here
if (!checked2) {
return;
}
CListBox * pLB=(CListBox*)this->GetDlgItem(IDC_LIST2);
CEdit * pEd_pos=(CEdit *)this->GetDlgItem(IDC_EDIT_P2);
CEdit * pEd_data=(CEdit *)this->GetDlgItem(IDC_EDIT_D2);
CString str1, str2;
pEd_pos->GetWindowText(str1);
pEd_data->GetWindowText(str2);
int key = atoi(LPCTSTR(str1));
if (erasures.exist(key)) {
this->MessageBox("This erasure has already been imported.", NULL, MB_ICONEXCLAMATION | MB_ICONWARNING);
return;
}
if (key > msg.GetLength() || key <= 0) {
this->MessageBox("This erasure position is abnormal.", NULL, MB_ICONEXCLAMATION | MB_ICONWARNING);
return;
}
int value = atoi(LPCTSTR(str2));
if (value<0 || value>255) {
this->MessageBox("DATA must between 0 and 255.", NULL, MB_ICONEXCLAMATION | MB_ICONWARNING);
return;
}
char* str = (char*)calloc(10, sizeof(char));
_itoa(value, str, 16);
str2 = CString(str);
if (!str1.IsEmpty() && !str2.IsEmpty()) {
pLB->AddString(str1+": 0x"+str2);
}
free(str);
erasures.add(key, value);
}
void CPageE::OnButtonDel2()
{
// TODO: Add your control notification handler code here
if (!checked2) {
return;
}
CListBox * pLB=(CListBox*)this->GetDlgItem(IDC_LIST2);
int index = pLB->GetCurSel();
pLB->DeleteString(index);
erasures.remove(index);
}
void CPageE::OnCheck2()
{
// TODO: Add your control notification handler code here
CEdit * pEd_pos=(CEdit *)this->GetDlgItem(IDC_EDIT_P2);
CEdit * pEd_data=(CEdit *)this->GetDlgItem(IDC_EDIT_D2);
CListBox * pLB=(CListBox*)this->GetDlgItem(IDC_LIST2);
if (pLB->IsWindowEnabled()) {
int count = pLB->GetCount();
while (count > 0) {
pLB->DeleteString(--count);
}
pEd_pos->EnableWindow(FALSE);
pEd_data->EnableWindow(FALSE);
pLB->EnableWindow(FALSE);
erasures.clear();
checked2 = FALSE;
}else {
pEd_pos->SetWindowText("");
pEd_data->SetWindowText("");
pEd_pos->EnableWindow();
pEd_data->EnableWindow();
pLB->EnableWindow();
checked2 = TRUE;
}
}
void CPageE::ShowText()
{
CStatic * pStatic=(CStatic *)this->GetDlgItem(IDC_STATIC_TIP);
pStatic->SetWindowText("Parity Num is the number of parity bytes which will be appended to the message to make a codeword. \r\nHere, we assume that it is at least four bytes of parity. In general, with E errors, and K erasures, you will need 2E + K bytes of parity.");
}
void CPageE::OnButton1()
{
// TODO: Add your control notification handler code here
CEdit * pEd_NPAR = (CEdit *)this->GetDlgItem(IDC_NPAR);
CString str;
pEd_NPAR->GetWindowText(str);
parityNum = atoi(LPCTSTR(str));
if (parityNum < 4 || parityNum > 20) {
this->MessageBox("Parity Num must between 4 and 20.", NULL, MB_ICONEXCLAMATION | MB_ICONWARNING);
return;
}
/* Initialization the ECC library */
initialize_ecc ();
/* Encode data into codeword, adding NPAR parity bytes */
int len = msg.GetLength();
for (int i=0; i<len; i++)
message[i] = msg[i];
encode_data(message, len, code);
str.Empty();
for (i = 0; i < parityNum; i++) {
CString temp;
temp.Empty();
temp.Format("%#x", LPCTSTR(code[len+i]));
str += temp;
str += " ";
}
CEdit * pEd_Byte = (CEdit *)this->GetDlgItem(IDC_Bytes);
pEd_Byte->SetWindowText(str);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -