I am having trouble getting the following to do what I want it to do:
rectList is a CObList containing objects that are of my class CMyRect. r is a member of CMyRect, and is a CRect. In my application, I have several rectangles dispayed, many overlapping each other. What I want this application to do is to delete the rectangles that are clicked on. Thus I have this the following:
void CMainFrame::OnLButtonDown(UINT nFlags, CPoint pt)
{
nbrRects = rectList.GetCount();
pos = rectList.GetHeadPosition();
for (int i = 0; i < nbrRects; i++)
{
pRect = (CMyRect*)rectList.GetNext(pos);
if (pRect->r.PtInRect(pt))
{
rectList.RemoveAt(pos);
delete pRect;
}
}
}
When running the app, I click on some of the outside rectangles and nothing happens. When clicking on a rectanle toward the center, I get an assertation failure and am pointed to line 299 in list_o.cpp which goes like this:
ASSERT(AfxIsValidAddress(pOldNode, sizeof(CNode)));
and I determined one of my problems is at rectList.RemoveAt(pos). I can't figure out what the problem with this line is, and I can't figure out why the rectangles are still being displayed on the Client window.
Please tell me what I am doing wrong here! lol Thanks in advance.
-Bones
rectList is a CObList containing objects that are of my class CMyRect. r is a member of CMyRect, and is a CRect. In my application, I have several rectangles dispayed, many overlapping each other. What I want this application to do is to delete the rectangles that are clicked on. Thus I have this the following:
void CMainFrame::OnLButtonDown(UINT nFlags, CPoint pt)
{
nbrRects = rectList.GetCount();
pos = rectList.GetHeadPosition();
for (int i = 0; i < nbrRects; i++)
{
pRect = (CMyRect*)rectList.GetNext(pos);
if (pRect->r.PtInRect(pt))
{
rectList.RemoveAt(pos);
delete pRect;
}
}
}
When running the app, I click on some of the outside rectangles and nothing happens. When clicking on a rectanle toward the center, I get an assertation failure and am pointed to line 299 in list_o.cpp which goes like this:
ASSERT(AfxIsValidAddress(pOldNode, sizeof(CNode)));
and I determined one of my problems is at rectList.RemoveAt(pos). I can't figure out what the problem with this line is, and I can't figure out why the rectangles are still being displayed on the Client window.
Please tell me what I am doing wrong here! lol Thanks in advance.
-Bones