Hex edit control

The HexEdit control is a plain hex editor wrapped in a CEdit derived class called CHexEdit. Where ever you use a CEdit class you can replace it with the CHexEdit class. CHexEdit supports the following features:

  1. Addressdisplay can be short or long or turned off.
  2. Hexdisplay can have any width between 1 and 256 bytes or turned off
  3. Asciidisplay can have any width between 1 and 256 bytes or turned off
  4. Editing in hex or ascii mode
  5. cut/copy/paste support (text and/or binary format, binary compatible with DevStudio)

Undo is in the context menu but not implemented right now. Horizontal scrolling is also not supported right now.

Public Methods


int GetData(LPBYTE p, int len);
Use GetData to retrieve the modified data from the control.
Parameter LPBYTE p pointer to the databuffer
  int len length of the databuffer
Return value number of bytes copied  
Remarks the GetData Method copies the data to the buffer provided with the parameter p.


void SetData(LPBYTE p, int len);
Use SetData to set the content that the control displays for editing
Parameter LPBYTE p pointer to the databuffer
  int len length of the databuffer
Return value none  
Remarks the SetData Method copies the data from the buffer provided with the parameter p into a internal working copy.


CSize GetSel(void);
Use GetSel to retrieve the range of bytes the user has selected.
Parameter none  
Return value
where cx contains the start and cy contains the end of the selection.
Remarks if nothing is selected both cx and cy are -1


void SetSel(int s, int e);
Use SetSel to set the selection.
Parameter int s start of selection
  int e end of selection
Return value
Remarks to clear any selection set both s and e to -1


void SetBPR(int bpr);
Use SetBPR to set the number of bytes per row that will be displayed.
Parameter int bpr number of bytes to display per row
Return value
Remarks SetBPR stands for SetBytesPerRow


void SetOptions(BOOL a, BOOL h, BOOL c, BOOL w);
Used to set various options.
Parameter BOOL a addressdisplay on/off
  BOOL h hexdisplay on/off
  BOOL c asciidisplay on/off
  BOOL w address is short (FALSE) or long (TRUE)
Return value


Download demo project - 32 KB

