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

📄 fshed.cpp

📁 HEX编辑器
💻 CPP
字号:
// fshed.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "fshed.h"

#include "MainFrm.h"
#include "ChildFrm.h"
#include "fshedDoc.h"
#include "fshedView.h"
#include "OptionsDlg.h"
#include "colorspage.h"

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

/////////////////////////////////////////////////////////////////////////////
// CFshedApp

BEGIN_MESSAGE_MAP(CFshedApp, CWinApp)
	//{{AFX_MSG_MAP(CFshedApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
	ON_COMMAND(ID_VIEW_OPTIONS, OnViewOptions)
	//}}AFX_MSG_MAP
	// Standard file based document commands
	ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
	ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
	// Standard print setup command
	ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFshedApp construction
#define FSH_INI_SECTION1 _T("Settings")
#define FSH_INI_ENTRY1   _T("Text Editor Name")
#define FSH_INI_ENTRY2   _T("Automatic BPL")
#define FSH_INI_ENTRY3   _T("Bytes per line")
#define FSH_INI_ENTRY4   _T("Offset Length")
#define FSH_INI_ENTRY5   _T("Character Set")
#define FSH_INI_ENTRY6   _T("Font Size")
#define FSH_INI_ENTRY7   _T("Open Read Only")
#define FSH_INI_ENTRY8   _T("Binary Mode")
#define FSH_INI_ENTRY9   _T("Show Unsigned")

#define FSH_INI_SECTION2 _T("Colors")
#define FSH_INI_ENTRY2_1 _T("Text")
#define FSH_INI_ENTRY2_2 _T("Selected Text")
#define FSH_INI_ENTRY2_3 _T("Background")
#define FSH_INI_ENTRY2_4 _T("Selected Background")
#define FSH_INI_ENTRY2_5 _T("Bookmark")
#define FSH_INI_ENTRY2_6 _T("Separator")

CFshedApp::CFshedApp()
{
    m_bAutomaticBPL = BST_CHECKED;
    m_iBytesPerLine = 16;
    m_iOffsetLen    = 6;
    m_iCharacterSet = ANSI_FIXED_FONT;
    m_iFontSize     = 10;
    m_bOpenReadOnly = FALSE;
    m_iBinaryMode   = LITTLEENDIAN_MODE;
    m_bUnsignedView = TRUE;
	m_clrBmk = RGB( 255, 0, 0 );
	m_clrSelBk = RGB( 255, 255, 0 );
	m_clrSelText = RGB( 0, 0, 0 );
	m_clrText = RGB (0,0,0);
	m_clrBk = RGB (255,255,255);
	m_clrSep = RGB (192,192,192);
}

CFshedApp::~CFshedApp()
{
    WriteProfileString(FSH_INI_SECTION1, FSH_INI_ENTRY1, m_TexteditorName);
    WriteProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY2, m_bAutomaticBPL);
    WriteProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY3, m_iBytesPerLine);
    WriteProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY4, m_iOffsetLen);
    WriteProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY5, m_iCharacterSet);
    WriteProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY6, m_iFontSize);
    WriteProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY7, m_bOpenReadOnly);
    WriteProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY8, m_iBinaryMode);
    WriteProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY9, m_bUnsignedView);
    WriteProfileInt(FSH_INI_SECTION2, FSH_INI_ENTRY2_1, m_clrText);
    WriteProfileInt(FSH_INI_SECTION2, FSH_INI_ENTRY2_2, m_clrSelText);
    WriteProfileInt(FSH_INI_SECTION2, FSH_INI_ENTRY2_3, m_clrBk);
    WriteProfileInt(FSH_INI_SECTION2, FSH_INI_ENTRY2_4, m_clrSelBk);
    WriteProfileInt(FSH_INI_SECTION2, FSH_INI_ENTRY2_5, m_clrBmk);
    WriteProfileInt(FSH_INI_SECTION2, FSH_INI_ENTRY2_6, m_clrSep);
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CFshedApp object

CFshedApp theApp;

