⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hexchfrm.pas

📁 MiniHex 1.1 源程序说明 “MiniHex11SrcSource”目录中的所有文件是MiniHex 1.1的主程序; “MiniHex11SrcControls”目录中的是该软件
💻 PAS
📖 第 1 页 / 共 5 页
字号:
      FBlock.StartOffset := FMsDownOffset;
      FBlock.EndOffset := Offset;
      if FBlock.StartOffset > FBlock.EndOffset then
        SwapInt(FBlock.StartOffset, FBlock.EndOffset);

      MoveCurTo(DLen);
    end;

    GetCursorPos(MsPos);
    MsPos := ViewBackPanel.ScreenToClient(MsPos);
    Sleep(30);
  end;

  while MsPos.y > ViewBackPanel.Height do
  begin
    if FTopRow + FVisRow < FRowCount then
    begin
      Inc(FTopRow);
      DLen := GetDLen(FTopRow + FVisRow - 1, FCurCol, True);
      Offset := GetOffsetByMoveTo(DLen);

      FBlock.StartOffset := FMsDownOffset;
      FBlock.EndOffset := Offset;
      if FBlock.StartOffset > FBlock.EndOffset then
        SwapInt(FBlock.StartOffset, FBlock.EndOffset);

      MoveCurTo(DLen);
    end;

    GetCursorPos(MsPos);
    MsPos := ViewBackPanel.ScreenToClient(MsPos);
    Sleep(30);
  end;
end;

procedure THexChForm.DrawAddrRow(OffRow, AbsRow: Integer);
var
  S: string;
  X, Y: Integer;
begin
  X := GetAddrAreaLeft;
  Y := OffRow * GetCharH;
  S := IntToHex(AbsRow * 16, 8) + ':';
  DrawText(X, Y, S, Options.AddrColor);
end;

procedure THexChForm.DrawHexRow(OffRow, AbsRow: Integer);
var
  S, S1: string;
  X, Y: Integer;
  i, Offset: Integer;
  //DrawBlock: Boolean;
  CharAttr: TCharAttr;
begin
  X := GetHexAreaLeft;
  Y := OffRow * GetCharH;
  S := GetHexAreaStr(AbsRow);

  {
  if not FBlock.Active then DrawBlock := False
  else
  begin
    if (GetOffset(AbsRow, 0) <= FBlock.EndOffset) and
       (GetOffset(AbsRow, 15) >= FBlock.StartOffset) then
         DrawBlock := True
    else
         DrawBlock := False;
  end;
  }
  //if DrawBlock then
  //begin
    for i := 0 to 15 do
    begin
      Offset := GetOffset(AbsRow, i);
      CharAttr := GetCharAttrByRowCol(AbsRow, i, True);
      if (Offset <> FBlock.EndOffset) and (i <> 15) then
      begin
        S1 := Copy(S, i*3+1, 3);
        DrawText(X+i*GetCharW*3, Y, S1, CharAttr);
      end else
      begin
        S1 := Copy(S, i*3+1, 2);
        DrawText(X+i*GetCharW*3, Y, S1, CharAttr);
        S1 := Copy(S, i*3+3, 1);
        DrawText(X+i*GetCharW*3+GetCharW*2, Y, S1, Options.HexColor);
      end;
    end;
  //end
  //else
  // DrawText(X, Y, S, Options.HexColor);
end;

procedure THexChForm.DrawChrRow(OffRow, AbsRow: Integer);
var
  S: string;
  S1: array[1..3] of string;
  i, j, Offset: Integer;
  DrawBlock, InBlock: Boolean;
  CharAttr: TCharAttr;