Download source - 8 KB


  • La confound arbore un dessus noir contraste on the up le Jumpman rouge et un dessous en cement-splatter gris Jordan

    Posted by Vetriatszy on 03/14/2013 03:38am

    apply for a a man Adonis body to attract the girls doing isn't just for finer fitness and well-being, but also to draw the opposite girl or boy. There will vary assessments over attractiveness of people around the world. your girls from any continent may also believe that a guy really need More Bonuses famous protruding muscles, a few can easily actually otherwise. these young girl for example six have abs, while a few think it is not required. additionally, Among these broadly distinct judgments, there is certainly one particular complete important to each of geographical limits around the globe. specific relevant state and this adolescent girls realize a good number pleasing incredibly male body is a fantastic bear with hips relation. to be able to Wikipedia, girls and boys alike unearth people utilizing neck at figures relative amount akin to 1.6, the best looking. thus giving us a large indicator about what definitely makes up allure on the inside a a man physical structure to the girls. typically, As a " friend,a working male calculates more and at last results in being which usually body excellent proportion, He may muscular areas the optimal magnitude, accompanied by tiny furthermore lower stomach. This is a wonderful be. little girls no more particularly big steroidal search almost all muscle builders end up with. they will pick out gents in body frame for instance versions with Abercrombie and as well,as well as the Fitch. you must have good quality the pc muscle number, even if not too much. you should have a sleek waist if possible. beneficial figures come in games and movies which includes 'Fight Club', 'Twilight' and / or 'Ninja Assassin'. Whether you like the flicks you aren't, most likely you will understand with me that the particular main actresses of these shows already have insanely good looking body systems, and this is attractive a great deal to the women. i am sure the marriage gifts raise the last aspect, you will have many violently disagreeing, mood the fact that the famous actors during these training videos are usually way too lean plus which Arnold Schwarzenegger's or Ronnie Coleman's is the only good. I respect for authority a opinion nevertheless,having said that i still chance that you see that a celebrity body is regarded far that much more attractive of late. totally next, i guess yourself believe most, if not all of these locations. basically, The appeal of a within male is indicated mainly truly by means of the arm returning to middle proportion. a strong body ratio trade shows the fitness level of the people effectively. getting factors and this also have an impact the appeal of your physique quite. I think that girls, besides choosing the best arm to finally stomach proportion meaningful, will seek altogether carved capacity with standard integral a tad too

  • read only

    Posted by olga145 on 05/30/2005 04:08am

    How can I make this edit "read only"? Thank you.

  • Mouse Wheel function

    Posted by Legacy on 01/05/2004 12:00am

    Originally posted by: Eusebiete

    BOOL CHexEditEE::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt){
    return CEdit::OnMouseWheel(nFlags, zDelta, pt);
    int oa = m_topindex;
    if(zDelta>0){ //es pa arriba
    if(m_topindex > 0){
    m_topindex -= (m_bpr);
    if(zDelta<0){ //es pa abajo
    if(m_topindex < m_length - m_lpp*m_bpr){
    m_topindex += (m_bpr);
    ::SetScrollPos(this->m_hWnd, SB_VERT, m_topindex / (m_bpr), TRUE);
    if(!m_bNoAddressChange) m_currentAddress += (m_topindex - oa);
    return CEdit::OnMouseWheel(nFlags, zDelta, pt);

  • Memory leak, GDI not released

    Posted by Legacy on 10/01/2003 12:00am

    Originally posted by: MemoryLove

    The memory leak is not due to m_pData but to GDI ressources.

    In method :

    void CHexEdit::OnPaint()
    CPaintDC pdc(this); // device context for painting

    you have the code lines :

    CDC dc;

    but this lines allocates ressources and even if dc is a local variable and will be destructed at the end of method, you have to explicitly call the free method.

    For fixes the buf, add this code line as the last code line of 'void CHexEdit::OnPaint()' method.


    Done it ? Ok check your memory and you will seee that you have no more memory leak ;-)

    • How to locate address

      Posted by random263 on 06/21/2004 10:46am

      I want to locate a given address, and scroll to view it's content, what should I do?

  • how to show the horizontal scroll bar?

    Posted by Legacy on 07/16/2003 12:00am

    Originally posted by: benben

    The hexedit is great, but I find when I change number of the characters per line(horizontal scroll bar is necessary now), no horizontal scroll bar will show.How to fix it?


  • A couple of things...

    Posted by Legacy on 06/23/2003 12:00am

    Originally posted by: Raymond Lee

    First off, great control! It's making my life easier at this very moment. :)

    A couple of things. First, I use this control in a splitter window. The problem is if I have a lot of data in the edit control and I shorten the pane, no vertical scrollbar appears. To remedy this, I wrote:

    void CHexEdit::OnSize(UINT nType, int cx, int cy)
    // Cause the scrollbars to appear if necessary.
    m_bUpdate = TRUE;

    CEdit::OnSize(nType, cx, cy);

    The second thing is I noticed the vertical scrollbar wasn't being calculated correctly. If one line of text is off the screen you cannot scroll down to it. To fix it, modify the two lines shown here in void CHexEdit::UpdateScrollbars()

    si.nMax = (m_length / m_bpr) - 1;
    si.nMax = m_length / m_bpr;


    if(si.nMax > (int)si.nPage)
    if(si.nMax > (int)si.nPage - 1)

    I hope this helps!
    -- Raymond Lee

  • Scroll Problem

    Posted by Legacy on 05/30/2003 12:00am

    Originally posted by: carmelo

    I'm sorry i don�t speek English.
    I think there are some little bugs in this class.
    The problem is the reference Scroll in the event OnKeyDown().

    case VK_PRIOR:
    SetSel(-1, -1);
    OnVScroll(SB_PAGEUP, 0, NULL);

    -Replace for this:
    SetSel(-1, -1);
    m_bNoAddressChange = FALSE;
    OnVScroll(SB_PAGEUP, 0, NULL); break;

    case VK_NEXT:
    SetSel(-1, -1);
    OnVScroll(SB_PAGEDOWN, 0, NULL);

    -Replace for this:
    SetSel(-1, -1);
    m_bNoAddressChange = FALSE;
    OnVScroll(SB_PAGEDOWN, 0, NULL); break;

  • Coloring elements within the control

    Posted by Legacy on 02/23/2003 12:00am

    Originally posted by: Martijn

    I'd like to highlight certain ranges (or single characters) within the total range.. Is there any way to set the background (or foreground) color of those ranges?

  • BUG - missing last character when using copy on ASCII data col

    Posted by Legacy on 12/11/2002 12:00am

    Originally posted by: XM

    Thanks for this control, it helps me.

    Everytime I tried to copy (Ctrl+C) data displayed in the
    ascii-data representing column I got one char less - the
    last one.

    - in the member function OnEditCopy() increase the size
    of the membuffer (1 byte more), so ...

    in the case that we have "m_currentMode==EDIT_ASCII"

    HGLOBAL hMema = ::GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE|GMEM_ZEROINIT, m_selEnd-m_selStart+1); // +1 !

    This is due to the nature of text/strings - they have to be
    null-terminated, and there was not a room for it ...

  • No one found? He didn't free m_pData always!

    Posted by Legacy on 07/11/2002 12:00am

    Originally posted by: alwayscy

    Should do this:
    if (m_pData)

    • This problem is discovered 2 years ago.

      Posted by Xiangying on 12/27/2004 07:10am

      Cheer up!

  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • Entire organizations suffer when their networks can't keep up and new opportunities are put on hold. Waiting on service providers isn't good business. In these examples, learn how to simplify network management so that your organization can better manage costs, adapt quickly to business demands, and seize market opportunities when they arise.

Most Popular Programming Stories

More for Developers

RSS Feeds

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