- Introduction
- Installation
- Creating
- Set The Data
- Virtual Data Mode
- Virtual Bookmarks
- Custom Colors
- Methods
Expand
- BkmAdd
- BkmClearAll
- BkmGetByID
- BkmGetByIndex
- BkmGetCount
- BkmHitTest
- BkmRemoveByID
- BkmSetVirtual
- ClearData
- Create
- CreateDialogCtrl
- Destroy
- ExecuteCmd
- GetCacheSize
- GetCapacity
- GetCaretPos
- GetColors
- GetData
- GetDataSize
- GetDateInfo
- GetEncoding
- GetFont
- GetGroupMode
- GetMenuHandle
- GetPagesCount
- GetPagePos
- GetPageSize
- GetSelection
- GetUnprintableChar
- GetWindowHandle
- GoToOffset
- HasSelection
- HitTest
- IsCmdAvail
- IsCreated
- IsDataSet
- IsMutable
- IsOffsetAsHex
- IsOffsetVisible
- IsVirtual
- ModifyData
- Redraw
- SetCapacity
- SetCaretPos
- SetColors
- SetConfig
- SetData
- SetDateInfo
- SetEncoding
- SetFont
- SetGroupMode
- SetMutable
- SetOffsetMode
- SetPageSize
- SetRedraw
- SetSelection
- SetUnprintableChar
- SetWheelRatio
- Structures
- Enums
- Notification Messages
- Exported Functions
- Positioning and Sizing
- Appearance
- Licensing
HexCtrl is a very featured hex viewer/editor control written in C++ with the help of the MFC library.
It's implemented as a pure abstract interface and therefore can be used in your app even if you don't use MFC directly. It's written with /std:c++20 standard in Visual Studio 2019.
- View and edit data up to 16EB (exabyte)
- Works in two data modes, Memory and Virtual Data Mode
- Fully featured Bookmarks Manager
- Fully featured Search and Replace
- Changeable encoding for the text area
- Many options to Copy/Paste to/from clipboard
- Undo/Redo
- Modify data with Filling and many predefined Operations options
- Ability to visually divide data into pages
- Print whole document/pages range/selection
- Set individual colors for the data chunks with Custom Colors
- Customizable look and appearance
- Assignable keyboard shortcuts via external config file
- Written with /std:c++20 standard conformance
The HexCtrl can be used in two different ways:
- Building from the sources as a part of your project
- Using as a .dll.
The building process is quite simple:
- Copy HexCtrl folder into your project's directory.
- Add all files from the HexCtrl folder into your project, except for
HexCtrl/dep/rapidjson/rapidjson-amalgam.h (header-only lib). - Add
#include "HexCtrl/HexCtrl.h"
where you suppose to use the HexCtrl. - Declare HexCtrl's namespace:
using namespace HEXCTRL;
- Declare
IHexCtrlPtr
member variable:IHexCtrlPtr myHex { CreateHexCtrl() };
- Create control instance.
If you want to build HexCtrl from the sources in non MFC app you will have to:
- Add support for Use MFC in a Shared DLL in your project settings.
- Uncomment the line
//#define HEXCTRL_MANUAL_MFC_INIT
inHexCtrl.h
header file.
To use HexCtrl as the .dll do the following:
- Copy HexCtrl.h and HexCtrlDefs.h files into your project's folder.
- Copy HexCtrl.lib file into your project's folder, so that linker can see it.
- Put HexCtrl.dll file next to your .exe file.
- Add the following line where you suppose to use the control:
#define HEXCTRL_SHARED_DLL //You can alternatively uncomment this line in HexCtrl.h.
#include "HexCtrl.h"`
- Declare
IHexCtrlPtr
member variable:IHexCtrlPtr myHex { CreateHexCtrl() };
- Create control instance.
To build HexCtrl.dll and HexCtrl.lib use the DLL Project/DLL Project.vcxproj Visual Studio project file.
HexCtrl's .dll is built with MFC Static Linking. So even if you are to use it in your own MFC project, even with different MFC version, there should not be any interferences
Building HexCtrl with MFC Shared DLL turned out to be a little tricky. Even with the help of AFX_MANAGE_STATE(AfxGetStaticModuleState())
macro there always were MFC debug assertions, which origins quite hard to comprehend.
IHexCtrlPtr
is, in fact, a pointer to a IHexCtrl
pure abstract base class, wrapped either in std::unique_ptr
or std::shared_ptr
. You can choose whatever is best for your needs by define or undefine/comment-out the HEXCTRL_IHEXCTRLPTR_UNIQUEPTR
macro in HexCtrl.h.
By default HEXCTRL_IHEXCTRLPTR_UNIQUEPTR
is defined, thus IHexCtrlPtr
is an alias for std::unique_ptr<IHexCtrl>
.
This wrapper is used mainly for convenience, so you don't have to bother about object lifetime, it will be destroyed automatically.
That's why there is a call to the factory function CreateHexCtrl()
- to properly initialize a pointer.
If you, for some reason, need a raw interface pointer, you can directly call CreateRawHexCtrl
function, which returns IHexCtrl
interface pointer, but in this case you will need to call Destroy
method manually afterwards, to destroy IHexCtrl
object.
HexCtrl uses its own namespace HEXCTRL
.
So it's up to you, whether to use namespace prefix before declarations:
HEXCTRL::
or to define namespace globally, in the source file's beginning:
using namespace HEXCTRL;
Create
is the first method you call to create HexCtrl instance. It takes HEXCREATE
reference as an argument.
You can choose whether control will behave as a child or independent popup window, by setting enCreateMode
member of this struct to EHexCreateMode::CREATE_CHILD
or EHexCreateMode::CREATE_POPUP
respectively.
HEXCREATE hcs;
hcs.enCreateMode = EHexCreateMode::CREATE_POPUP;
hcs.hwndParent = m_hWnd;
m_myHex->Create(hcs);
For all available options see HEXCREATE
description.
To use HexCtrl within Dialog you can, of course, create it with the Classic Approach, call Create
method and provide all the necessary information.
But there is another option you can use:
- Put Custom Control from the Toolbox in Visual Studio dialog designer into your dialog template and make it desirable size.
- Go to the Properties of that control and in the Class field, within the Misc section, type: HexCtrl.
Give the control appropriate ID of your choice (IDC_MY_HEX in this example).
Also, here you can set the control's Dynamic Layout properties, so that control behaves appropriately when dialog is being resized.
- Declare
IHexCtrlPtr
member variable within your dialog class:
IHexCtrlPtr m_myHex { CreateHexCtrl() };
- Call
CreateDialogCtrl
method from your dialog'sOnInitDialog
method.
BOOL CMyDialog::OnInitDialog()
{
CDialogEx::OnInitDialog();
m_myHex->CreateDialogCtrl(IDC_MY_HEX, m_hWnd);
}
To set a data for the HexCtrl the SetData
method is used.
The code below shows how to construct HexCtrl
object and display first 0x1FF
bytes of the current app's memory:
IHexCtrlPtr myHex { CreateHexCtrl() };
HEXCREATE hcs;
hcs.hwndParent = m_hWnd;
hcs.rect = {0, 0, 600, 400}; //Window rect.
myHex->Create(hcs);
HEXDATA hds;
hds.spnData = { reinterpret_cast<std::byte*>(GetModuleHandle(nullptr)), 0x1FF };
myHex->SetData(hds);
The next example shows how to display std::string
's text as hex data:
std::string str = "My string";
HEXDATA hds;
hds.spnData = { reinterpret_cast<std::byte*>(str.data()), str.size() };
myHex->SetData(hds);
Besides the standard default mode, when HexCtrl just holds a pointer to some bytes in memory, it also has additional Virtual mode.
This mode can be quite useful, for instance in cases where you need to display a very large amount of data that can't fit in memory all at once.
If HEXDATA::pHexVirtData
pointer is set then all the data routine will be done through it. This pointer is of IHexVirtData
class type, which is a pure abstract base class.
You have to derive your own class from it and implement all its public methods.
class IHexVirtData
{
public:
virtual void OnHexGetData(HEXDATAINFO&) = 0; //Data to get.
virtual void OnHexSetData(const HEXDATAINFO&) = 0; //Data to set, if mutable.
};
Then provide a pointer to the created object of this derived class prior to call to SetData
method, through the HEXDATA::pHexVirtData
.
HexCtrl has innate functional to work with any amount of bookmarked regions. These regions can be assigned with individual background and text colors and description.
But if you have some big and complicated data logic and want to handle all these regions yourself, you can do it with the help of Virtual Bookmarks. To enable it call the BkmSetVirtual
method.
The main method of the IHexVirtBkm
interface is HitTest
. It takes data offset and returns pointer to HEXBKM
if there is a bookmark, or nullptr
otherwise.
class IHexVirtBkm
{
public:
virtual ULONGLONG OnHexBkmAdd(const HEXBKM& stBookmark) = 0; //Add new bookmark, return new bookmark's ID.
virtual void OnHexBkmClearAll() = 0; //Clear all bookmarks.
[[nodiscard]] virtual ULONGLONG OnHexBkmGetCount() = 0; //Get total bookmarks count.
[[nodiscard]] virtual auto OnHexBkmGetByID(ULONGLONG ullID)->HEXBKM* = 0; //Bookmark by ID.
[[nodiscard]] virtual auto OnHexBkmGetByIndex(ULONGLONG ullIndex)->HEXBKM* = 0; //Bookmark by index (in inner list).
[[nodiscard]] virtual auto OnHexBkmHitTest(ULONGLONG ullOffset)->HEXBKM* = 0; //Does given offset have a bookmark?
virtual void OnHexBkmRemoveByID(ULONGLONG ullID) = 0; //Remove bookmark by given ID (returned by Add()).
};
This interface is used to set custom bk/text colors for the data offset.
In order to use this feature the HEXDATA::pHexVirtColors
member must be set to a valid class inherited from this interface prior to calling SetData
method.
class IHexVirtColors
{
public:
void OnHexGetColor(HEXCOLORINFO&) = 0;
};
The OnHexGetColor
method of this interface takes HEXCOLORINFO
struct as an argument. The pClr
member of this struct must point to a valid HEXCOLOR
struct after method completes, or nullptr
for default colors.
The HexCtrl has plenty of methods that you can use to customize its appearance, and to manage its behavior.
ULONGLONG BkmAdd(const HEXBKM& hbs, bool fRedraw = false)
Adds new bookmark to the control. Uses HEXBKM
as an argument. Returns created bookmark's id.
HEXBKM hbs;
hbs.vecSpan.emplace_back(HEXSPAN { 0x1, 10 });
hbs.clrBk = RGB(0, 255, 0);
hbs.clrText = RGB(255, 255, 255);
hbs.wstrDesc = L"My first bookmark, with green bk and white text.";
myHex.BkmAdd(hbs);
void BkmClearAll();
Clears all bookmarks.
BkmGetByID(ULONGLONG ullID)->HEXBKM*;
Get bookmark by ID.
auto BkmGetByIndex(ULONGLONG ullIndex)->HEXBKM*;
Get bookmark by Index.
ULONGLONG BkmGetCount()const;
Get bookmarks' count.
auto BkmHitTest(ULONGLONG ullOffset)->HEXBKM*;
Test given offset and retrieves pointer to HEXBKM
if it contains a bookmark.
void BkmRemoveByID(ULONGLONG ullID);
Removes bookmark by the given ID.
void BkmSetVirtual(bool fEnable, IHexVirtBkm* pVirtual = nullptr);
Enables or disables bookmarks virtual mode.
void ClearData();
Clears data from the HexCtrl view, not touching data itself.
bool Create(const HEXCREATE& hcs);
Main initialization method.
Takes HEXCREATE
as argument. Returns true
if created successfully, false
otherwise.
bool CreateDialogCtrl(UINT uCtrlID, HWND hwndDlg);
Creates HexCtrl from Custom Control dialog's template. Takes control's id, and dialog's window handle as arguments. See Creating section for more info.
void Destroy();
Destroys the control.
You only invoke this method if you use a raw IHexCtrl
pointer obtained by the call to CreateRawHexCtrl
function. Otherwise don't use it.
Remarks
You usually don't need to call this method unless you use HexCtrl through the raw pointer obtained by CreateRawHexCtrl
factory function.
If you use HexCtrl in standard way, through the IHexCtrlPtr
pointer, obtained by CreateHexCtrl
function, this method will be called automatically.
void ExecuteCmd(EHexCmd enCmd)const;
Executes one of the predefined commands of EHexCmd
enum. All these commands are basically replicating control's inner menu.
auto GetCacheSize()const->DWORD;
Returns current cache size set in HEXDATA
.
DWORD GetCapacity()const;
Returns current capacity.
ULONGLONG GetCaretPos()const;
Retrieves current caret position offset.
auto GetColors()const->HEXCOLORS;
Returns current HEXCOLORS
.
auto GetData(HEXSPAN hss)const->std::byte*;
Returns a pointer to a data offset no matter what mode the control works in.
Note that in the Virtual mode returned data size can not exceed current cache size, and therefore may be less than the size acquired.
In the default mode returned pointer is just an offset from the data pointer set in the SetData
method.
auto GetDataSize()const->ULONGLONG;
Returns currently set data size.
GetDateInfo()const->std::tuple<DWORD, wchar_t>;
Returns date format-ordering specifier, and date separator.
int GetEncoding()const;
Get code page that is currently in use.
void GetFont(LOGFONTW& lf);
Retrieves current font through lf
arg.
auto GetGroupMode()const->EHexDataSize;
Retrieves current data grouping mode.
HMENU GetMenuHandle()const;
Retrieves the HMENU
handle of the control's context menu. You can use this handle to customize menu for your needs.
Control's internal menu uses menu ID
s in range starting from 0x8001
. So if you wish to add your own new menu, assign menu ID
starting from 0x9000
to not interfere.
When user clicks custom menu, control sends WM_NOTIFY
message to its parent window with LPARAM
pointing to HEXMENUINFO
with its hdr.code
member set to HEXCTRL_MSG_MENUCLICK
. wMenuID
field will be holding ID
of the menu clicked.
DWORD GetPageSize()const;
Get current count of pages set by SetPageSize
.
auto GetPagePos()->ULONGLONG const;
Get current page a cursor stays at.
DWORD GetPageSize()const;
Get current page size set by SetPageSize
.
auto GetSelection()const->std::vector<HEXSPAN>;
Returns std::vector
with the offsets and sizes of the current selection.
wchar_t GetUnprintableChar()const;
Returns replacement char for unprintable characters.
HWND GetWindowHandle(EHexWnd enWnd)const
Retrieves window handle for one of the HexCtrl's windows. Takes EHexWnd
enum as an argument.
void GoToOffset(ULONGLONG ullOffset, int iRelPos = 0)
Go to a given offset. The second argument iRelPos
may take-in three different values:
-1
- offset will appear at the top line.-
0
- offset will appear at the middle. -
1
- offset will appear at the bottom line.
bool HasSelection()const;
Returns true
if HexCtrl has any area selected.
auto HitTest(POINT pt, bool fScreen = true)const->std::optional<HEXHITTEST>
Hit testing of given point in a screen fScreen = true
, or client fScreen = false
coordinates. In case of success returns HEXHITTEST
structure.
bool IsCmdAvail(EHexCmd enCmd)const;
Returns true
if given command can be executed at the moment, false
otherwise.
bool IsCreated()const;
Shows whether HexCtrl is created or not yet.
bool IsDataSet()const;
Shows whether a data was set to HexCtrl or not
bool IsMutable()const;
Shows whether HexCtrl is currently in edit mode or not.
bool IsOffsetAsHex()const;
Is "Offset" currently represented (shown) as Hex or as Decimal. It can be changed by double clicking at offset area.
HEXVISION IsOffsetVisible(ULONGLONG ullOffset)const;
Checks for offset visibility and returns HEXVISION
as a result.
bool IsVirtual()const;
Returns true
if HexCtrl currently works in Virtual Data Mode.
void ModifyData(const HEXMODIFY& hms);
Modify data currently set in HexCtrl, see the HEXMODIFY
struct for details.
void Redraw();
Redraws main window.
void SetCapacity(DWORD dwCapacity);
Sets HexCtrl's current capacity.
void SetCaretPos(ULONGLONG ullOffset, bool fHighLow = true, bool fRedraw = true);
Sets the caret to the given offset. The fHighLow
flag shows which part of the hex chunk, low or high, a caret must be set to.
void SetColors(const HEXCOLORS& clr);
Sets all the colors for the control. Takes HEXCOLORS
as the argument.
bool SetConfig(std::wstring_view wstrPath);
Sets the path to a JSON config file with keybindings to use in HexCtrl, or empty path (L""
) for default. This file is using EHexCmd
enum values as keys and strings array as values:
{
"CMD_DLG_SEARCH": [ "ctrl+f", "ctrl+h" ],
"CMD_SEARCH_NEXT": [ "f3" ],
"CMD_SEARCH_PREV": [ "shift+f3" ]
}
For default values see the HexCtrl/res/keybind.json
file from the project sources.
void SetData(const HEXDATA& hds);
Main method to set a data to display in read-only or mutable modes. Takes HEXDATA
as an argument.
void SetDateInfo(DWORD dwFormat, wchar_t wchSepar);
Sets date format-ordering specifier, along with date separator.
void SetEncoding(int iCodePage);
Sets the code page for the HexCtrl's text area. Takes code page identifier as an argument, or -1
for default ASCII-only characters.
Note: Code page identifier must represent Single-byte Character Set. Multi-byte character sets are not currently supported.
void SetFont(const LOGFONTW& lf);
Sets a new font for the HexCtrl. This font has to be monospaced.
void SetGroupMode(EHexDataSize enGroupMode);
Sets current data grouping mode. See EHexDataSize
for more info.
void SetMutable(bool fEnable);
Enables or disables mutable mode. In mutable mode all the data can be modified.
void SetOffsetMode(bool fHex);
Sets offset area being shown as Hex (fHex=true
) or as Decimal (fHex=false
).
void SetPageSize(DWORD dwSize, const wchar_t* wstrName = L"Page");
Sets the size of the page to draw the divider line between. This size should be multiple to the current capacity size to take effect. The second argument sets the name to be displayed in the bottom info area of the HexCtrl ("Page", "Sector", etc...).
To remove the divider just set dwSize
to 0.
void SetRedraw(bool fRedraw);
Should the main HexCtrl window be redrawn or not. E.g. should the WM_PAINT
message be handled or not.
void SetSelection(const std::vector<HEXSPAN>& vecSel, bool fRedraw = true, bool fHighlight = false);
Sets current selection or highlight in the selection, if fHighlight
is true
.
void SetUnprintableChar(wchar_t wch);
Sets replacement char for unprintable characters.
void SetWheelRatio(double dbRatio)
Sets the ratio for how much to scroll with mouse-wheel.
Below are listed all HexCtrl's structures.
Structure for bookmarks, used in BkmAdd
method.
struct HEXBKM
{
std::vector<HEXSPAN> vecSpan { }; //Vector of offsets and sizes.
std::wstring wstrDesc { }; //Bookmark description.
ULONGLONG ullID { }; //Bookmark ID, assigned internally by framework.
ULONGLONG ullData { }; //User defined custom data.
COLORREF clrBk { RGB(240, 240, 0) }; //Bk color.
COLORREF clrText { RGB(0, 0, 0) }; //Text color.
};
using PHEXBKM = HEXBKM*;
The member vecSpan
is of a std::vector<HEXSPAN>
type because a bookmark may have few non adjacent areas. For instance, when selection is made as a block, with Alt pressed.
Bookmark information struct.
struct HEXBKMINFO
{
NMHDR hdr { }; //Standard Windows header.
PHEXBKM pBkm { }; //Bookmark pointer.
};
HexCtrl custom colors.
struct HEXCOLOR
{
COLORREF clrBk { }; //Bk color.
COLORREF clrText { }; //Text color.
};
using PHEXCOLOR = HEXCOLOR*;
Struct for hex chunks' color information.
struct HEXCOLORINFO
{
NMHDR hdr { }; //Standard Windows header.
ULONGLONG ullOffset { }; //Offset for the color.
PHEXCOLOR pClr { }; //Pointer to the color struct.
};
This structure describes all control's colors. All these colors have their default values.
struct HEXCOLORS
{
COLORREF clrTextHex { GetSysColor(COLOR_WINDOWTEXT) }; //Hex chunks text color.
COLORREF clrTextASCII { GetSysColor(COLOR_WINDOWTEXT) }; //ASCII text color.
COLORREF clrTextSelect { GetSysColor(COLOR_HIGHLIGHTTEXT) }; //Selected text color.
COLORREF clrTextDataInterp { RGB(250, 250, 250) }; //Data Interpreter text color.
COLORREF clrTextCaption { RGB(0, 0, 180) }; //Caption text color
COLORREF clrTextInfoRect { GetSysColor(COLOR_WINDOWTEXT) }; //Text color of the bottom "Info" rect.
COLORREF clrTextCaret { RGB(255, 255, 255) }; //Caret text color.
COLORREF clrBk { GetSysColor(COLOR_WINDOW) }; //Background color.
COLORREF clrBkSelected { GetSysColor(COLOR_HIGHLIGHT) }; //Background color of the selected Hex/ASCII.
COLORREF clrBkDataInterp { RGB(147, 58, 22) }; //Data Interpreter Bk color.
COLORREF clrBkInfoRect { GetSysColor(COLOR_BTNFACE) }; //Background color of the bottom "Info" rect.
COLORREF clrBkCaret { RGB(0, 0, 255) }; //Caret background color.
COLORREF clrBkCaretSelect { RGB(0, 0, 200) }; //Caret background color in selection.
};
The main initialization struct used for control creation.
struct HEXCREATE
{
EHexCreateMode enCreateMode { EHexCreateMode::CREATE_CHILD }; //Creation mode of the HexCtrl window.
HEXCOLORS stColor { }; //All the control's colors.
HWND hwndParent { }; //Parent window pointer.
const LOGFONTW* pLogFont { }; //Font to be used instead of default, it has to be monospaced.
RECT rect { }; //Initial rect. If null, the window is screen centered.
UINT uID { }; //Control ID.
DWORD dwStyle { }; //Window styles, 0 for default.
DWORD dwExStyle { }; //Extended window styles, 0 for default.
double dbWheelRatio { 1.0 }; //Ratio for how much to scroll with mouse-wheel.
};
Main struct to set a data to display in the control.
struct HEXDATA
{
std::span<std::byte> spnData { }; //Data to display.
IHexVirtData* pHexVirtData { }; //Pointer for Virtual mode.
IHexVirtColors* pHexVirtColors { }; //Pointer for Custom Colors class.
DWORD dwCacheSize { 0x800000 }; //In Virtual mode max cached size of data to fetch.
bool fMutable { false }; //Is data mutable (editable) or read-only.
bool fHighLatency { false }; //Do not redraw window until scrolling completes.
};
Struct for a data information used in IHexVirtData
.
struct HEXDATAINFO
{
NMHDR hdr { }; //Standard Windows header.
HEXSPAN stHexSpan { }; //Offset and size of the data bytes.
std::span<std::byte> spnData { }; //Data span.
};
Structure is used in HitTest
method.
struct HEXHITTEST
{
ULONGLONG ullOffset { }; //Offset.
bool fIsText { false }; //Is cursor at Text or Hex area.
bool fIsHigh { false }; //Is it High or Low part of the byte.
};
This struct is used to represent data modification parameters.
When enModifyMode
is set to EHexModifyMode::MODIFY_ONCE
, bytes from pData
just replace corresponding data bytes as is.
If enModifyMode
is equal to EHexModifyMode::MODIFY_REPEAT
then block by block replacement takes place few times.
For example, if:
SUM(vecSpan.ullSize) == 9
spnData.size() == 3
enModifyMode
is set toEHexModifyMode::MODIFY_REPEAT
- bytes in memory at
vecSpan.ullOffset
are010203040506070809
- bytes pointed to by
spnData.data()
are030405
then, after modification, bytes at vecSpan.ullOffset
will become 030405030405030405
.
If enModifyMode
is equal to EHexModifyMode::MODIFY_OPERATION
then enOperMode
comes into play, showing what kind of operation must be performed on data.
struct HEXMODIFY
{
EHexModifyMode enModifyMode { EHexModifyMode::MODIFY_ONCE }; //Modify mode.
EHexOperMode enOperMode { }; //Operation mode, used only in MODIFY_OPERATION mode.
EHexDataSize enOperSize { }; //Operation data size.
std::span<std::byte> spnData { }; //Data span.
std::vector<HEXSPAN> vecSpan { }; //Vector of data offsets and sizes.
bool fBigEndian { false }; //Treat the data as a big endian, used only in MODIFY_OPERATION mode.
};
Menu information struct.
struct HEXMENUINFO
{
NMHDR hdr { }; //Standard Windows header.
POINT pt { }; //Mouse position when clicked.
WORD wMenuID { }; //Menu identifier.
};
This struct is used mostly in selection and bookmarking routines. It holds offset and size of the data region.
struct HEXSPAN
{
ULONGLONG ullOffset { };
ULONGLONG ullSize { };
};
This struct is returned from IsOffsetVisible
method. Two members i8Vert
and i8Horz
represent vertical and horizontal visibility respectively. These members can be in three different states:
-1
— offset is higher, or at the left, of the visible area.-
1
— offset is lower, or at the right. -
0
— offset is visible.
struct HEXVISION
{
std::int8_t i8Vert { }; //Vertical offset.
std::int8_t i8Horz { }; //Horizontal offset.
operator bool() { return i8Vert == 0 && i8Horz == 0; }; //For test simplicity: if(IsOffsetVisible()).
};
Enum of commands that can be executed within HexCtrl.
enum class EHexCmd : std::uint8_t
{
CMD_DLG_SEARCH = 0x01, CMD_SEARCH_NEXT, CMD_SEARCH_PREV,
CMD_NAV_DLG_GOTO, CMD_NAV_REPFWD, CMD_NAV_REPBKW, CMD_NAV_DATABEG, CMD_NAV_DATAEND,
CMD_NAV_PAGEBEG, CMD_NAV_PAGEEND, CMD_NAV_LINEBEG, CMD_NAV_LINEEND,
CMD_GROUPBY_BYTE, CMD_GROUPBY_WORD, CMD_GROUPBY_DWORD, CMD_GROUPBY_QWORD,
CMD_BKM_ADD, CMD_BKM_REMOVE, CMD_BKM_NEXT, CMD_BKM_PREV, CMD_BKM_CLEARALL, CMD_BKM_DLG_MANAGER,
CMD_CLPBRD_COPY_HEX, CMD_CLPBRD_COPY_HEXLE, CMD_CLPBRD_COPY_HEXFMT, CMD_CLPBRD_COPY_TEXTUTF16,
CMD_CLPBRD_COPY_BASE64, CMD_CLPBRD_COPY_CARR, CMD_CLPBRD_COPY_GREPHEX, CMD_CLPBRD_COPY_PRNTSCRN,
CMD_CLPBRD_COPY_OFFSET, CMD_CLPBRD_PASTE_HEX, CMD_CLPBRD_PASTE_TEXTUTF16, CMD_CLPBRD_PASTE_TEXTCP,
CMD_MODIFY_DLG_OPERS, CMD_MODIFY_FILLZEROS, CMD_MODIFY_DLG_FILLDATA, CMD_MODIFY_UNDO, CMD_MODIFY_REDO,
CMD_SEL_MARKSTART, CMD_SEL_MARKEND, CMD_SEL_ALL, CMD_SEL_ADDLEFT, CMD_SEL_ADDRIGHT, CMD_SEL_ADDUP, CMD_SEL_ADDDOWN,
CMD_DLG_DATAINTERP, CMD_DLG_ENCODING, CMD_APPEAR_FONTCHOOSE, CMD_APPEAR_FONTINC, CMD_APPEAR_FONTDEC,
CMD_APPEAR_CAPACINC, CMD_APPEAR_CAPACDEC, CMD_DLG_PRINT, CMD_DLG_ABOUT,
CMD_CARET_LEFT, CMD_CARET_RIGHT, CMD_CARET_UP, CMD_CARET_DOWN,
CMD_SCROLL_PAGEUP, CMD_SCROLL_PAGEDOWN
};
Enum represents the modes that HexCtrl's window can be created in.
enum class EHexCreateMode : std::uint8_t
{
CREATE_CHILD, CREATE_POPUP, CREATE_CUSTOMCTRL
};
Data size to operate on, used in EHexModifyMode::MODIFY_OPERATION
mode. Also used to set data grouping mode, in SetGroupMode
method.
enum class EHexDataSize : std::uint8_t
{
SIZE_BYTE = 0x01, SIZE_WORD = 0x02, SIZE_DWORD = 0x04, SIZE_QWORD = 0x08
};
Enum of the data modification modes, used in HEXMODIFY
.
enum class EHexModifyMode : std::uint8_t
{
MODIFY_ONCE, MODIFY_REPEAT, MODIFY_OPERATION, MODIFY_RAND_MT19937, MODIFY_RAND_FAST
};
Enum of the data operation modes, used in HEXMODIFY
when HEXMODIFY::enModifyMode
is set to MODIFY_OPERATION
.
enum class EHexOperMode : std::uint8_t
{
OPER_ASSIGN, OPER_OR, OPER_XOR, OPER_AND, OPER_NOT, OPER_SHL, OPER_SHR, OPER_ROTL,
OPER_ROTR, OPER_SWAP, OPER_ADD, OPER_SUBTRACT, OPER_MULTIPLY, OPER_DIVIDE,
OPER_CEILING, OPER_FLOOR
};
Enum of all HexCtrl's internal windows. This enum is used as an arg in GetWindowHandle
method to retrieve window's handle.
enum class EHexWnd : std::uint8_t
{
WND_MAIN, DLG_BKMMANAGER, DLG_DATAINTERP, DLG_FILLDATA,
DLG_OPERS, DLG_SEARCH, DLG_ENCODING, DLG_GOTO
};
During its work HexCtrl sends notification messages to HEXCREATE::hwndParent
window, about its different states, through WM_NOTIFY mechanism.
The LPARAM
of the WM_NOTIFY
message will contain a pointer to the NMHDR standard windows struct. Depending on the notification message LPARAM
can then be casted to a pointer to another struct, see message description for details.
Sent if bookmark is clicked. LPARAM
will contain pointer to a HEXBKMINFO
struct.
Sent when caret position has changed. LPARAM
will contain pointer to a NMHDR
struct.
Sent when context menu is about to be displayed. LPARAM
will contain pointer to a HEXMENUINFO
struct.
Sent to indicate that HexCtrl window is about to be destroyed. LPARAM
will contain pointer to a NMHDR
struct.
Sent when user defined custom menu has been clicked. LPARAM
will contain pointer to a HEXMENUINFO
struct.
Sent when selection has been made. LPARAM
will contain pointer to a NMHDR
struct.
Sent to indicate that the data has changed. LPARAM
will contain pointer to a NMHDR
struct.
HexCtrl has few "C"
interface functions which it exports when built as .dll.
extern "C" HEXCTRLAPI IHexCtrl* __cdecl CreateRawHexCtrl();
Main function that creates raw IHexCtrl
interface pointer. You barely need to use this function in your code.
See the IHexCtrlPtr
section for more info.
extern "C" HEXCTRLAPI HEXCTRLINFO* __cdecl GetHexCtrlInfo();
Returns pointer to HEXCTRLINFO
, which is the HexCtrl's service information structure.
Service structure for HexCtrl's version information.
struct HEXCTRLINFO
{
const wchar_t* pwszVersion { }; //WCHAR version string.
union {
unsigned long long ullVersion { }; //ULONGLONG version number.
struct {
short wMajor;
short wMinor;
short wMaintenance;
short wRevision;
}stVersion;
};
};
To properly resize and position your HexCtrl's window you may have to handle WM_SIZE
message in its parent window, in something like this way:
void CMyWnd::OnSize(UINT nType, int cx, int cy)
{
//...
::SetWindowPos(m_myHex->GetWindowHandle(EHexWnd::WND_MAIN), this->m_hWnd, 0, 0, cx, cy, SWP_NOACTIVATE | SWP_NOZORDER);
}
To change control's font size — Ctrl+MouseWheel
To change control's capacity — Ctrl+Shift+MouseWheel
This software is available under "The HexCtrl License", it is free for any NON-COMMERCIAL use.
See the LICENSE file.