【问题标题】:how to auto scrolldown a richedit textbox win32 c/c++如何自动向下滚动richedit文本框win32 c/c++
【发布时间】:2016-04-10 16:35:13
【问题描述】:

这是我将消息附加到 Richedit 文本框的代码:

CHARFORMAT cf;
memset( &cf, 0, sizeof cf );
cf.cbSize = sizeof cf;
cf.dwMask = CFM_COLOR;
if (getuserofmessage(msg) == myname)
cf.crTextColor = RGB(0,0,255);// <----- the color of the text
else if (getuserofmessage(msg) == "admin")
cf.crTextColor = RGB(255,0,0);// <----- the color of the text
else
cf.crTextColor = RGB(55,200,100);// <----- the color of the text

SendMessage( hwnd , EM_SETCHARFORMAT, (LPARAM)SCF_SELECTION, (LPARAM) &cf);

/*SendMessage(hwnd, EM_SETSEL, 0, -1); 
    SendMessage(hwnd, EM_SETSEL, -1, -1); 
     SendMessage(hwnd, EM_REPLACESEL, 0, (LPARAM)msg.c_str());*/
     CHARRANGE cr;
cr.cpMin = -1;
cr.cpMax = -1;

// hwnd = rich edit hwnd
SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&cr);
SendMessage(hwnd, EM_REPLACESEL, 0, (LPARAM)msg.c_str());

这里是 Richedit 文本框的创建窗口:

hwnd=CreateWindowEx(WS_EX_CLIENTEDGE, RICHEDIT_CLASS, "",                   
ES_READONLY | WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL,
x,
y,
w,
h,
parent,
(HMENU)identifier,
GetModuleHandle(NULL),
NULL);

但是当文本框中的消息变得非常适合它时,它不会自动向下滚动,从而迫使用户必须不断向下滚动。面临此问题的所有其他引用都在 .NET 或 c# 中。我不能在追加后以某种方式将光标设置到文本框的底部吗?或类似的东西。任何帮助表示赞赏。谢谢。

编辑: 我尝试添加:

DWORD TextSize;
TextSize=GetWindowTextLength(hwnd);
SendMessage(hwnd,EM_SETSEL,TextSize,TextSize);
SendMessage(hwnd,EM_SCROLLCARET,0,0);

在我的附加代码之后,因为这是其他人的解决方案,但对我不起作用

【问题讨论】:

    标签: c++ c textbox richedit richedit-control


    【解决方案1】:

    在插入文本之前,
    int start_lines, end_lines; start_lines = SendMessage(hwnd, EM_GETLINECOUNT,0,0);

    插入文本后,
    end_lines = SendMessage(hwnd, EM_GETLINECOUNT,0,0); SendMessage(hwnd, EM_LINESCROLL, 0, end_lines - start_lines);

    【讨论】:

      【解决方案2】:

      SendMessage(hwnd, WM_VSCROLL, SB_BOTTOM, 0L);

      插入文本后最适合我。

      【讨论】:

        【解决方案3】:

        delphi 试试这个。

        SendMessage(RichEdit1.Handle, WM_VSCROLL, SB_BOTTOM, 0);
        

        【讨论】:

          猜你喜欢
          • 2012-03-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-01-22
          相关资源
          最近更新 更多