Hi,
I want use CRichEditCtrl and CListBox to customization my CRichEditCtrlEx control. This CRichEditCtrlEx control just like IntelliSense of VS IDE.
Now, I has some problems that when key down Return button the CListBox could not auto fill compeleted.
Can you give me some advices or sample code?
Thanks very mush!
What I have tried:
void CRichEditCtrlEx::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if ((nChar == 13))
{
if (0 == (GetKeyState(VK_SHIFT) & 0x8000))
{
if (m_bIsAssistCreated)
{
const string buffer(1024, '\0');
const int index = m_pAssistBox->GetCurSel();
m_pAssistBox->GetText(index, const_cast<lptstr>(buffer.c_str()));
m_pAssistBox->DestroyWindow();
delete m_pAssistBox;
m_pAssistBox = nullptr;
m_bIsAssistCreated = false;
const long nTotalLength = this->GetTextLength();
const int nCurLine = LineFromChar(-1);
const int nLength = LineLength(nCurLine);
this->SetSel(nTotalLength - nLength, nTotalLength);
this->ReplaceSel(buffer.c_str(), TRUE);
this->Invalidate();
return;
}
}
}
else
{
const int nCurLine = LineFromChar(-1);
const int nLength = LineLength(nCurLine);
string buffer(nLength + 2, '\0');
this->GetLine(nCurLine, const_cast<lptstr>(buffer.c_str()), static_cast<int>(buffer.capacity()));
buffer.erase(std::find_if(buffer.begin(), buffer.end(), [](const TCHAR ch) { return ch == '\r'; }), buffer.end());
if (!m_bIsAssistCreated && !buffer.empty())
{
for (const auto item : m_vecSourceData)
{
if (string::npos != string(item).find(buffer))
{
m_pAssistBox = new CAssistBox();
m_pAssistBox->SetSource(m_vecSourceData);
const CSize size = GetStringSize(buffer.c_str());
CPoint pt = GetCaretPos();
pt.Offset(-size.cx + 2, 20);
m_pAssistBox->Create(this, pt);
m_pAssistBox->AutoSelect(buffer.c_str());
m_bIsAssistCreated = true;
break;
}
}
}
else
{
if (m_bIsAssistCreated)
{
if (!m_pAssistBox->AutoSelect(buffer.c_str()))
{
m_pAssistBox->DestroyWindow();
delete m_pAssistBox;
m_pAssistBox = nullptr;
m_bIsAssistCreated = false;
Invalidate();
}
}
}
}
CRichEditCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
}