Click here to Skip to main content
Click here to Skip to main content

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:-

public:
    enum DataMode { TEXT_MODE = 0, HEX_MODE };
public:
    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.

License

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

Share

About the Author

philip andrew

Hong Kong Hong Kong
No Biography provided

Comments and Discussions

 
GeneralEnter ASCII in HEX-Mode PinmemberItsMeAgain3-Dec-03 3:39 
GeneralRe: Enter ASCII in HEX-Mode Pinmemberconrad Braam28-Jan-04 0:38 
Generalerror Pinmembersuby5r7654rgfv19-Dec-01 8:40 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 27 Jun 2001
Article Copyright 2001 by philip andrew
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid