CRichEditCtrl阻止在SetSet上自动滚动
CRichEditCtrl prevent auto scroll on SetSel
我有一个继承自CRichEditCtrl的CMyRichEditCtrl类。当我调用SetSel时,它会自动滚动CRichEditCtrl的内容,以便插入符号可见。我想避免这种行为。
困扰我的是,这种行为似乎在6.0和其他版本之间发生了变化。
Visual Studio 2010:http://msdn.microsoft.com/en-us/library/4zek9k1f(v=vs.100).aspx
插入符号放置在由开始(cpMin或nStartChar)和结束(cpMax或nEndChar)索引中较大者指示的选择的末尾此函数滚动CRichEditCtrl的内容,以便插入符号可见
Visual Studio 6.0:http://msdn.microsoft.com/en-us/library/aa313352(v=vs.60).aspx
插入符号放置在由开始(cpMin或nStartChar)和结束(cpMax或nEndChar)索引中较大者指示的选择的末尾此函数不会滚动CRichEditCtrl的内容以使插入符号可见
调用SetSel时,有没有办法防止控件自动滚动?
这不是一个容易的过程,但我终于找到了一个解决方法。
void CMyRichEditCtrl::doStuff()
{
SetRedraw( FALSE );
int nOldFirstVisibleLine = GetFirstVisibleLine();
// Save current selection
long lMinSel, lMaxSel;
GetSel( lMinSel, lMaxSel );
// Do something here
doSomething();
// Restore selection
SetSel( lMinSel, lMaxSel );
// Prevent the auto-scroll of the control when calling SetSel()
int nNewFirstVisibleLine = GetFirstVisibleLine();
if( nOldFirstVisibleLine != nNewFirstVisibleLine )
LineScroll( nOldFirstVisibleLine - nNewFirstVisibleLine );
SetRedraw( TRUE );
RedrawWindow();
}
使用CRichEditCtrl::SetOptions方法或以下代码禁用和启用自动滚动。hwnd是富编辑控件的句柄。
您可以使用以下代码禁用自动滚动:
LRESULT prevOptions = SendMessage(hwnd, EM_GETOPTIONS, 0, 0);
SendMessage(hwnd, EM_SETOPTIONS, ECOOP_SET, prevOptions & ~ECO_AUTOVSCROLL);
并使用启用它
SendMessage(hwnd, EM_SETOPTIONS, ECOOP_SET, prevOptions);
更改为
重新绘制窗口(0,0,RDW_NOERASE);
它更好。
相关文章:
- 使用一个考虑到std::map中键值的滚动或换行的键
- QScrollArea:由垂直滚动条引起的水平滚动条
- 跟踪滚动条上的鼠标事件
- 如何在不使用滚动条的情况下使视图更改
- 如何为对象生成滚动效果?
- 如何模拟不同边数的骰子滚动?
- 如何初始化升压滚动窗口累加器?
- 实现包含多个 QQuickPaintedItems 的 QQuickView 的滚动
- 通过水平滚动条更改标签
- 如何防止 Windows 控制台上的回车键自动滚动
- Qt:无法直接为带有子项的小部件添加滚动条
- OnVScroll : 从 CSpinButtonCtrl 或垂直滚动条调用?
- win32 滚动条在 C/C++ 程序中不起作用
- 为什么玩家控制器"own"偏航俯仰和滚动,但角色"owns"它的位置?
- 外观 MFC 滚动条
- 我在QChartView中找不到缩放图形的鼠标滚轮滚动事件
- 如何使用C++获取/设置OBS中的垂直滚动过滤器属性?
- 停止 QTextCursor::insertText() 修改 QTextDocument 滚动条范围
- 如何在控制台应用程序中添加滚动功能以显示更大的输入
- CRichEditCtrl阻止在SetSet上自动滚动