class CFshedCommandLineInfo : public CCommandLineInfo
{
public:
   CFshedCommandLineInfo() { m_dwStartOffset = m_dwEndOffset = 0; }
   DWORD m_dwStartOffset, m_dwEndOffset;
   void ParseParam(const TCHAR* pszParam, BOOL bFlag, BOOL bLast)
   {
      CCommandLineInfo::ParseParam(pszParam, bFlag, bLast);
      if (bFlag)
      {
         LPTSTR pEnd;
         switch (pszParam[0])
         {
            case 's':
            case 'S':
                m_dwStartOffset = strtoul(pszParam + 1, &pEnd, 0);
            break;
            case 'e':
            case 'E':
                m_dwEndOffset = strtoul(pszParam + 1, &pEnd, 0);
            break;
            case 'l':
            case 'L':
                m_dwEndOffset = m_dwStartOffset + strtoul(pszParam + 1, &pEnd, 0) - 1;
                if (m_dwEndOffset < m_dwStartOffset)
                   m_dwEndOffset = m_dwStartOffset;
            break;
         }
      }
   }
};

/////////////////////////////////////////////////////////////////////////////
// CFshedApp initialization

BOOL CFshedApp::InitInstance()
{
	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	// Change the registry key under which our settings are stored.
	// TODO: You should modify this string to be something appropriate
	// such as the name of your company or organization.
	SetRegistryKey(IDS_COMP_NAME);
    CString strPath;
    strPath = (LPCTSTR)GetProfileString(FSH_INI_SECTION1, FSH_INI_ENTRY1);
    m_TexteditorName = (LPTSTR)(LPCTSTR)strPath;
    m_bAutomaticBPL = GetProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY2, m_bAutomaticBPL);
    m_iBytesPerLine = GetProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY3, m_iBytesPerLine);
    m_iOffsetLen = GetProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY4, m_iOffsetLen);
    m_iCharacterSet = GetProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY5, m_iCharacterSet);
    m_iFontSize = GetProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY6, m_iFontSize);
    m_bOpenReadOnly = GetProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY7, m_bOpenReadOnly);
    m_iBinaryMode = GetProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY8, m_iBinaryMode);
    m_bUnsignedView = GetProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY9, m_bUnsignedView);
    m_clrText = GetProfileInt(FSH_INI_SECTION2, FSH_INI_ENTRY2_1, m_clrText);
    m_clrSelText = GetProfileInt(FSH_INI_SECTION2, FSH_INI_ENTRY2_2, m_clrSelText);
    m_clrBk = GetProfileInt(FSH_INI_SECTION2, FSH_INI_ENTRY2_3, m_clrBk);
    m_clrSelBk = GetProfileInt(FSH_INI_SECTION2, FSH_INI_ENTRY2_4, m_clrSelBk);
    m_clrBmk = GetProfileInt(FSH_INI_SECTION2, FSH_INI_ENTRY2_5, m_clrBmk);
    m_clrSep = GetProfileInt(FSH_INI_SECTION2, FSH_INI_ENTRY2_6, m_clrSep);

	LoadStdProfileSettings();  // Load standard INI file options (including MRU)

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views.

	CMultiDocTemplate* pDocTemplate;
	pDocTemplate = new CMultiDocTemplate(
		IDR_FSHEDTYPE,
		RUNTIME_CLASS(CFshedDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CFshedView));
	AddDocTemplate(pDocTemplate);

	// create main MDI Frame window
	CMainFrame* pMainFrame = new CMainFrame;
	if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
		return FALSE;
	m_pMainWnd = pMainFrame;

	// Parse command line for standard shell commands, DDE, file open
	CFshedCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

   if (cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew)
       cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
	// Dispatch commands specified on the command line
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;

   if (CCommandLineInfo::FileOpen)
   {
      POSITION pos = pDocTemplate->GetFirstDocPosition();
      if (pos)
      {
         CFshedDoc *pDoc = (CFshedDoc *)pDocTemplate->GetNextDoc(pos);
         if (pDoc && (cmdInfo.m_dwStartOffset < cmdInfo.m_dwEndOffset))
         {
            pos = pDoc->GetFirstViewPosition();
            if (pos)
            {
               CFshedView *pView = (CFshedView *)pDoc->GetNextView(pos);
               if (pView)
               {
                  pView->SetSel(cmdInfo.m_dwStartOffset, cmdInfo.m_dwEndOffset);
               }
            }
         }
      }
   }

	// The main window has been initialized, so show and update it.
	pMainFrame->ShowWindow(m_nCmdShow);
	pMainFrame->UpdateWindow();

	return TRUE;
}


