Click here to Skip to main content
15,890,579 members
Articles / Programming Languages / C++
Article

Simple Hex Editor

Rate me:
Please Sign up or sign in to vote.
2.86/5 (12 votes)
27 Jul 20032 min read 116.9K   4.7K   35   14
A simple hex editor

Hex Editor

Introduction

One of the most useful tools for programmers is a good Hex editor. So, I decided to throw one together. There is lots of room for more features, such as find functionality, but it is still a good hex editor. It is a good example of how to implement custom document views.

Description

The applications is SDI, with a view based off of CScrollView. The data is loaded into a CString object. I used CString because of its easy memory management (GetBuffer() and Empty() were all I needed). The view class manually draws the text data twice, in ASCII on the left and in hex on the right. Simple highlighting and cursor control is written into the view class, while data manipulation is handled by the data interface. It was really more for my own experience, but I decided that it might be a handy example for fellow programmers on a similar path.

Points of interest

The scrolling may or may not be implemented the way it was intended. I couldn't find very good documentation on how to get it working perfectly, so I set the origins to the top left and simply calculated the visible lines myself. There may be a better way to do that (if there is, tell me), but the end result is that I only draw what I need, making the rendering fast enough to be usable. I also managed to avoid erasing the screen for everything except scrolling.

Known bugs

There are probably quite a few. Meh.

Updates

July 24, 2003 - Fixed the package, fixed drawing to use a memory dc making scrolling smooth, attempted to fix mousewheel scrolling (unable to confirm, no mouse to test with), used window color instead of plain white for background, disabled printing, fixed signed/unsigned warnings.

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


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
SuggestionNew feature Pin
WillianBR5-Jan-12 6:06
WillianBR5-Jan-12 6:06 
GeneralQuick 'n' dirty way Pin
andwan07-Jun-09 11:45
andwan07-Jun-09 11:45 
GeneralImportant Question Pin
Fabian Ganter7-Aug-08 3:12
Fabian Ganter7-Aug-08 3:12 
GeneralHex Edit 2.5F Pin
Andrew Phillips7-Apr-08 18:22
Andrew Phillips7-Apr-08 18:22 
GeneralFree hex editor with MFC source Pin
Andrew Phillips1-Mar-05 12:02
Andrew Phillips1-Mar-05 12:02 
GeneralRe: Free hex editor with MFC source Pin
PaulFrazee2-Mar-05 11:25
PaulFrazee2-Mar-05 11:25 
GeneralThis is not an editor... it is a viewer! Pin
Spiceworm22-Feb-05 10:55
Spiceworm22-Feb-05 10:55 
GeneralRe: This is not an editor... it is a viewer! Pin
PaulFrazee22-Feb-05 17:15
PaulFrazee22-Feb-05 17:15 
GeneralShould be more function. Pin
ICE_WIZARD22-Jul-03 6:18
ICE_WIZARD22-Jul-03 6:18 
GeneralQuick and Dirty fixes Pin
McGarrah21-Jul-03 15:55
McGarrah21-Jul-03 15:55 
GeneralRe: Quick and Dirty fixes Pin
PaulFrazee22-Jul-03 11:15
PaulFrazee22-Jul-03 11:15 
GeneralMissing files & bugs Pin
billgatest19-Jul-03 1:27
billgatest19-Jul-03 1:27 
1) No resource.h file in zip archive
2) Executable in zip file is debug version - should be release version
3) Program uses white for background color of text, but uses default windows color for window background. Use one or the other, but not both.
4) Mousewheel scrolling causes window to be redrawn incorrectly under windows xp - background is not erased.
5) Print preview shows printout will occupy tiny area of page. If feature is not implemented, delete menu item.
6) Lots of flickering when scrolling - write to memory DC instead of screen directly.
7) Lots of signed/unsigned comparison warnings during compile. Add casts to remove warnings.
GeneralRe: Missing files & bugs Pin
PaulFrazee19-Jul-03 8:42
PaulFrazee19-Jul-03 8:42 
GeneralScrolling doesn't work Pin
Dominik Reichl18-Jul-03 6:01
Dominik Reichl18-Jul-03 6:01 

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.