Visual C++ CEdit 控件 - 为什么插入点被 SetWindowText() 改变
以下代码片段来自多行 CEdit 控件的 OnChange() 处理程序,该控件设置了“WantReturn”。
void DLG::OnChangeEditPrepareTape()
{
CString ss;
std::vector<char> aTape;
m_prepareTape.GetWindowText(ss);
m_prepareTape.SetWindowText(ss);
}
如果 SetWindowText() 被注释掉,则用户的文本将在右侧构建,一切都很好。但是,有了它,文本插入点就会移动到左边缘,并且用户的字符会进入现有字符的左侧。
我想在两个调用之间放置一些修补文本,并且可以通过以下方式获得我想要的内容CEdit 的子类化。但我很想知道是否有办法通过 Get() & 来做到这一点放()。
我正在使用 Visual C++ 6,带有 Service Pack 5。现在已有十一年了,但正如他们所说,“软件不会磨损”:-)。
The following snippet is from the OnChange() handler of a multiline CEdit control, which has "WantReturn" set.
void DLG::OnChangeEditPrepareTape()
{
CString ss;
std::vector<char> aTape;
m_prepareTape.GetWindowText(ss);
m_prepareTape.SetWindowText(ss);
}
If the SetWindowText() is commented out, the user’s text builds up on the right, and all is well. But, with it in, the text insertion point moves to the left edge, and the user’s characters go in to the left of the existing characters..
I want to put some tinkering text between the two calls, and can get what I want by subclassing CEdit. But I’d be interested to know if there is a way of doing it by Get() & Set().
I’m using Visual C++ 6, with Service Pack 5. Eleven years old now, but then “Software does not wear out” as they say:-).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
插入点由
SetWindowText()
重置,因为从控件的角度来看,其整个文本内容刚刚被重置(可能重置为空字符串),并且插入点和当前选择都已重置可能没有足够的意义来保留它们。您可以使用 GetSel() 和 SetSel() 自行实现此行为:
The insertion point is reset by
SetWindowText()
because, from the control's point of view, its whole text content has just been reset (possibly to the empty string), and both the insertion point and the current selection might not be meaningful enough to keep them around.You can use GetSel() and SetSel() to implement this behavior yourself:
您可以在替换文本之前使用
GetSel
检索光标位置,然后使用SetSel
将其放置在同一位置。如果您在将文本放回文本框中之前对其进行修改,则可以相应地递增或递减
start
(和end
)。You can you use
GetSel
to retrieve the cursor position before you replace the text, andSetSel
to place it in the same location afterwards.If you modify the text before you put it back in the text box, you can increment or decrement
start
(andend
) accordingly.