begin
  S := GetChrAreaStr(AbsRow);

  if not FBlock.Active then DrawBlock := False
  else
  begin
    if (GetOffset(AbsRow, 0) <= FBlock.EndOffset) and
       (GetOffset(AbsRow, 15) >= FBlock.StartOffset) then
         DrawBlock := True
    else
         DrawBlock := False;
  end;

  if DrawBlock then
  begin
    j := 1;
    S1[1] := '';    S1[2] := '';    S1[3] := '';
    for i := 0 to 15 do
    begin
      Offset := GetOffset(AbsRow, i);
      InBlock := (Offset <= FBlock.EndOffset) and (Offset >= FBlock.StartOffset);
      if InBlock then j := 2;
      if Offset > FBlock.EndOffset then j := 3;
      S1[j] := S1[j] + S[i + 1];
    end;
    j := 0;
    for i := 1 to 3 do
    begin
      if i = 2 then CharAttr := Options.BlockColor
      else CharAttr := Options.ChrColor;
      DrawStrForChrRow(S1[i], OffRow, j, CharAttr);
      j := j + Length(S1[i]);
    end;
  end
  else
    DrawStrForChrRow(S, OffRow, 0, Options.ChrColor);
end;

procedure THexChForm.DrawStrForChrRow(S: string; OffRow, Col: Integer; CharAttr: TCharAttr);
var
  i, X, Y: Integer;
  S1: string;
begin
  if S = '' then Exit;
  X := GetChrAreaLeft + GetCharW * Col;
  Y := OffRow * GetCharH;
  if not Options.ShowDot then
  begin
    DrawText(X, Y, S, CharAttr);
  end else
  begin
    for i := 1 to Length(S) do
    begin
      if (Ord(S[i]) >= 32) and (Ord(S[i]) <=126) then
        S1 := S[i]
      else
        S1 := '.';
      DrawText(X+GetCharW*(i-1), Y, S1, CharAttr)
    end;
  end;
end;

procedure THexChForm.DrawOneRow(OffRow, AbsRow: Integer);
begin
  DrawAddrRow(OffRow, AbsRow);
  DrawHexRow(OffRow, AbsRow);
  DrawChrRow(OffRow, AbsRow);
end;

procedure THexChForm.DrawSpcRow(OffRow: Integer);
var
  X, Y: Integer;
begin
  X := GetAddrAreaLeft;
  Y := OffRow * GetCharH;
  DrawText(X, Y, StringOfChar(' ', 74), Options.HexColor);
end;

procedure THexChForm.DrawItem(OffRow, Col: Integer; HexCharAttr, ChrCharAttr: TCharAttr);
var
  X, Y: Integer;
  RowPointer: PChar;
begin
  X := GetHexAreaLeft + GetCharW * (Col*3);
  Y := OffRow * GetCharH;
  RowPointer := GetRowColPointer(FTopRow + OffRow, Col);
  DrawText(X, Y, IntToHex(Integer(RowPointer^), 2), HexCharAttr);

  DrawStrForChrRow(RowPointer^, OffRow, Col, ChrCharAttr);
end;

procedure THexChForm.DrawCurItem(Show: Boolean = True);
var
  OffRow: Integer;
begin
  OffRow := FCurRow - FTopRow;
  if (OffRow >= 0) and (OffRow < FVisRow) then
  begin
    if Show then
    begin
      DrawItem(OffRow, FCurCol, Options.CurItemColor, Options.CurItemColor);
      DrawCursor(True);
    end else
    begin
      DrawItem(OffRow, FCurCol, GetCharAttrByRowCol(FCurRow, FCurCol, True), GetCharAttrByRowCol(FCurRow, FCurCol, True));
    end;
  end;
end;

procedure THexChForm.DrawCursor(Show: Boolean = True);
var
  P: PChar;
  S: string;
  CharAttr: TCharAttr;
  X, Y: Integer;
  OffRow: Integer;
begin
  OffRow := FCurRow - FTopRow;
  X := GetHexAreaLeft + GetCharW * (FCurCol*3);
  Y := OffRow * GetCharH;
  P := GetRowColPointer(FCurRow, FCurCol);
  CharAttr := GetCharAttrByRowCol(FCurRow, FCurCol, FCurInHex);
  S := IntToHex(Integer(P^), 2);
  if FCurInHigh then S := S[1]
  else begin
    S := S[2];
    X := X + GetCharW;
  end;

  if Show then
  begin
    if FCurInHex then
      DrawText(X, Y, S, Options.CurItemColor)
    else
      DrawStrForChrRow(P^, OffRow, FCurCol, Options.CurItemColor);
  end else
  begin
    if FCurInHex then
      DrawText(X, Y, S, CharAttr)
    else
      DrawStrForChrRow(P^, OffRow, FCurCol, CharAttr);
  end;
