📄 hexwnd.cpp
字号:
path[len-1] = 'p';
WinHelp (hwnd, path, HELP_CONTENTS, 0);
}
break;
case IDM_EDIT_ENTERDECIMALVALUE:
CMD_edit_enterdecimalvalue ();
break;
case IDM_COPY_HEXDUMP:
CMD_copy_hexdump ();
break;
case IDM_EDIT_COPY:
CMD_edit_copy ();
break;
case IDM_PASTE_WITH_DLG:
CMD_edit_paste ();
break;
case IDM_EDIT_PASTE:
CMD_fast_paste ();
break;
case IDM_ABOUT:
DialogBox (hInstance, MAKEINTRESOURCE (IDD_ABOUTDIALOG), hwnd, (DLGPROC) AboutDlgProc);
break;
case IDM_FIND:
CMD_find ();
break;
case IDM_GO_TO:
CMD_goto();
break;
case IDM_CHANGE_MODE:
character ('\t');
break;
case IDM_SAVE_AS:
CMD_save_as ();
break;
case IDM_SAVE:
CMD_save ();
break;
case IDM_EXIT:
SendMessage (hwnd, WM_CLOSE, 0, 0);
break;
case IDM_SCROLL_UP:
if (iCurLine > 0)
{
iCurLine--;
adjust_vscrollbar ();
repaint ();
}
break;
case IDM_SCROLL_DOWN:
if (iCurLine < iNumlines-1)
{
iCurLine++;
adjust_vscrollbar ();
repaint ();
}
break;
case IDM_SCROLL_LEFT:
if (iHscrollPos > 0)
{
iHscrollPos--;
adjust_hscrollbar ();
repaint ();
}
break;
case IDM_SCROLL_RIGHT:
if (iHscrollPos < iHscrollMax)
{
iHscrollPos++;
adjust_hscrollbar ();
repaint();
}
break;
case IDM_BOTTOM:
{
iCurByte = DataArray.GetUpperBound()+1;
iCurNibble = 1;
iCurLine = BYTELINE-(cyBuffer-1); // Cursor visible on lower border.
if (iCurLine < 0)
iCurLine = 0;
adjust_view_for_caret ();
adjust_vscrollbar ();
bSelected = FALSE;
repaint();
break;
}
case IDM_TOP:
iCurByte = iCurLine = iCurNibble = 0;
adjust_view_for_caret ();
adjust_vscrollbar ();
bSelected = FALSE;
repaint();
break;
case IDM_OPEN:
CMD_open ();
break;
case IDM_NEW:
CMD_new ();
break;
default:
{
char buf[500];
sprintf (buf, "Unknown COMMAND-ID %d.", cmd);
MessageBox (NULL, buf, "frhed ERROR", MB_OK);
}
break;
}
return 0;
}
//--------------------------------------------------------------------------------------------
int HexEditorWindow::destroy_window ()
{
return 0;
}
//--------------------------------------------------------------------------------------------
// Set the window title and the statusbar text.
void HexEditorWindow::set_wnd_title()
{
char buf[512];
if (strlen (filename) != 0)
{
// Change window title.
if (bFilestatusChanged)
{
sprintf (buf, "[%s", filename);
if (m_iFileChanged == TRUE)
strcat (buf, " *");
strcat (buf, "]");
if (bPartialOpen==TRUE)
strcat (buf, " - P");
strcat (buf, " - frhed");
SetWindowText (hwnd, buf);
bFilestatusChanged = FALSE;
}
// Selection going on.
if (bSelected == TRUE)
{
if (iEndOfSelection >= iStartOfSelection)
{
sprintf (buf, "Selected: Offset %d=0x%x to %d=0x%x (%d byte(s))", iStartOfSelection, iStartOfSelection,
iEndOfSelection, iEndOfSelection, iEndOfSelection-iStartOfSelection+1);
}
else
{
sprintf (buf, "Selected: Offset %d=0x%x to %d=0x%x (%d byte(s))", iEndOfSelection, iEndOfSelection,
iStartOfSelection, iStartOfSelection, iStartOfSelection-iEndOfSelection+1);
}
SendMessage (hwndStatusBar, SB_SETTEXT, 0, (LPARAM) buf);
}
else // Normal display.
{
//Pabs changed - \t removed from end of string literal ("Offset %d=0x%x\t" -> "Offset %d=0x%x")
sprintf (buf, "Offset %d=0x%x", iCurByte, iCurByte);
//end
int wordval, longval;
char buf2[80];
//Pabs changed - line insert
if (DataArray.GetLength()-iCurByte > 0){//if we are not looking at the End byte
// R. Kibria: changed the output slightly (used to be "Bits = 0b").
strcat (buf, " Bits=");//append stuff to status text
unsigned char zzz=DataArray[iCurByte];//quicker to have a tmp var than to call operator[] 8 times
for(int i=0;i<8;i++)buf2[i]=((zzz>>i)&0x1?'1':'0');//Extract bits
for(i=0;i<4;i++)swap(buf2[i],buf2[7-i]);//flip order-for some reason it doesn't display correctly going i-- or i++ in for loop
buf2[8]='\0';//terminate string
strcat (buf, buf2);//append to status text
}
strcat (buf, "\t");//add that \t back on to the status text
//end
if (bUnsignedView) // Values signed/unsigned?
{
// UNSIGNED
if (iBinaryMode == LITTLEENDIAN_MODE)
{
// UNSIGNED LITTLEENDIAN_MODE
// Decimal value of byte.
if (DataArray.GetLength ()-iCurByte >= 1)
{
sprintf (buf2, "\tUnsigned: B:%u", (unsigned int) DataArray[iCurByte]);
strcat (buf, buf2);
}
else
{
sprintf (buf2, "\tEND");
strcat (buf, buf2);
}
// Space enough for a word?
if (DataArray.GetLength ()-iCurByte >= 2)
{
// Space enough for a word.
wordval = (DataArray[iCurByte+1] << 8) | DataArray[iCurByte];
sprintf (buf2, ",W:%u", (unsigned int) wordval);
strcat (buf, buf2);
}
if (DataArray.GetLength ()-iCurByte >= 4)
{
// Space enough for a longword.
longval = wordval | (((DataArray[iCurByte + 3] << 8) | DataArray[iCurByte + 2]) << 16);
sprintf (buf2, ",L:%u", (unsigned int) longval);
strcat (buf, buf2);
}
}
else
{
// UNSIGNED BIGENDIAN_MODE
// Decimal value of byte.
if (DataArray.GetLength ()-iCurByte >= 1)
{
sprintf (buf2, "\tUnsigned: B:%u", (unsigned int) DataArray[iCurByte]);
strcat (buf, buf2);
}
else
{
sprintf (buf2, "\tEND");
strcat (buf, buf2);
}
// Space enough for a word?
if (DataArray.GetLength ()-iCurByte >= 2)
{
// Space enough for a word.
wordval = (DataArray[iCurByte] << 8) | DataArray[iCurByte+1];
sprintf (buf2, ",W:%u", (unsigned int) wordval);
strcat (buf, buf2);
}
if (DataArray.GetLength ()-iCurByte >= 4)
{
// Space enough for a longword.
longval = (wordval<<16) | (DataArray[iCurByte+2]<<8) | (DataArray[iCurByte+3]);
sprintf (buf2, ",L:%u", (unsigned int) longval);
strcat (buf, buf2);
}
}
}
else // SIGNED
{
if (iBinaryMode == LITTLEENDIAN_MODE)
{
// SIGNED LITTLEENDIAN_MODE
// Decimal value of byte.
if (DataArray.GetLength ()-iCurByte >= 1)
{
sprintf (buf2, "\tSigned: B:%d", (int) (signed char) DataArray[iCurByte]);
strcat (buf, buf2);
}
else
{
sprintf (buf2, "\tEND");
strcat (buf, buf2);
}
// Space enough for a word?
if (DataArray.GetLength ()-iCurByte >= 2)
{
// Space enough for a word.
wordval = (DataArray[iCurByte + 1] << 8) | DataArray[iCurByte];
sprintf (buf2, ",W:%d", (int) (signed short) wordval);
strcat (buf, buf2);
}
if (DataArray.GetLength ()-iCurByte >= 4)
{
// Space enough for a longword.
longval = wordval | (((DataArray[iCurByte + 3] << 8) | DataArray[iCurByte + 2]) << 16);
sprintf (buf2, ",L:%d", (signed int) longval);
strcat (buf, buf2);
}
}
else
{
// SIGNED BIGENDIAN_MODE
// Decimal value of byte.
if (DataArray.GetLength ()-iCurByte >= 1)
{
sprintf (buf2, "\tSigned: B:%d", (signed char) DataArray[iCurByte]);
strcat (buf, buf2);
}
else
{
sprintf (buf2, "\tEND");
strcat (buf, buf2);
}
// Space enough for a word.
if (DataArray.GetLength ()-iCurByte >= 2)
{
// Space enough for a longword.
wordval = (DataArray[iCurByte] << 8) | DataArray[iCurByte+1];
sprintf (buf2, ",W:%d", (int) (signed short) wordval);
strcat (buf, buf2);
}
if (DataArray.GetLength ()-iCurByte >= 4)
{
// Space enough for a longword.
longval = (wordval<<16) | (DataArray[iCurByte+2]<<8) | (DataArray[iCurByte+3]);
sprintf (buf2, ",L:%d", (signed int) longval);
strcat (buf, buf2);
}
}
}
SendMessage (hwndStatusBar, SB_SETTEXT, 0, (LPARAM) buf);
// Character set, input mode or read-only, binary mode.
switch (iCharacterSet)
{
case ANSI_FIXED_FONT:
sprintf (buf, "\tANSI");
break;
case OEM_FIXED_FONT:
sprintf (buf, "\tOEM");
break;
}
if( bReadOnly )
{
sprintf (buf2, " / READ");
strcat (buf, buf2);
}
else if( iInsertMode )
{
sprintf (buf2, " / INS");
strcat (buf, buf2);
}
else
{
sprintf (buf2, " / OVR");
strcat (buf, buf2);
}
if (iBinaryMode == LITTLEENDIAN_MODE)
{
sprintf (buf2, " / L"); // Intel
strcat (buf, buf2);
}
else if (iBinaryMode == BIGENDIAN_MODE)
{
sprintf (buf2, " / B"); // Motorola
strcat (buf, buf2);
}
SendMessage (hwndStatusBar, SB_SETTEXT, 1, (LPARAM) buf);
// File size.
sprintf (buf, "\tSize: %u", DataArray.GetLength ());
SendMessage (hwndStatusBar, SB_SETTEXT, 2, (LPARAM) buf);
}
}
else
{
SetWindowText (hwnd, "frhed");
SendMessage (hwndStatusBar, WM_SETTEXT, 0, (LPARAM) "No file loaded");
}
}
//--------------------------------------------------------------------------------------------
// Set Caret position.
void HexEditorWindow::set_caret_pos ()
{
if (bSelected)
{
SetCaretPos (-cxChar, -cyChar);
return;
}
int iCaretLine = iCurByte / iBytesPerLine,
iBottomLine = iCurLine + cyBuffer - 1;
switch (m_iEnteringMode)
{
case CHARS:
if (iCaretLine >= iCurLine && iCaretLine <= iBottomLine && filename[0] != '\0')
{
int y = iCaretLine - iCurLine,
x = iOffsetLen+iByteSpace+iBytesPerLine*3+iCharSpace
- iHscrollPos + (iCurByte%iBytesPerLine);
SetCaretPos (CLIENT_BORDER_WIDTH + x*cxChar, CLIENT_BORDER_WIDTH + y*cyChar);
}
else
SetCaretPos (-cxChar, -cyChar);
break;
case BYTES:
// If caret in vertical visible area...
if (iCaretLine >= iCurLine && iCaretLine <= iBottomLine && filename[0] != '\0')
{
int y = iCaretLine - iCurLine,
x = iOffsetLen+iByteSpace + (iCurByte%iBytesPerLine)*3 - iHscrollPos + iCurNibble;
SetCaretPos (CLIENT_BORDER_WIDTH + x*cxChar, CLIENT_BORDER_WIDTH + y*cyChar);
}
else
SetCaretPos (-cxChar, -cyChar);
}
}
//--------------------------------------------------------------------------------------------
// Repaints the whole window.
int HexEditorWindow::repaint( int line )
{
HideCaret( hwnd );
iUpdateLine = line;
InvalidateRect( hwnd, NULL, FALSE );
UpdateWindow( hwnd );
ShowCaret( hwnd );
return 0;
}
//--------------------------------------------------------------------------------------------
// Clear everything up.
void HexEditorWindow::clear_all ()
{
iOffsetLen = 8;
iByteSpace = 2;
iBytesPerLine = 16;
iCharSpace = 1;
iCharsPerLine = iOffsetLen + iByteSpace + iBytesPerLine*3 + iCharSpace + iBytesPerLine;
DataArray.ClearAll ();
filename[0] = '\0';
iVscrollMax = 0;
iVscrollPos = 0;
iVscrollInc = 0;
iHscrollMax = 0;
iHscrollPos = 0;
iHscrollInc = 0;
iCurLine = 0;
iCurByte = 0;
iCurNibble = 0;
}
//--------------------------------------------------------------------------------------------
// Set the vertical scrollbar position.
void HexEditorWindow::adjust_vscrollbar ()
{
iVscrollPos = (int) ((float)iCurLine * ((float)iVscrollMax)/(float)(iNumlines-1));
SetScrollPos (hwndVBar, SB_CTL, iVscrollPos, TRUE);
}
//--------------------------------------------------------------------------------------------
// Set the horizontal scrollbar position.
void HexEditorWindow::adjust_hscrollbar ()
{
SetScrollPos (hwndHBar, SB_CTL, iHscrollPos, TRUE);
}
//--------------------------------------------------------------------------------------------
// Highlight (invert) the character/byte at the current offset.
void HexEditorWindow::mark_char (HDC hdc)
{
if( bDontMarkCurrentPos )
return;
if (bSelected)
{
SetCaretPos (-cxChar, -cyChar);
return;
}
int DC_was_allocated = FALSE;
if (hdc == 0)
{
hdc = GetDC (hwnd);
DC_was_allocated = TRUE;
}
int chpos;
RECT r;
switch (m_iEnteringMode)
{
case CHARS:
chpos = iOffsetLen + iByteSpace + (iCurByte%iBytesPerLine)*3 - iHscrollPos;
r.left = CLIENT_BORDER_WIDTH + chpos * cxChar;
r.top = CLIENT_BORDER_WIDTH + (iCurByte/iBytesPerLine-iCurLine)*cyChar;
r.right = CLIENT_BORDER_WIDTH + r.left + 2*cxChar;
r.bottom = CLIENT_BORDER_WIDTH + (iCurByte/iBytesPerLine-iCurLine+1)*cyChar;
InvertRect (hdc, &r);
break;
case BYTES:
chpos = iOffsetLen + iByteSpace + iBytesPerLine*3 + iCharSpace
+ (iCurByte % iBytesPerLine) - iHscrollPos;
r.left = CLIENT_BORDER_WIDTH + chpos * cxChar;
r.top = CLIENT_BORDER_WIDTH + (iCurByte/iBytesPerLine-iCurLine)*cyChar;
r.right = CLIENT_BORDER_WIDTH + (chpos+1)*cxChar;
r.bottom = CLIENT_BORDER_WIDTH + (iCurByte/iBytesPerLine-iCurLine+1)*cyChar;
InvertRect (hdc, &r);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -