|
-
September 28th, 2006, 12:59 PM
#1
I am corrupting memory ?
I creat an edit box dynamically to allow the user to modify text. The user types in the information and upon pressing enter twice, the edit box sends a message to the view that the edit is complete. The OnEditComplete(...) handler then obtains information from the edit box save the information to the database and hides itself. The edit box is not destroyed until it is re-created or the view is closed in which the destructor deletes this.
There has to be some memory corruption going on because when I open a schedule in my application close and reopen, everything is fine until I create this edit box, make some changes and press enter twice.
Code:
void CMileStone::OnLButtonDblClk(UINT nFlags, CPoint point)
{
CClientDC dc(this);
OnPrepareDC(&dc);
CRect rcBoundary = GetCalendar()->GetBoundary();
dc.LPtoDP(&rcBoundary);
rcBoundary.NormalizeRect();
if(rcBoundary.PtInRect(point))
{
CRect rcWorkspace = GetCalendar()->GetWorkspaceRect();
dc.LPtoDP(rcWorkspace);
rcWorkspace.NormalizeRect();
if(rcWorkspace.PtInRect(point))
{
}
else
{
dc.DPtoLP(&rcWorkspace);
CPoint pt(point);
dc.DPtoLP(&pt);
CMileStoneRowLabel* pLabel = NULL;
CMileStoneRow* pRow = NULL;
if(GetRowByPoint(pt, pRow) >= 0)
{
m_nCurrentRowID = pRow->GetRowID();
if(pRow->GetRowLabelByPoint(pt, pLabel))
{
CRect rc = pLabel->GetBoundary();
dc.LPtoDP(&rc);
rc.NormalizeRect();
rc.DeflateRect(CSize(2,2));
if(m_pEdit)
delete m_pEdit;
m_pEdit = new CInPlaceEdit();
if(!m_pEdit->CreateInplaceEdit(this, pLabel->GetTextAlignment(), pLabel->GetFontSettings()))
return;
m_pEdit->SetWindowText(pLabel->GetLabel());
m_pEdit->SetExtendedData(0, (DWORD)pLabel);
m_pEdit->MoveWindow(&rc);
m_pEdit->ShowWindow(SW_SHOW);
m_pEdit->SetFocus();
m_pEdit->SetSel(0, -1); }
}
else
m_nCurrentRowID = 0;
}
}
CAutoScrollView::OnLButtonDblClk(nFlags, point);
}
void CMileStone::OnEditComplete(WPARAM wParam, LPARAM lParam)
{
DWORD dwDummy = 0;
DWORD dwLabel = 0;
m_pEdit->GetExtendedData(dwDummy, dwLabel);
CMileStoneRowLabel* pLabel = (CMileStoneRowLabel*)dwLabel;
if(pLabel != NULL)
{
int nRowID = pLabel->GetRowID();
int nColumnID = pLabel->GetHeadingID();
CString csText = m_pEdit->GetText();
if(SaveRowLabel(nRowID, nColumnID, pLabel->GetFontSettings(), pLabel->GetTextAlignment(), csText))
pLabel->SetLabel(csText);
}
m_pEdit->ShowWindow(SW_HIDE);
}
Anyone see anything wrong with the above approach?
Mike B
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|