end;

procedure THexChForm.DrawAllRow();
var
  AbsRow: Integer;
  i: Integer;
begin
  for i := 0 to FVisRow do  //本来是FVisRow-1, 但底下要多画一行
  begin
    AbsRow := FTopRow + i;
    if AbsRow < FRowCount then
      DrawOneRow(i, AbsRow)
    else
      DrawSpcRow(i);
  end;
  DrawCurItem;
end;

procedure THexChForm.ShowStatusInfo;
begin
  StatusBar.Panels.BeginUpdate;
  ShowLength;
  ShowOffset;
  ShowBlockInfo;
  ShowCurValue;
  ShowModifyFlag;
  StatusBar.Panels.EndUpdate;
end;

procedure THexChForm.ShowLength;
var
  S: string;
  Value: Integer;
begin
  Value := FBufSize;;
  S := '长度: ';
  if Options.StatusLengthRadix = raDec then
    S := S + Format('%10dD', [Value])
  else
    S := S + '  ' + IntToHex(Value, 8) + 'H';
  StatusBar.Panels[0].Text := S;
end;

procedure THexChForm.ShowOffset;
var
  S: string;
  Value: Integer;
begin
  Value := GetOffset;
  S := '偏移: ';
  if Options.StatusOffsetRadix = raDec then
    S := S + Format('%10dD', [Value])
  else
    S := S + '  ' + IntToHex(Value, 8) + 'H';
  StatusBar.Panels[1].Text := S;
end;

procedure THexChForm.ShowBlockInfo;
var
  S: string;
begin
  S := '块信息: ';
  if FBlock.Active then
  begin
    if Options.StatusBlockInfoRadix = raDec then
      S := S + Format('%10dD', [FBlock.StartOffset]) +
        ' - '+ Format('%10dD', [FBlock.EndOffset])
    else
      S := S + '  ' + IntToHex(FBlock.StartOffset, 8) + 'H' +
              ' - ' + IntToHex(FBlock.EndOffset, 8) + 'H';
  end else
  begin
    if FBlock.StartOffset > FBlock.EndOffset then
      S := S + '(未定义)'
    else
      S := S + '(已隐藏)';
  end;
  StatusBar.Panels[2].Text := S;
end;

procedure THexChForm.ShowCurValue;
var
  S: string;
  P: Pointer;
  Offset: Integer;
begin
  Offset := GetOffset;
  P := GetRowColPointer(FCurRow, FCurCol);
  S := '';
  case Options.StatusCurValueType of
    vt8s:
      S := IntToStr(PShortInt(P)^);
    vt8u:
      S := IntToStr(PByte(P)^);
    vt16s:
      if Offset + 2 <= FBufSize then
        S := IntToStr(PSmallInt(P)^);
    vt16u:
      if Offset + 2 <= FBufSize then
        S := IntToStr(PWord(P)^);
    vt32s:
      if Offset + 4 <= FBufSize then
        S := IntToStr(PLongInt(P)^);
    vt32u:
      if Offset + 4 <= FBufSize then
        S := IntToStr(PLongWord(P)^);
    vtSingle:
      if Offset + 4 <= FBufSize then
        S := Format('%2.8e', [PSingle(P)^]);
    vtDouble:
      if Offset + 8 <= FBufSize then
        S := Format('%2.8e', [PDouble(P)^]);
  end;
  StatusBar.Panels[3].Text := '当前值: ' +  S;
end;

procedure THexChForm.ShowModifyFlag;
var
  S: string;
begin
  if FModified then S := '已修改'
  else S := '未修改';
  StatusBar.Panels[4].Text := S;
end;

procedure THexChForm.DoUpKey(ShiftPressed: Boolean);
begin
  if ShiftPressed then AdjustBlockA(GetOffset, GetOffsetByMove(-32));
  MoveCur(-32);
  if ShiftPressed then DrawAllRow;
end;

procedure THexChForm.DoDownKey(ShiftPressed: Boolean);
begin
  if ShiftPressed then AdjustBlockB(GetOffset, GetOffsetByMove(32));
  MoveCur(32);
  if ShiftPressed then DrawAllRow;
end;

procedure THexChForm.DoLeftKey(ShiftPressed: Boolean);
begin
  if FCurInHex then
  begin
    if ShiftPressed then AdjustBlockA(GetOffset, GetOffsetByMove(-1));
    MoveCur(-1);
  end else
  begin
    if ShiftPressed then AdjustBlockA(GetOffset, GetOffsetByMove(-2));
    MoveCur(-2);
  end;
  if ShiftPressed then DrawAllRow;
end;

procedure THexChForm.DoRightKey(ShiftPressed: Boolean);
begin
  if FCurInHex then
  begin
    if ShiftPressed then AdjustBlockB(GetOffset, GetOffsetByMove(1));
    MoveCur(1);
  end else
  begin
    if ShiftPressed then AdjustBlockB(GetOffset, GetOffsetByMove(2));
    MoveCur(2);
  end;
  if ShiftPressed then DrawAllRow;
end;

procedure THexChForm.DoPageUpKey(ShiftPressed: Boolean);
var
  OffRow: Integer;
  Offset1, Offset2: Integer;
begin
  if FRowCount <= FVisRow then Exit;
  if (FTopRow = 0) and CheckCursorInWindow then Exit;

  Offset1 := GetOffset;

  if CheckCursorInWindow then
  begin
    OffRow := FCurRow - FTopRow;
    FTopRow := FTopRow - (FVisRow - 1);
    if FTopRow < 0 then FTopRow := 0;
    FCurRow := FTopRow + OffRow;
  end
  else if FCurRow > FTopRow then
  begin
    FCurRow := FCurRow - (FVisRow - 1);
    FTopRow := FCurRow - (FVisRow - 1);
    if FTopRow < 0 then FTopRow := 0;
    FCurRow := FTopRow + (FVisRow - 1);
  end
  else if FCurRow < FTopRow then
  begin
    FCurRow := FCurRow - (FVisRow - 1);
    if FCurRow < 0 then FCurRow := 0;
    FTopRow := FCurRow;
  end;

  Offset2 := GetOffset;
  if ShiftPressed then AdjustBlockA(Offset1, Offset2);

  VertScrollBar.Position := FTopRow;
  DrawAllRow;
  ShowStatusInfo;
  FillDataInspValue;
end;

procedure THexChForm.DoPageDownKey(ShiftPressed: Boolean);
var
  OffRow: Integer;
  Offset1, Offset2: Integer;
begin
  if FRowCount <= FVisRow then Exit;
  if (FTopRow+FVisRow-1 = FRowCount-1) and CheckCursorInWindow then Exit;

  Offset1 := GetOffset;

  if CheckCursorInWindow then
  begin
    OffRow := FCurRow - FTopRow;
    FTopRow := FTopRow + (FVisRow - 1);
    if FTopRow + FVisRow - 1 > FRowCount - 1 then
      FTopRow := FRowCount - FVisRow;
    FCurRow := FTopRow + OffRow;
    While GetOffset >= FBufSize do
      Dec(FCurRow);
  end
  else if FCurRow > FTopRow then
  begin
    FCurRow := FCurRow + (FVisRow - 1);
    if FCurRow + FVisRow - 1 > FRowCount - 1 then
      FCurRow := FRowCount - FVisRow;
    FTopRow := FCurRow - (FVisRow - 1);
  end
  else if FCurRow < FTopRow then
  begin
    FCurRow := FCurRow + (FVisRow - 1);
    FTopRow := FCurRow;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -