Re: I am corrupting memory ?
dynamical allocating is unnecessary
Kuphryn
Re: I am corrupting memory ?
Ok, I changed the code in the CInPlaceEdit class to post the message rather than send the message, this allowed me to delete the edit right away in OnEditComplete(), but I still have the problem.
Code:
void CInPlaceEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if(nChar == VK_RETURN)
{
m_nEnterPressed++;
if(m_nEnterPressed == 2)
GetParent()->PostMessage(TEXT_EDIT_COMPLETE, 0, 0); }
else
{
m_nEnterPressed--;
if(m_nEnterPressed < 0)
m_nEnterPressed = 0;
}
CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
}
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);
delete m_pEdit;
m_pEdit = NULL;
}
Also, one other question, the same logfont settings are used by the edit box and the label drawn in the view, but they appear to be much different in size. Is there something with the edit box that doesn't allow the font height to change?
Mike B
Re: I am corrupting memory ?
Quote:
Originally Posted by kuphryn
dynamical allocating is unnecessary
Kuphryn
Not sure how I can do it any other way. I was under the impression that certain settings cannot be set for the CEdit control during runtime, such as text alignment.
1) If I create the edit on the stack, it just goes out of scope.
2) If I create a member CInPlaceEdit m_edit;, I cannot change the text alignment.
Unless I am missing something, I need to dynamically create the edit. Do you have any suggestions?
Mike B
Re: I am corrupting memory ?
why are you using pointers?
Re: I am corrupting memory ?
Quote:
Originally Posted by Alin
why are you using pointers?
OK, this is for you and kuphryn, I have changed the code, I am no longer using pointers.
I created a CInPlaceEdit as a member variable of the class. I then call its CreateInPlaceEdit(...) function which creates the control, I then set everything and show the edit. Then in OnEditComplete() I call Detach() on the edit (Is that all I have to do?).
Code:
void CMileStone::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// A buch of irrelevant code
if(!m_edit.CreateInplaceEdit(this, pLabel->GetTextAlignment(), pLabel->GetFontSettings()))
return;
m_edit.SetWindowText(pLabel->GetLabel());
m_edit.SetExtendedData(0, (DWORD)pLabel);
m_edit.MoveWindow(&rc);
m_edit.ShowWindow(SW_SHOW);
m_edit.SetFocus();
m_edit.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_edit.GetExtendedData(dwDummy, dwLabel);
CMileStoneRowLabel* pLabel = (CMileStoneRowLabel*)dwLabel;
if(pLabel != NULL)
{
int nRowID = pLabel->GetRowID();
int nColumnID = pLabel->GetHeadingID();
CString csText = m_edit.GetText();
if(SaveRowLabel(nRowID, nColumnID, pLabel->GetFontSettings(), pLabel->GetTextAlignment(), csText))
pLabel->SetLabel(csText);
}
m_edit.ShowWindow(SW_HIDE);
m_edit.Detach();
/* delete m_pEdit;
m_pEdit = NULL;*/
}
I am now not convinced it is the edit causing the problem, might be the CMileStoneItemLabel* that is being passed through the edit box, CInPlaceEdit::SetExtendedData(DWORD dw1, DWORD dw2) and
CInPlaceEdit::GetExtendedData(DWORD& dw1, DWORD& dw2).
Ok, let me look into this a bit further, but answer me this, is Detach() all I have to call on the CInPlaceEdit member in order to create a new one?
Mike B
Re: I am corrupting memory ?
i'd do something like:
Code:
if (!IsWindow(m_edit.m_hWnd))
{
if(!m_edit.CreateInplaceEdit(this, pLabel->GetTextAlignment(), pLabel->GetFontSettings()))
Re: I am corrupting memory ?
Code:
CaDlg::CaDlg(CWnd* pParent /*=NULL*/)
: CDialog(CaDlg::IDD, pParent)
, m_bIsHidden(FALSE)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CaDlg::OnCreateShow()
{
// TODO: Add your control notification handler code here
if(!IsWindow(m_edit.m_hWnd))
{
if(m_edit.Create(WS_CHILD | WS_BORDER | WS_VISIBLE, CRect(10, 10, 100, 100), this, 1))
m_edit.ShowWindow(SW_SHOW);
}
else
if(m_bIsHidden)
{
m_bIsHidden = FALSE;
m_edit.ShowWindow(SW_SHOW);
}
}
void CaDlg::OnHide()
{
// TODO: Add your control notification handler code here
m_edit.ShowWindow(SW_HIDE);
m_bIsHidden = TRUE;
}
Re: I am corrupting memory ?
Code:
void CaDlg::OnCreateShow()
{
// TODO: Add your control notification handler code here
static BOOL m_bIsCreated = FALSE;
if(m_bIsCreated == FALSE)
{
if(m_edit.Create(WS_CHILD | WS_BORDER | WS_VISIBLE, CRect(10, 10, 100, 100), this, 1))
{
m_bIsCreated = TRUE;
m_edit.ShowWindow(SW_SHOW);
}
else
{
m_bIsCreated = FALSE;
return;
}
}
else
m_edit.ShowWindow(SW_SHOW);
}
void CaDlg::OnHide()
{
// TODO: Add your control notification handler code here
m_edit.ShowWindow(SW_HIDE);
}