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

📄 thexviewer.cpp

📁 mpq文件的格式就是一种压缩格式
💻 CPP
字号:
/*****************************************************************************/
/* THexViewer.cpp                         Copyright (c) Ladislav Zezula 2003 */
/*---------------------------------------------------------------------------*/
/* Description :                                                             */
/*---------------------------------------------------------------------------*/
/*   Date    Ver   Who  Comment                                              */
/* --------  ----  ---  -------                                              */
/* 18.04.03  1.00  Lad  The first version of THexViewer.cpp                  */
/*****************************************************************************/

#include "stdafx.h"
#include "resource.h"
#include "THexViewer.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//-----------------------------------------------------------------------------
// THexViewer dialog

BEGIN_MESSAGE_MAP(THexViewer, CDialog)
	//{{AFX_MSG_MAP(THexViewer)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

THexViewer::THexViewer(CWnd* pParent /*=NULL*/)	: CDialog(THexViewer::IDD, pParent)
{}

//-----------------------------------------------------------------------------
// Public functions

void THexViewer::SetData(const char * pData, DWORD dwDataSize)
{
    if(dwDataSize > sizeof(m_Data))
        dwDataSize = sizeof(m_Data);

    memcpy(m_Data, pData, dwDataSize);
    m_dwDataSize = dwDataSize;
}

//-----------------------------------------------------------------------------
// Protected functions

BYTE * THexViewer::GetHexViewLine(char * szLine, DWORD dwOffs, BYTE * pData, DWORD & dwDataSize)
{
    char * szBegin = szLine;
    DWORD dwBytes;

    // Print the address
    szLine += sprintf(szLine, "%08lX  ", dwOffs);
    
    // Print the hexa bytes
    for(dwBytes = 0; dwBytes < 0x10 && dwBytes < dwDataSize; dwBytes++)
        szLine += sprintf(szLine, "%02lX ", pData[dwBytes]);

    // Fill with spaces
    while((szLine - szBegin) < 0x3B)
        *szLine ++ = ' ';

    for(dwBytes = 0; dwBytes < 0x10 && dwBytes < dwDataSize; dwBytes++)
    {
        BYTE bByte = pData[dwBytes];
        if(bByte < 0x20)
            bByte = '.';

        *szLine++ = (char)bByte;
    }

    // Fill the rest with spaces
    while((szLine - szBegin) < 0x4B)
        *szLine ++ = ' ';
    *szLine = 0;

    dwDataSize -= dwBytes;
    return pData + dwBytes;
}

BOOL THexViewer::OnInitDialog() 
{
    LOGFONT logFont;

    CDialog::OnInitDialog();

    // Fill the LOGFONT structure
    ZeroMemory(&logFont, sizeof(LOGFONT));
    logFont.lfHeight         = -12;
    logFont.lfWidth          = 0;
    logFont.lfEscapement     = 0;
    logFont.lfOrientation    = 0;
    logFont.lfWeight         = FW_NORMAL;
    logFont.lfItalic         = FALSE;
    logFont.lfUnderline      = FALSE;
    logFont.lfStrikeOut      = FALSE;
    logFont.lfCharSet        = DEFAULT_CHARSET;
    logFont.lfOutPrecision   = OUT_DEFAULT_PRECIS;
    logFont.lfClipPrecision  = CLIP_DEFAULT_PRECIS;
    logFont.lfQuality        = DEFAULT_QUALITY;
    logFont.lfPitchAndFamily = DEFAULT_PITCH;
    _tcscpy(logFont.lfFaceName, _T("Courier")); 
    m_Font.CreateFontIndirect(&logFont);

    m_Pen.CreatePen(PS_SOLID, 1, RGB(255, 255, 255));
    return TRUE;
}

void THexViewer::OnPaint() 
{
	CPaintDC dc(this);
    CFont * pOldFont = dc.SelectObject(&m_Font);
    CPen  * pOldPen = dc.SelectObject(&m_Pen);
    DWORD  dwDataSize = m_dwDataSize;
    DWORD dwOffs = 0;
    BYTE * pData = m_Data;
    char szLine[96];
    RECT rect;
    int x = 2;
    int y = 2;

    // Draw the whole dialog background
    GetClientRect(&rect);
    dc.Rectangle(&rect);

    while(dwDataSize > 0 && y <= rect.bottom)
    {
        memset(szLine, 0, sizeof(szLine));
        pData = GetHexViewLine(szLine, dwOffs, pData, dwDataSize);
        dc.TextOut(x, y, szLine, 75);

        dwOffs += 16;
        y += 13;
    }

    dc.SelectObject(pOldPen);
    dc.SelectObject(pOldFont);
}

⌨️ 快捷键说明

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