?? hexeditwnd.cpp
字號(hào):
return FALSE; // ERR
// autosel next pair
if (pp->x - uxCurPair - 2*uFontWidth > uFontWidth / 2)
{
++uPair;
uxCurPair += DIGIT_PAIR_WIDTH;
}
}
// out of range?
if (IsOutOfRange(stat.dwCurOffset + uLine * 16 + uPair))
return FALSE; // ERR
// x -> LOWORD ?
ppos->bHiword = ((UINT)pp->x > uxCurPair + uFontWidth) ? FALSE: TRUE;
// save offset
ppos->dwOffset = stat.dwCurOffset + uLine * 16 + uPair;
return TRUE; // OK
}
// in text field ?
else if ((DWORD)pp->x >= CHARS_X &&
(DWORD)pp->x < CHARS_X + uFontWidth * 16 &&
//(DWORD)pp->y < uMaxLines * uFontHeight + iyHETop)
(DWORD)pp->y >= iyHETop &&
(DWORD)pp->y < iyHETop + uMaxLines * uFontHeight)
{
uLine = ((DWORD)pp->y - iyHETop) / uFontHeight;
uPair = (UINT)pp->x - CHARS_X;
uPair /= uFontWidth;
// out of range?
if (IsOutOfRange(stat.dwCurOffset + uLine * 16 + uPair))
return FALSE; // ERR
// build output
ppos->bTextSection = TRUE;
ppos->bHiword = TRUE;
ppos->dwOffset = stat.dwCurOffset + uLine * 16 + uPair;
return TRUE; // OK
}
else
return FALSE; // ERR
}
//
// cursor key,... handling
//
BOOL HexEditWnd::HEHandleWM_KEYDOWN(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HE_POS posNew;
int iNewLine;
DWORD dwOff;
// caret already set
if (!stat.bCaretPosValid)
return FALSE; // ERR
//
// handle special keys
//
// tab key
switch(wParam)
{
case VK_TAB:
// switch between text/data fields
if (stat.bCaret)
{
// kill sel
if (stat.bSel)
KillSelection();
// reset caret
stat.posCaret.bTextSection ^= TRUE;
stat.posCaret.bHiword = TRUE;
SetCaret();
// make visible if is not
if (!IsOffsetVisible(stat.posCaret.dwOffset))
SetTopLine();
return TRUE; // OK
}
else
return FALSE; // ERR
}
// shift key
if ( IsKeyDown(VK_SHIFT) )
{
posNew = stat.posCaret;
switch(wParam)
{
case VK_LEFT: // left
posNew.dwOffset--;
break;
case VK_RIGHT: // right
posNew.dwOffset++;
break;
case VK_NEXT: // page down
posNew.dwOffset += uMaxLines * 16;
break;
case VK_PRIOR: // page up
posNew.dwOffset -= uMaxLines * 16;
break;
case VK_DOWN: // down
posNew.dwOffset += 16;
break;
case VK_UP: // up
posNew.dwOffset -= 16;
break;
default:
return FALSE; // ERR
}
// validate
if (ValidatePos(&posNew))
Beep();
if (stat.bSel)
{
if (stat.dwOffSelStart == stat.posCaret.dwOffset)
dwOff = stat.dwOffSelEnd;
else
dwOff = stat.dwOffSelStart;
SetSelection( dwOff, posNew.dwOffset);
}
else
SetSelection( stat.posCaret.dwOffset, posNew.dwOffset );
SetCaret(&posNew);
MakeCaretVisible();
return TRUE; // OK
}
//
// move caret in HE area / move current line
//
posNew = stat.posCaret;
iNewLine = GetCurrentLine();
switch(wParam)
{
case VK_NEXT: // page down
posNew.dwOffset += uMaxLines * 16;
iNewLine += uMaxLines;
break;
case VK_PRIOR: // page up
posNew.dwOffset -= uMaxLines * 16;
iNewLine -= uMaxLines;
break;
case VK_DOWN: // down
posNew.dwOffset += 16;
++iNewLine;
break;
case VK_UP: // up
posNew.dwOffset -= 16;
--iNewLine;
break;
case VK_RIGHT: // rigth
if (stat.posCaret.bTextSection)
{
++posNew.dwOffset;
posNew.bHiword = TRUE;
}
else
{
posNew.bHiword ^= 1;
if (!stat.posCaret.bHiword)
++posNew.dwOffset;
}
break;
case VK_LEFT: // left
if (stat.posCaret.bTextSection)
{
--posNew.dwOffset;
posNew.bHiword = TRUE;
}
else
{
posNew.bHiword ^= 1;
if (stat.posCaret.bHiword)
--posNew.dwOffset;
}
break;
case VK_BACK:
if (stat.posCaret.bTextSection)
--posNew.dwOffset;
break;
default:
return FALSE; // ERR
}
// changes -> GUI
if (stat.bSel &&
wParam != VK_RIGHT &&
wParam != VK_LEFT)
{
// validate
if (ValidateLine(&iNewLine))
Beep();
// set
SetCurrentLine(iNewLine);
}
else
{
// validate
if (ValidatePos(&posNew))
Beep();
// set
KillSelection();
SetCaret(&posNew);
MakeCaretVisible();
}
return TRUE; // OK
}
//
// if caret isn't in the visible area, the top line is reset
//
// returns:
// whether it was needed to reset the top line
//
BOOL HexEditWnd::MakeCaretVisible()
{
DWORD dwLastVisibleOff;
if (IsOffsetVisible(stat.posCaret.dwOffset))
return FALSE; // ERR
dwLastVisibleOff = __min(uMaxLines * 16 + stat.dwCurOffset,
diData.dwSize);
if (stat.posCaret.dwOffset < stat.dwCurOffset) // caret above ?
SetTopLine((int)(stat.posCaret.dwOffset / 16));
else // caret below
SetTopLine((int)(stat.posCaret.dwOffset / 16 - uMaxLines + 1));
return TRUE; // OK
}
//
// corrects the information in a given HE_POS structure if it's out of range
//
// returns:
// whether sth was fixed
//
BOOL HexEditWnd::ValidatePos(PHE_POS ppos)
{
if ((int)ppos->dwOffset < 0)
{
ppos->dwOffset = 0;
ppos->bHiword = TRUE;
return TRUE; // OK
}
else if (ppos->dwOffset >= diData.dwSize)
{
ppos->dwOffset = diData.dwSize - 1;
ppos->bHiword = FALSE;
return TRUE; // OK
}
else
return FALSE; // ERR
}
//
// returns:
// last caret status
//
BOOL HexEditWnd::SetCaretSet(BOOL bSet)
{
BOOL bRet;
bRet = stat.bCaret;
stat.bCaret = bSet;
return bRet;
}
//
// set the V scrollbar range relative to "diData.dwSize"
//
void HexEditWnd::SetupVScrollbar()
{
DWORD dwTotalLines = GetTotalLineNum();
SetScrollRange(hMainWnd, SB_VERT, 0, (int)(dwTotalLines - 1), TRUE);
return;
}
UINT HexEditWnd::GetTotalLineNum()
{
DWORD dwTotalLines;
dwTotalLines = diData.dwSize / 16;
if (diData.dwSize % 16)
++dwTotalLines;
return dwTotalLines;
}
//
// handles V scrollbar movement
//
BOOL HexEditWnd::HEHandleWM_VSCROLL(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
int nPos;
SCROLLINFO scrollinfo = { sizeof(SCROLLINFO) };
nPos = GetScrollPos(hWnd, SB_VERT);
switch(LOWORD(wParam))
{
case SB_THUMBPOSITION:
case SB_THUMBTRACK:
// get the tracking position
scrollinfo.fMask = SIF_TRACKPOS;
GetScrollInfo(hWnd, SB_VERT, &scrollinfo);
nPos = scrollinfo.nTrackPos;
break;
case SB_TOP:
nPos = 0;
break;
case SB_BOTTOM:
nPos = GetTotalLineNum() - 1;
break;
case SB_LINEDOWN:
++nPos;
break;
case SB_LINEUP:
--nPos;
break;
case SB_PAGEDOWN:
nPos += uMaxLines;
break;
case SB_PAGEUP:
nPos -= uMaxLines;
break;
}
return SetTopLine((int)nPos);
}
//
// sets the line to the top of the visible data range
//
BOOL HexEditWnd::SetTopLine(int iNewLine)
{
int nNewPos;
nNewPos = iNewLine;
// validation
if (nNewPos < 0)
nNewPos = 0;
nNewPos = __min(nNewPos, (int)GetTotalLineNum() - 1);
// avoid repainting ?
if (nNewPos == stat.iLastLine)
return TRUE; // OK
// set new line
SetScrollPos(hMainWnd, SB_VERT, nNewPos, TRUE);
stat.iLastLine = nNewPos;
// set new offset
stat.dwCurOffset = nNewPos * 16;
// reset caret
if (stat.bCaretPosValid)
SetCaret();
// repaint
RepaintClientArea();
return TRUE; // OK
}
//
// overloaded
//
BOOL HexEditWnd::SetTopLine(DWORD dwOffset)
{
return SetTopLine( (int)dwOffset / 16);
}
//
// overloaded
//
BOOL HexEditWnd::SetTopLine()
{
return SetTopLine((DWORD)stat.posCaret.dwOffset);
}
void HexEditWnd::RepaintClientArea()
{
InvalidateRect(hMainWnd, NULL, FALSE);
return;
}
void HexEditWnd::RepaintClientAreaNow()
{
RepaintClientArea();
UpdateWindow(hMainWnd);
return;
}
void HexEditWnd::HEHandleWM_MOUSEWHEEL(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
int nPos;
short int iDelta;
iDelta = (int)HIWORD(wParam);
nPos = GetScrollPos(hWnd, SB_VERT);
if (iDelta > 0)
{
// move up
nPos -= WHEEL_MOVE_STEPS;
}
else
{
// move down
nPos += WHEEL_MOVE_STEPS;
}
SetTopLine((int)nPos);
return;
}
void HexEditWnd::HEHandleWM_SHOWWINDOW(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HEdit.HESetFont(HEdit.hFont);
SetupVScrollbar();
ConfigureTB();
SetHEWndCaption();
return;
}
void HexEditWnd::Beep()
{
MessageBeep(MB_ICONEXCLAMATION);
return;
}
BOOL HexEditWnd::HEHandleWM_COMMAND(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(LOWORD(wParam))
{
case TB_GOTO:
if (DialogBoxParam( GetInstance(), (PSTR)IDD_GOTO, hWnd, GotoDlgProc, 0) &&
stat.bCaretPosValid)
{
SetTopLine();
SetCaret(&stat.posCaret);
}
return TRUE;
case TB_SELBLOCK:
DialogBoxParam( GetInstance(), (PSTR)IDD_SELBLOCK, hWnd, SelBlockDlgProc, 0);
return TRUE;
case TB_SELALL:
SelectAll();
return TRUE;
case TB_SEARCH:
DialogBoxParam( GetInstance(), (PSTR)IDD_SEARCH, hWnd, SearchDlgProc, 0);
return TRUE;
case TB_SEARCHDOWN:
case TB_SEARCHUP:
PerformSearchAgain(&search, LOWORD(wParam) == TB_SEARCHDOWN ? TRUE : FALSE);
return TRUE;
case TB_WIN2TOP:
SetHEWnd2Top( bHEOnTop ^ 1 );
ConfigureTB();
return TRUE;
case TB_SAVE:
SaveChanges();
return TRUE;
case TB_UNDO:
UndoChanges();
return TRUE;
case TB_CUT:
CutSelectedBlock();
return TRUE;
case TB_COPY:
CopySelectedBlock();
return TRUE;
case TB_PASTE:
PasteBlockFromCB();
return TRUE;
case TB_ABOUT:
ShowAbout();
return TRUE;
case TB_CLOSE:
HEditQuit();
return TRUE;
//
// tray menu commands (IDT_XXX)
//
case IDT_RESTORE:
HEditReturnFromTray();
return TRUE;
case IDT_EXIT:
HEditKillTrayIcon();
HEditQuit();
return TRUE;
}
return FALSE; // ERR
}
BOOL HexEditWnd::HEHandleWM_NOTIFY(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
//
// offer TB tooltips
//
if (((LPNMHDR)lParam)->code == TTN_NEEDTEXT)
{
switch(((LPNMHDR) lParam)->idFrom)
{
case TB_SAVE:
((LPTOOLTIPTEXT)lParam)->lpszText = "save changes ( STR+S )";
return TRUE;
case TB_UNDO:
((LPTOOLTIPTEXT)lParam)->lpszText = "undo all unsaved changes ( STR+Z )";
return TRUE;
case TB_GOTO:
((LPTOOLTIPTEXT)lParam)->lpszText = "goto offset ( STR+G )";
return TRUE;
case TB_SELBLOCK:
((LPTOOLTIPTEXT)lParam)->lpszText = "select block ( STR+B )";
return TRUE;
case TB_SELALL:
if ( IsAllSelected() )
((LPTOOLTIPTEXT)lParam)->lpszText = "deselect all ( STR+A )";
else
((LPTOOLTIPTEXT)lParam)->lpszText = "select all ( STR+A )";
return TRUE;
case TB_SEARCH:
((LPTOOLTIPTEXT)lParam)->lpszText = "search ( STR+F )";
return TRUE;
case TB_SEARCHDOWN:
((LPTOOLTIPTEXT)lParam)->lpszText = "search down again ( ALT+D )";
return TRUE;
case TB_SEARCHUP:
((LPTOOLTIPTEXT)lParam)->lpszText = "search up again ( ALT+U )";
return TRUE;
case TB_CUT:
((LPTOOLTIPTEXT)lParam)->lpszText = "cut into clipboard ( STR+X )";
return TRUE;
case TB_COPY:
((LPTOOLTIPTEXT)lParam)->lpszText = "copy to clipboard ( STR+C )";
return TRUE;
case TB_PASTE:
((LPTOOLTIPTEXT)lParam)->lpszText = "paste from clipboard ( STR+V )";
return TRUE;
case TB_WIN2TOP:
((LPTOOLTIPTEXT)lParam)->lpszText =
bHEOnTop ? "set window state to non-top" : "set window state to top ( STR+T )";
return TRUE;
case TB_ABOUT:
((LPTOOLTIPTEXT)lParam)->lpszText = "about ( F12 )";
return TRUE;
case TB_CLOSE:
((LPTOOLTIPTEXT)lParam)->lpszText = "close this window ( ESC )";
return TRUE;
}
}
return FALSE; // ERR
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -