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:
- Addressdisplay can be short or long or turned off.
- Hexdisplay can have any width between 1 and 256 bytes or turned off
- Asciidisplay can have any width between 1 and 256 bytes or turned off
- Editing in hex or ascii mode
- 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
GetData
|
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. |
SetData
|
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. |
GetSel
|
CSize GetSel(void); |
| Use GetSel to retrieve the
range of bytes the user has selected. |
| Parameter |
none |
|
| Return value |
CSize
|
where cx contains the start and cy contains
the end of the selection. |
| Remarks |
if nothing is selected both cx
and cy are -1 |
SetSel
|
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 |
none
|
|
| Remarks |
to clear any selection set both
s and e to -1 |
SetBPR
|
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 |
none
|
|
| Remarks |
SetBPR stands for
SetBytesPerRow |
SetOptions
|
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 |
none
|
|
| Remarks |
|
Download demo project - 32 KB
Download source - 8 KB
Comments
read only
Posted by olga145 on 05/30/2005 04:08amHow can I make this edit "read only"? Thank you.
ReplyMouse Wheel function
Posted by Legacy on 01/05/2004 12:00amOriginally posted by: Eusebiete
ReplyBOOL CHexEditEE::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt){
if(!m_pData)
return CEdit::OnMouseWheel(nFlags, zDelta, pt);
int oa = m_topindex;
if(zDelta>0){ //es pa arriba
if(m_topindex > 0){
m_topindex -= (m_bpr);
RedrawWindow();
}
}
if(zDelta<0){ //es pa abajo
if(m_topindex < m_length - m_lpp*m_bpr){
m_topindex += (m_bpr);
RedrawWindow();
}
}
::SetScrollPos(this->m_hWnd, SB_VERT, m_topindex / (m_bpr), TRUE);
if(!m_bNoAddressChange) m_currentAddress += (m_topindex - oa);
RepositionCaret(m_currentAddress);
return CEdit::OnMouseWheel(nFlags, zDelta, pt);
}
Memory leak, GDI not released
Posted by Legacy on 10/01/2003 12:00amOriginally posted by: MemoryLove
-
ReplyHow to locate address
Posted by random263 on 06/21/2004 10:46amI want to locate a given address, and scroll to view it's content, what should I do?
Replyhow to show the horizontal scroll bar?
Posted by Legacy on 07/16/2003 12:00amOriginally posted by: benben
Hi:
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?
Thanks
benben
Reply
A couple of things...
Posted by Legacy on 06/23/2003 12:00amOriginally 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;
BECOMES
si.nMax = m_length / m_bpr;
AND...
if(si.nMax > (int)si.nPage)
BECOMES
if(si.nMax > (int)si.nPage - 1)
I hope this helps!
-- Raymond Lee
Reply
Scroll Problem
Posted by Legacy on 05/30/2003 12:00amOriginally 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:
.....
else
SetSel(-1, -1);
OnVScroll(SB_PAGEUP, 0, NULL);
Move(0,0);
break;
-Replace for this:
......
else
SetSel(-1, -1);
m_bNoAddressChange = FALSE;
OnVScroll(SB_PAGEUP, 0, NULL); break;
case VK_NEXT:
.....
else
SetSel(-1, -1);
OnVScroll(SB_PAGEDOWN, 0, NULL);
Move(0,0);
break;
-Replace for this:
Reply......
else
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:00amOriginally 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?
ReplyBUG - missing last character when using copy on ASCII data col
Posted by Legacy on 12/11/2002 12:00amOriginally posted by: XM
Reply
No one found? He didn't free m_pData always!
Posted by Legacy on 07/11/2002 12:00amOriginally posted by: alwayscy
Should do this:
CHexEdit::~CHexEdit()
{
if (m_pData)
free(m_pData);
}
-
ReplyThis problem is discovered 2 years ago.
Posted by Xiangying on 12/27/2004 07:10amCheer up!
ReplyHOWTO: use in visual basic project
Posted by Legacy on 05/27/2002 12:00amOriginally posted by: Ashwi Ambekar
I need to use the HexEdit in my visual basic code. I registerd the OCX, now when I call SetData, I get error while compiling ,
Reply"Function or interface marked as restricted, or function uses automation type not supported in Visual basic.
Loading, Please Wait ...