Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
bytes per line in hex view
Browse files Browse the repository at this point in the history
  • Loading branch information
zodiacon committed Apr 25, 2022
1 parent 8cb016d commit 52c5787
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions TotalPE/MainFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ void CMainFrame::InitMenu() {
}
AddMenu(GetMenu());
UIAddMenu(GetMenu());
UIAddMenu(IDR_CONTEXT);
}

void CMainFrame::UpdateUI() {
Expand Down
23 changes: 22 additions & 1 deletion TotalPE/ReadOnlyHexView.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "pch.h"
#include "ReadOnlyHexView.h"
#include "ToolbarHelper.h"
#include <ToolbarHelper.h>

void CReadOnlyHexView::SetData(std::vector<uint8_t> const& data) {
m_data.Clear();
Expand Down Expand Up @@ -29,13 +29,16 @@ LRESULT CReadOnlyHexView::OnCreate(UINT, WPARAM, LPARAM, BOOL&) {
{ ID_DATASIZE_8BYTES, IDI_NUM8, BTNS_CHECKGROUP },
{ 0 },
{ ID_FILE_SAVE, IDI_SAVE, BTNS_BUTTON, L"Export" },
{ 0 },
{ ID_BYTESPERLINE, 0, BTNS_DROPDOWN | BTNS_WHOLEDROPDOWN | BTNS_SHOWTEXT, L"Bytes Per Line" },
};
CreateSimpleReBar(ATL_SIMPLE_REBAR_NOBORDER_STYLE);
CToolBarCtrl tb = ToolbarHelper::CreateAndInitToolBar(m_hWnd, buttons, _countof(buttons), 16);

AddSimpleReBarBand(tb);
Frame()->AddToolBar(tb);
Frame()->GetUI().UISetCheck(ID_DATASIZE_1BYTE, true);
Frame()->GetUI().UISetRadioMenuItem(ID_BYTESPERLINE_32, ID_BYTESPERLINE_8, ID_BYTESPERLINE_128);

m_hWndClient = m_Hex.Create(m_hWnd, rcDefault, nullptr,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_VSCROLL | WS_HSCROLL, WS_EX_CLIENTEDGE);
Expand All @@ -55,6 +58,15 @@ LRESULT CReadOnlyHexView::OnChangeDataSize(WORD, WORD id, HWND, BOOL&) {
return 0;
}

LRESULT CReadOnlyHexView::OnChangeBytesPerLine(WORD, WORD id, HWND, BOOL&) {
auto index = id - ID_BYTESPERLINE_8;
int bytes[] = { 8, 16, 24, 32, 48, 64, 96, 128 };
m_Hex.SetBytesPerLine(bytes[index]);
Frame()->GetUI().UISetRadioMenuItem(id, ID_BYTESPERLINE_8, ID_BYTESPERLINE_128);

return 0;
}

LRESULT CReadOnlyHexView::OnSave(WORD, WORD, HWND, BOOL&) {
CSimpleFileDialog dlg(FALSE, nullptr, nullptr, OFN_EXPLORER | OFN_ENABLESIZING | OFN_OVERWRITEPROMPT,
L"All Files\0*.*\0", m_hWnd);
Expand All @@ -79,3 +91,12 @@ LRESULT CReadOnlyHexView::OnSetFocus(UINT, WPARAM, LPARAM, BOOL&) {
return 0;
}

LRESULT CReadOnlyHexView::OnDropDown(int, LPNMHDR hdr, BOOL&) {
CMenu menu;
menu.LoadMenu(IDR_CONTEXT);
auto pt = ToolbarHelper::GetDropdownMenuPoint(hdr->hwndFrom, ID_BYTESPERLINE);
Frame()->TrackPopupMenu(menu.GetSubMenu(0).GetSubMenu(1), TPM_VERTICAL, pt.x, pt.y);

return 0;
}

4 changes: 4 additions & 0 deletions TotalPE/ReadOnlyHexView.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class CReadOnlyHexView : public CView<CReadOnlyHexView> {
BEGIN_MSG_MAP(CreadOnlyHexView)
MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
MESSAGE_HANDLER(WM_SHOWWINDOW, OnShowWindow)
NOTIFY_CODE_HANDLER(TBN_DROPDOWN, OnDropDown)
COMMAND_RANGE_HANDLER(ID_DATASIZE_1BYTE, ID_DATASIZE_8BYTES, OnChangeDataSize)
COMMAND_RANGE_HANDLER(ID_BYTESPERLINE_8, ID_BYTESPERLINE_128, OnChangeBytesPerLine)
COMMAND_ID_HANDLER(ID_FILE_SAVE, OnSave)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
CHAIN_MSG_MAP(CView<CReadOnlyHexView>)
Expand All @@ -26,8 +28,10 @@ class CReadOnlyHexView : public CView<CReadOnlyHexView> {
LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
LRESULT OnShowWindow(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
LRESULT OnChangeDataSize(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnChangeBytesPerLine(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnSave(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnSetFocus(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
LRESULT OnDropDown(int /*idCtrl*/, LPNMHDR hdr, BOOL& /*bHandled*/);

private:
CHexControl m_Hex;
Expand Down
4 changes: 2 additions & 2 deletions TotalPE/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Used by TotalPE.rc
//
#define IDD_ABOUTBOX 100
#define ID_BYTESPERLINE 101
#define IDR_MAINFRAME 128
#define IDS_TITLE 129
#define IDI_DIR_OPEN 201
Expand Down Expand Up @@ -45,7 +46,6 @@
#define IDI_DELAY_IMPORT 239
#define IDI_CODE 240
#define IDI_SHIELD2 241
#define IDI_ICON1 242
#define IDI_RELOC 242
#define IDC_EXTLINK 1000
#define IDC_LINK 1001
Expand Down Expand Up @@ -95,6 +95,6 @@
#define _APS_NEXT_RESOURCE_VALUE 243
#define _APS_NEXT_COMMAND_VALUE 32813
#define _APS_NEXT_CONTROL_VALUE 1002
#define _APS_NEXT_SYMED_VALUE 101
#define _APS_NEXT_SYMED_VALUE 102
#endif
#endif

0 comments on commit 52c5787

Please sign in to comment.