Click here to Skip to main content
12,818,508 members (35,238 online)
Click here to Skip to main content
Add your own
alternative version


28 bookmarked
Posted 26 Jun 2001

Hex Edit Control

, 26 Jun 2001
Rate this:
Please Sign up or sign in to vote.
An Hex Editing control that switches between plain text and HEX modes (using RICHED20.DLL)
<!-- Download Links --> <!-- Article image -->

Sample Image - hexedit.jpg

<!-- Add the rest of your HTML here -->

If you have the need to edit character data in HEX and character modes and there is not enough space on the screen to use a fully featured HEX edit control, then this is for you. This HEX edit control allows the user to edit text in HEX or normal ASCII modes and switch between the two. Current text selection cursor position is preserved when switching between the two modes allowing particular areas of text to be highlighted and viewed in HEX mode.

Non-printable characters are displayed as an upside-down question mark by default although this character can be changed by calling the SetBinaryCharacter method. The public methods available on CHexEditCtrl are:-

    enum DataMode { TEXT_MODE = 0, HEX_MODE };
    void SetBinaryCharacter(TCHAR ch);
    virtual void SetDataSelection(const long nFirst, const long nLength);
    void DataToScreen();
    void SetData(CString Data, long nLength);
    void GetData(CString& Data, const long nMaxLength, long& nLengthReturned);

    void SetDataMode(const DataMode& mode);

    // only tests data changed since the last call to this function
    BOOL IsDataChanged();	

In order to use the control the steps are

  1. Create a custom control on the screen with a blank caption, class of RichEdit20A, style of 0x50a11084 and exstyle of 0x0.
  2. In the dialogs associated .h file, in the //{{AFX_DATA(... section add the control, eg. CHexEditCtrl m_HexEdit;
  3. In the dialogs associated .cpp file, in the DoDataExchange section add DDX_Control(pDX, IDC_HEXEDIT, m_HexEdit); where the IDC_HEXEDIT matches the resource identifier for the custom control on the dialog

This should be all that is needed to get going. The control may be useful for the display of character messages transferred between hardware devices connected to the PC.

This code works in UNICODE, however, it only displays the hex characters as though it were ASCII.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

philip andrew
Hong Kong Hong Kong
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralEnter ASCII in HEX-Mode Pin
ItsMeAgain3-Dec-03 4:39
memberItsMeAgain3-Dec-03 4:39 
GeneralRe: Enter ASCII in HEX-Mode Pin
conrad Braam28-Jan-04 1:38
memberconrad Braam28-Jan-04 1:38 
Generalerror Pin
suby5r7654rgfv19-Dec-01 9:40
membersuby5r7654rgfv19-Dec-01 9:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 27 Jun 2001
Article Copyright 2001 by philip andrew
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid