Virtual Developer Workshop: Containerized Development with Docker

Environment: Visual C++ 6, Win NT,2000,95,98


Since I couldn't find a hexedit control that fit my needs, I launched this project to develop my own hex edit control. This hex edit control is a complete implementation of a hex edit control that features most of the wanted edit features all the standard edit controls offer. It can be used as a simple single line edit box or as a view for a hexeditor-application (see screenshot).


  • multi- / single-line (depending on the windows-style)
  • automatical scrolling when multi-line
  • horizontal scrolling without scrollbars when single-line
  • show Address (on/off)
  • variable Address-Size
  • show Binary (on/off)
  • cursor navigation (arrows, home, end, page up/down)
  • copy/paste (ctrl+c / ctrl+v)
  • context menue (copy / paste) with strings from resources, when IDS_CONTROL_COPY, IDS_CONTROL_PASTE is defined
  • edit (only hex-data, not binary)
  • selection (only hex-data)
  • special highlighting of a section (not selection)
  • show selection always (only multiline mode)
  • set how many bytes per row or let it calculate (automatic)
  • set colours (every colour can be set)
  • set readonly (enabled/disabled: no colour-difference)
  • Viewclass to use directly as a view (derived from CView)


  • Currently it's only possible to edit in the hex view and not the text/binary view of the data.
  • The size of the data is fix, it's not possible to insert data. (there is no insert mode, only overwrite mode)

Basic Instructions to use the control/view in your code

1) Use folowing Code in the InitInstance of your application class.

CHexEditBase::RegisterClass(); //when using the CHexEditBase_SC 
                               //windows class (not needed for 
                               //the examples here)

2) Using the view is pretty simple

2.1) Use the Wizzard to create a class derived from CEditView

2.2) Replace all the "CEditView" with "CHexEditBaseView" in the generated files

2.3) To set the data which has to be displayed you can use one of two methods:

  • SetDirectDataPtr(BYTE* pData, UINT nSize, bool bUpdate)
    If you have a large amount of data and you don't want the View to buffer it. If the control is not read-only, user input will directly modify the data pointed to by pData. And you have to make sure that this pointer will be valid as long as the control lives or it has been set to display some other data (efficient but less secure methode to set the diplayed data)
  • SetData(const BYTE* pData, UINT nSize, bool bUpdate)
    This methode copies the data given by pData (with size in bytes of nSize). Modifications will be made to the buffer the view maintains. After editing you can call GetData to get the modified data from the control.

2.4) Use something like the folowing code in the OnInitialUpdate methode

// example code for OnInitialUpdate for view class
// (derived from CHexEditBaseView)
GetHexEditCtrl().SetDirectDataPtr(m_pDataPtr, m_nSize, false);
GetHexEditCtrl().SetAddressSize(4, false);
GetHexEditCtrl().SetShowAddress(true, false);
GetHexEditCtrl().SetShowAscii(true, false);
GetHexEditCtrl().SetBytesPerRow(16, true, true);

3) Using the control is easy as well (only easiest way is discribed here)

3.1) Edit the dialogresource and insert edit-controls where you want to see the hex-control later.

3.2) Set multiline-flag when you want to use the control as a multiline (resource editor).

3.3) Use the ClassWizard to connect a member-variable (control (NOT value)) with the previously inserted edit-control. (use class CEdit)

3.4) Use the code editor and replace the CEdit (int the h-file of your dialog/fomview) with CHexEditBase. Don't forget to include "hexeditbase.h" there.

3.5) Go to the InitDialog (or insert it) and use the m_HexEdit (or how ever your member is called) to set data:

m_HexEdit.SetData((const BYTE*)"dummydata", 9);

