main() { char choice; Initial(); while(1) { choice = MenuSelect(); switch (choice) { case 1:EnterData(); break; case 2:DeleteLine(); break; case 3:List(); break; case 4:exit(0); } } }
LRESULT HexView::OnChar(UINT nChar) { if(nChar < 32) return 0; if(m_nEditMode == HVMODE_READONLY) { MessageBeep(MB_ICONASTERISK); return 0; } if(m_nWhichPane == 0) // hex column { int cl[4] = { 2, 3, 3, 8 }; int cb[4] = { 16, 10, 8, 2 }; //int cw[4] = { 2, 3, 3, 2 }; int cf = m_nControlStyles & HVS_FORMAT_MASK; int val; BYTE b = 0; // get data under caret if(m_nSubItem > 0) { b = m_pDataSeq->getlastmodref(); } else { GetData(m_nCursorOffset, &b, 1); } // check this is an allowed character if(cf == HVS_FORMAT_HEX && !isxdigit(nChar) || cf == HVS_FORMAT_DEC && !(nChar >= '0' && nChar <= '9') || cf == HVS_FORMAT_OCT && !(nChar >= '0' && nChar <= '7') || cf == HVS_FORMAT_BIN && !(nChar >= '0' && nChar <= '1') ) { MessageBeep(MB_ICONASTERISK); return 0; } int val2; if(nChar >= 'a') val2 = nChar - 'a' + 0x0a; else if(nChar >= 'A') val2 = nChar - 'A' + 0x0A; else val2 = nChar - '0'; int power = 1; int base = cb[cf]; for(int i = cl[cf] - 1; i > m_nSubItem; i--) power *= base; if(m_nEditMode == HVMODE_INSERT) b = 0; val = b; val = (val / power) % base; val *= power; val = b - val; val += val2 * power; // check that we won't overflow the underlying value if(val > 0xff) { //MessageBeep(MB_ICONASTERISK); //return 0; val -= b % power; } if(m_nSubItem++ == 0) { b = (BYTE)val; // enter the data EnterData(&b, 1, m_nWhichPane == 0 ? false : true, true, false); } else { // directly edit the byte in the sequence - this // prevents us from introducing any more spans than necessary // and keeps this as a single 'byte' edit m_pDataSeq->getlastmodref() = val; ContentChanged(); if(m_nSubItem == cl[cf]) { m_nSubItem = 0; m_nCursorOffset++; } RepositionCaret(); } } else { BYTE b = nChar; // ascii column - enter the data as-is m_nSubItem = 0; EnterData(&b, 1, true, true, false); } return 0; }