On a MFC application a CEdit
control of a dialogue is subclassed. There is a numerical keypad on another dialogue which is supposed to send values to that text box. If the text is highlighted on the edit control the GetSel
method returns the start and end index of the highlighted text and this will be replaced with the value comes from the keypad. This works fine.
Now if the the subclassed CEdit
become a part of a custom CComboBox
control the GetSel
method on the CEdit
control of combobox always returns 0.
I don't seem to realize what the reason and solution is. And would appreciate any help. Thanks.
Update:
Here is the piece of code that tries to get the highlighted text
BOOL CBaseDialog::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN && pMsg->lParam == 2)
{
switch (pMsg->wParam)
{
case VK_TAB:
//NextDialogCtrl();
break;
case 'ret':
//keybd_event(VK_RETURN, 0, 0, 0);
return FALSE;
case '?':
break;
default:
if (m_LastFocused >= 0)
{
CWnd* pwnd = GetDlgItem(m_LastFocused);
if (pwnd->IsKindOf(RUNTIME_CLASS(CComboBox)) )
{
CCustomComboBox* ctl = (CCustomComboBox*)pwnd;
//this method always returns 0 index for the
//start and end position index
ctl->m_edit->GetSel(m_LastStPos, m_LastEndPos);
}
}
} break;
}
}
The combo is subclassed like this:
BOOL CSymbolDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//combo is CCustomComboBox type
combo.SubclassDlgItem(IDC_COMBO,this);
//rest of the code...
}
And the CEdit control:
HBRUSH CCustomComboBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
if (nCtlColor == CTLCOLOR_EDIT)
{
//[ASCII 160][ASCII 160][ASCII 160]Edit control
if (m_edit.GetSafeHwnd() == NULL)
m_edit.SubclassWindow(pWnd->GetSafeHwnd());
}
else if (nCtlColor == CTLCOLOR_LISTBOX)
{
//ListBox control
if (m_listbox.GetSafeHwnd() == NULL)
m_listbox.SubclassWindow(pWnd->GetSafeHwnd());
}
HBRUSH hbr = CComboBox::OnCtlColor(pDC, pWnd, nCtlColor);
return hbr;
}