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

Hex Edit Control

By , 26 Jun 2001
 
<!-- 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

About the Author

philip andrew

Hong Kong Hong Kong
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralEnter ASCII in HEX-ModememberItsMeAgain3-Dec-03 3:39 
GeneralRe: Enter ASCII in HEX-Modememberconrad Braam28-Jan-04 0:38 
Generalerrormembersuby5r7654rgfv19-Dec-01 8:40 

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

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