mfc 一个关于焦点的问题
代码如下:但主要是m_richedit.GetFocus()==(CWnd*)m_richedit.m_hWnd这一句判断,我的焦点已经定位在RichEdit中了,但是这...
代码如下:
但主要是 m_richedit.GetFocus() == (CWnd*)m_richedit.m_hWnd 这一句判断,
我的焦点已经定位在RichEdit中了,但是这句返回的还是false请问谁知道呢?
是因为我在单击Button2时焦点已经改变了吗?但是这样我在下面的函数前加了
m_richedit.setfocus(),结果还是一样,请问为什么呢?
void Cmian2Dlg::OnBnClickedButton2()
{
if(m_richedit.GetFocus() == (CWnd*)m_richedit.m_hWnd)
{
CString str;
str = m_richedit.GetSelText();
long int start = 0, end = 0;
m_richedit.GetSel(start, end);
if(start != end)
{
this->MessageBoxW(_T("你所选择的是:") + str);
long int start = 0, end = 0;
m_richedit.GetSel(start, end);
m_richedit.SetFocus();
m_richedit.SetSel(start,end);
}
else
{
int y = (m_richedit.GetCaretPos()).y;
int x = (m_richedit.GetCaretPos()).x;
str.Format(_T("%d,%d"),x, y);
this->MessageBoxW(str);
m_richedit.SetFocus();
m_richedit.SetCaretPos(CPoint(x,y));
m_richedit.ShowCaret();
}
}
else
{
this->MessageBoxW(_T("焦点不在RichEdit内。"));
}
// TODO: 在此添加控件通知处理程序代码
} 展开
但主要是 m_richedit.GetFocus() == (CWnd*)m_richedit.m_hWnd 这一句判断,
我的焦点已经定位在RichEdit中了,但是这句返回的还是false请问谁知道呢?
是因为我在单击Button2时焦点已经改变了吗?但是这样我在下面的函数前加了
m_richedit.setfocus(),结果还是一样,请问为什么呢?
void Cmian2Dlg::OnBnClickedButton2()
{
if(m_richedit.GetFocus() == (CWnd*)m_richedit.m_hWnd)
{
CString str;
str = m_richedit.GetSelText();
long int start = 0, end = 0;
m_richedit.GetSel(start, end);
if(start != end)
{
this->MessageBoxW(_T("你所选择的是:") + str);
long int start = 0, end = 0;
m_richedit.GetSel(start, end);
m_richedit.SetFocus();
m_richedit.SetSel(start,end);
}
else
{
int y = (m_richedit.GetCaretPos()).y;
int x = (m_richedit.GetCaretPos()).x;
str.Format(_T("%d,%d"),x, y);
this->MessageBoxW(str);
m_richedit.SetFocus();
m_richedit.SetCaretPos(CPoint(x,y));
m_richedit.ShowCaret();
}
}
else
{
this->MessageBoxW(_T("焦点不在RichEdit内。"));
}
// TODO: 在此添加控件通知处理程序代码
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询