3.6) Use other members to set other attributes (set bUbdate (usually last parameter for set-methodes) only with the last SetXXXXX-Methode:

// example how to use CHexEditBase in OnInitDialog

m_cHexEdit.SetShowAddress(false, false);

m_cHexEdit.SetShowAscii(false, false);

//bUpdate=true for the last one
m_cHexEdit.SetData((const BYTE*)"dummydata", 9, true);

For more information about how to use this control check out the sourcode from the demoproject.

Version History

  • version
    • first version of this control

  • version
    • bug in CreateHighlightingPolygons (when scrolling highlighting out of window on top, sometimes the address got overpainted by some parts of the highlighting section)

  • version
    • MakeVisible is now slightly smarter
    • SetFont, GetFont WM_SETFONT, WM_GETFONT works now

  • version
    • Fixed the 16Bit scroll range limitation when thumbtracking (see OnVScroll)
    • Modified SetFont to only accept fixed-pitched fonts
    • Replaced some GetSafeHwnd() with ::IsWindow(m_hWnd)
    • Call DestroyWnd from the Destructor, to get rid of the TRACE from "CWnd::~CWnd ..."


Download demo project - 70 Kb
Download source - 20 Kb


  • Cooooool !!! Thanx

    Posted by olga145 on 05/30/2005 01:41pm

    Cooooool !!! Thanx

  • Hex edit control

    Posted by Legacy on 08/22/2003 07:00am

    Originally posted by: Costas Vlachidis

    Thanx for making this piece of code public.I'm using it in image processing!

  • Memory leak

    Posted by Legacy on 03/02/2003 08:00am

    Originally posted by: redsword

    Memory leak!
    yes ! it's great. but this class due to memory leak.
    in your code:
    try {
    pControl = new CHexEditBase();

    if (!pControl->SubClassWindow(hwnd)) {

    return TRUE; // Free ??????


    • it is free here: PostNcDestroy & m_bSelfCleanup

      Posted by jauming on 09/03/2007 07:03am

      void CHexEditBase::PostNcDestroy() 
      	if(m_bSelfCleanup) {
      		m_bSelfCleanup = false;
      		delete this;

  • HexEdit

    Posted by Legacy on 09/26/2002 07:00am

    Originally posted by: SpazyMoto

    Could you give me a starting direction to be able to paint the hex numbers based on there value? This could help to pick out table in code. Example you have the hex values of
    ff fe fd fc fb fa and you paint the rectangle or text to be diffrent shades of red ff would be bright red and fa would be a lighter shade of red.

  • Nice work!

    Posted by Legacy on 05/05/2002 07:00am

    Originally posted by: SuNr

    Nice control! Easy, fast...useful!

  • Do you have implementation to chage the data size?

    Posted by Legacy on 04/24/2002 07:00am

    Originally posted by: Sadru

    Do you have implementation to chage the data size?

  • Well done control

    Posted by Legacy on 03/06/2002 08:00am

    Originally posted by: Wolfgang Ibl

    This is really a cool control with a lot of features. I have only 2 questions:

    Is it possible to display a (disabled) vertical scroll bar, even if the control's content does not exceed it's height (like it can be done with the CEdit) - the reason is, that if you fit it into a dialog, you have an ugly stripe on the right without the bar...

    Is it possible to have the ascii column editable?


  • Thank you

    Posted by Legacy on 11/11/2001 08:00am

    Originally posted by: HsiaLin

    Thank you for this fine vc++ source, but if you will port it to Builder 5.0 i`ll give you a high-five :-)

  • Wonderful control....more?

    Posted by Legacy on 11/07/2001 08:00am

    Originally posted by: Mike Lashbrook

    I love this view control and use it frequently. The only question that I have is.... Will it ever support an insert mode? That is really the only thing missing that would make it a perfect binary file editor.

    Thanks for the control,

  • Great work but.............

    Posted by Legacy on 10/18/2001 07:00am

    Originally posted by: Rajesh

    Hi Christian,

    Great work!!! I have an application which requires large file to be edited..but when i open a these large files for obvious resons the memory usage goes up. Is there a way by which I read only those many bytes from the file needed to be displayed depending on the current size of the window. Ofcourse there are alot of issues like how would you handle the scrolling...Do, you have any suggestions how this can be done, or if you already have a fix that will be great;-)

    thanks and Regards

  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date