在 MFC 应用程序CEdit
中,对话控件是子类化的。另一个对话框上有一个数字键盘,应该将值发送到该文本框。如果文本在编辑控件上突出显示,则该GetSel
方法返回突出显示文本的开始和结束索引,这将替换为来自键盘的值。这工作正常。
现在,如果子类CEdit
成为自定义控件的一部分,则组合框CComboBox
控件GetSel
上的方法CEdit
始终返回 0。
我似乎没有意识到原因和解决方案是什么。并会感谢任何帮助。谢谢。
更新:
这是一段试图获取突出显示的文本的代码
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;
}
}
该组合的子类如下:
BOOL CSymbolDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//combo is CCustomComboBox type
combo.SubclassDlgItem(IDC_COMBO,this);
//rest of the code...
}
和 CEdit 控件:
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;
}