/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	afx_msg void OnVisit();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
	ON_BN_CLICKED(IDC_VISIT, OnVisit)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

// App command to run the dialog
void CFshedApp::OnAppAbout()
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// CFshedApp message handlers


void CFshedApp::OnViewOptions() 
{
    CPropertySheet optSheet(IDS_TTL_OPTIONS, AfxGetMainWnd());
    CDispPage dispPage;
    CGenPage  genPage;
    CColorsPage clrPage;
    optSheet.AddPage(&genPage);
    optSheet.AddPage(&dispPage);
    optSheet.AddPage(&clrPage);
	genPage.m_strTextEditor = m_TexteditorName;
	genPage.m_nNumBytes = m_iBytesPerLine;
	genPage.m_bAdjustBytes = m_bAutomaticBPL;
	genPage.m_nOffsetLen = m_iOffsetLen;
	genPage.m_bSetRead = m_bOpenReadOnly;
	dispPage.m_nSigned = !m_bUnsignedView;
    dispPage.m_nAnsi = (m_iCharacterSet == OEM_FIXED_FONT) ? 1 : 0;
	dispPage.m_nFontSize = m_iFontSize;
    dispPage.m_nIntel = (m_iBinaryMode == BIGENDIAN_MODE) ? 1 : 0;
    clrPage.m_clrbtnText.currentcolor = m_clrText;
    clrPage.m_clrbtnSep.currentcolor = m_clrSep;
    clrPage.m_clrbtnSelBack.currentcolor = m_clrSelBk;
    clrPage.m_clrbtnSel.currentcolor = m_clrSelText;
    clrPage.m_clrbtnBookmark.currentcolor = m_clrBmk;
    clrPage.m_clrbtnBack.currentcolor = m_clrBk;
    if (optSheet.DoModal() == IDOK)
    {
		m_TexteditorName = (LPTSTR)(LPCTSTR)genPage.m_strTextEditor;
		m_iBytesPerLine = genPage.m_nNumBytes;
		m_bAutomaticBPL = genPage.m_bAdjustBytes;
	    m_iOffsetLen = genPage.m_nOffsetLen;
		m_bUnsignedView = !dispPage.m_nSigned;
		m_bOpenReadOnly = genPage.m_bSetRead;
        m_iCharacterSet = (dispPage.m_nAnsi ? OEM_FIXED_FONT : ANSI_FIXED_FONT);
    	m_iFontSize = dispPage.m_nFontSize;
        m_iBinaryMode = (dispPage.m_nIntel ? BIGENDIAN_MODE : LITTLEENDIAN_MODE);
        m_clrText = clrPage.m_clrbtnText.currentcolor;
        m_clrSep = clrPage.m_clrbtnSep.currentcolor;
        m_clrSelBk = clrPage.m_clrbtnSelBack.currentcolor;
        m_clrSelText = clrPage.m_clrbtnSel.currentcolor;
        m_clrBmk = clrPage.m_clrbtnBookmark.currentcolor;
        m_clrBk = clrPage.m_clrbtnBack.currentcolor;

        POSITION pos = GetFirstDocTemplatePosition();
        CMultiDocTemplate *pDocTemplate = (CMultiDocTemplate *)GetNextDocTemplate(pos);
        if (pDocTemplate)
        {
            pos = pDocTemplate->GetFirstDocPosition();
            while (pos)
            {
               CFshedDoc *pDoc = (CFshedDoc *)pDocTemplate->GetNextDoc(pos);
               pDoc->UpdateAllViews(NULL);
            }
        }
    }
}

void CAboutDlg::OnVisit() 
{
    ShellExecute(m_hWnd, "open", "http://www.searchandreplace.com/fshexedit.htm ", NULL, NULL, SW_SHOWNORMAL );
}

⌨️ 快捷键说明

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