Originally posted by: Moshe Berger
Sometimes when scrolling up with the mouse a crash might happen. It seems that the crash happens when you click with the mouse on the scroll bar to scroll up above the middle row.
To fix it edit the OnVScroll() function. Replace this row, which appears near the end of the function:
if(!m_bNoAddressChange)
with this one:
if(!m_bNoAddressChange && (m_topindex - oa) > 0)
Originally posted by: Todd Trimble
Some things I'll soon start working on but thought I'd ask if anyone else has implemented so I don't reinvent the wheel...
1) I'd like to use this control to display a small segment anywhere in a large memory space. For example, I'd like to clearly explain to the user that the 64 bytes visible in the pane are actually at 0x8000-0x803F in a memory block. Is there a good way to give a base offset to the address displayed to the left of the data or does the first line in the buffer always have to be 0x0000?
2) If I have just filled my buffer with say 48 bytes read from memory and I want to add a few bytes to the end of the buffer, it's a little irritationg to have to select the last existing byte in the buffer, press insert, retype the byte that just got shifted out of the current location and then move to the new last byte and insert my new data. In other words, is there a way to have insert (or some other mechanism) add bytes AFTER the selected byte and not before? That way my first INSERT keypress would leave the original data unmodified and allow me to just start adding bytes at the end...
3) At times, when the control has just been newly created, clicking somewhere in the control will cause all the displayed info (address, data & ASCII) on the line to seemingly disappear. Typing any one character is enough to refresh the display and bring the info back, but that leaves open the possibility that the data has now been modified from it's original by the keypress. Any one else seen this and delt with it?
I'd be happy to hear from anyone who has dealt with any of these things or issues similar. I'll report my findings once solutions are developed or found. Thanks!
Todd Trimble
Originally posted by: Scott Guillaudeu
I have just a couple of fixes to post--hopefully they help you.
1. The program may crash if you are scrolling with the UP arrow when you go past the top. Edit this code in OnVScroll:
case SB_LINEUP:
2. I added this code to update m_currentAddress. This fixes the problem when the cursor is on the bottom line, and you hit page up (when you have enough data to scroll), the cursor stays below the viewable window. If you press UP a couple of times, you will see cursor artifacting outside the edit control. It's the opposite for page down.
case SB_PAGEDOWN:
case SB_PAGEUP:
3. If you click the mouse to position the cursor one line below the end of your data, the cursor will stay there (sometimes leaving artifacts on the horizontal scroll bar). This is an off-by-one error in CalcPos(int x, int y).
y /= m_lineHeight;
4. This final fix is for a crash when you select data from the bottom up (backwards). The source is just missing a few calls to NormalizeSel(). Add the calls at the top of OnEditClear, OnEditCopy, and maybe GetSel. OnEditCut calls OnEditCopy, so you don't need one there. OnEditPaste already calls NormalizeSel().
First I'd like to thank the author for saving me a ton of time!! This control is good looking and very functional! Thankyou!
if (m_topindex > 0)
{
if (m_topindex >= m_bpr) // ensures m_topindex will not be negative
m_topindex -= m_bpr;
}
RedrawWindow();
Again, edit OnVScroll:
if(m_topindex < m_length - m_lpp*m_bpr)
{
m_topindex += m_bpr * m_lpp;
if (m_currentAddress + m_lpp * m_bpr <= m_length) {
m_currentAddress += m_lpp * m_bpr;
}
if(m_topindex > m_length - m_lpp*m_bpr)
m_topindex = m_length - m_lpp*m_bpr;
RedrawWindow();
}
break;
if(m_topindex > 0)
{
m_topindex -= m_bpr * m_lpp;
if (m_currentAddress > m_bpr * m_lpp) {
m_currentAddress -= m_bpr * m_lpp;
}
if(m_topindex < 0)
m_topindex = 0;
RedrawWindow();
}
break;
Just change the first "if" statement to:
if(y < 0 || y >= m_lpp) // notice >= instead of > fixes off-by-one bug
return CPoint(-1, -1);
BTW--NormalizeSel uses a cool algorithm I've never seen before. It swaps two variables without using a temp var by using XOR. Cool!
Originally posted by: Xia Li
This is almost what I want. But this hexedit seems only allow you to edit preloaded data(38 bytes). How about user want to add more data?
Thanks for advance!
xia
Refer VK_INSERT section of OnKeyDown() in source.
ReplyOriginally posted by: Atlas Wang
I think that class of HexEdit is great. It saves me a lot of time when I do my project. However, I think there are some little bugs in it.
First, when I use DELETE key to delete data in the client window, if data is deleted all and then press DELETE key down, a system error will appear. I do not know why. But if using mouse to select all data all delete it, no problem;
Second, I want to use it in a controlbar. The contolbar is created dynamically and a Hexedit window is created dynamically, too. If the initial data all in the window, the VScoll bar will not appear. But if I dynamically add some data in it and make the length of data greater than a page, the vscrollbar cannot appear properly. Always it cannot draw the up & down arrows. I tried a lot but I cannot sovle it.
Anyway, thank the author and hope HexEdit can be perfect.
I found it. You can rewrite SelDelete() funcion: m_length=m_length-(e-s); Replace for this: m_length=(m_length>0?(m_length-(e-s)):0); when e-s=1 and m_length=0, it will change m_length to -1!
ReplyOriginally posted by: Todd Trimble
Nice work. One question:
When I try to instantiate a control of type CHexEdit, the dialog draws nicely execpt that there appears to be a blinking cursor that extends from the upper left corner of my HexEdit control to the lower right corner of my dialog. As soon as I use the mouse to select any part of the HexEdit, the cursor returns to normal.
Does this happen to anyone else? Solutions?
Thanks again!
Todd
ReplyOriginally posted by: Chris Wegrzyn
Anyways, like most hex editor programs, (I'd think so...) mine needed to be able to open large files (at least one or two megabytes). I noticed however, that while scrolling, by dragging the scroll box, the application would crash after a certain point. I determined that it was an overflow mixed with UINT/int conversions, that caused m_topindex to be set to a negative number in OnVScroll. Anyways, change the code for "case SB_THUMBTACK:" in the OnVScroll member function to:
ZeroMemory(&si, sizeof(SCROLLINFO));
m_topindex = si.nTrackPos * m_bpr;
That's all! That fixed the scrolling problem for me. Have fun! And thanks again to the author!
-- Chris Wegrzyn
First of all, I'd like to thank the author for making such a great class. I thought I'd have to spend hours creating this sort of control, but I _ALWAYS_ check CodeGuru first =)
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_TRACKPOS;
// Call GetScrollInfo to get current tracking
// position in si.nTrackPos
// Yep...Copied almost straight out of the Platform SDK =)
if (!::GetScrollInfo(this->m_hWnd, SB_VERT, &si) )
return; // GetScrollInfo failed
RedrawWindow();
break;
Originally posted by: Peter
The navigation keys(right,left,up,down) works fine as long
as there are no activex controls in the view. When there is an
activex control in the view, the focus shifts to the Activex control
I don't know how to solve the problem.
thanks
--Peter
Originally posted by: Olivier RAMAT
However, besides some caret positioning problems, I fixed two bugged functions
This rewriting of the SelInsert ensures m_pData is assigned the value of p before the SetSel
void CHexEdit::SelDelete(int s, int e)
{
LPBYTE p = (LPBYTE) malloc(m_length - (e-s)+1);
memcpy(p, m_pData, s);
if(s < m_length-(e-s))
memcpy(p+s, m_pData+e, (m_length -e));
free(m_pData);
m_pData = p;
SetSel(-1, -1);
m_length = m_length-(e-s);
if(m_currentAddress > m_length)
{
m_currentAddress = m_length;
RepositionCaret(m_currentAddress);
}
m_bUpdate = TRUE;
}
void CHexEdit::SelInsert(int s, int l)
{
LPBYTE p = (LPBYTE) calloc(m_length + l, 1);
memcpy(p, m_pData, s);
memcpy(p+s+l, m_pData+s, (m_length-s));
free(m_pData);
m_pData = p;
SetSel(-1, -1);
m_length = m_length+l;
m_bUpdate = TRUE;
}
This hex edit control is great. I needed such a control in my project
and it saved my a lot of time.
causing memory access violations.
function updates the control, so avoiding memory access violation during the drawing of the
control with the OnPaint function.
The same applies to the rewriting of the SelDelete.
Originally posted by: Maarten Hoeben
I needed a Hex Edit Control in one of my applications. This implementation saved me a lot of work. However, apart from the memory bugs, the caret movement with the page-up/page-down keys do not seem to work properly. My understanding of the code is that on a page-down, the caret has to move to the last visible line, and if it is already on that line, a page down should occur. If the caret is at the last line, everything seems to work ok. If the caret is not on the last visible line, the controls simply pages-down and leaves the caret out of sight (causing it to be drawn outside the control in some cases!). For page-up, the bug is vice versa.
System: VC6, Window 98.