C++ 如何在win32 c/c++;
以下是我将消息附加到richedit文本框的代码:C++ 如何在win32 c/c++;,c++,c,textbox,richedit,richedit-control,C++,C,Textbox,Richedit,Richedit Control,以下是我将消息附加到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(ms
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());
但是当文本框中的信息变得非常适合它时,它不会自动向下滚动,这迫使用户必须不断向下滚动。面对这个问题的所有其他引用都在.NET或c#中。我是否可以在追加后将光标设置到文本框的底部?或者类似的。感谢您的帮助。谢谢
编辑:
我试着加上:
DWORD TextSize;
TextSize=GetWindowTextLength(hwnd);
SendMessage(hwnd,EM_SETSEL,TextSize,TextSize);
SendMessage(hwnd,EM_SCROLLCARET,0,0);
在我的附加代码之后,因为这是其他人的解决方案,但在插入文本之前对我不起作用,
int开始线,结束线;
start_lines=SendMessage(hwnd,EM_GETLINECOUNT,0,0)代码>
插入文本后,
end_lines=SendMessage(hwnd,EM_GETLINECOUNT,0,0);
SendMessage(hwnd、EM_行滚动、0、结束_行-开始_行)编码>在插入文本之前,
int开始线,结束线;
start_lines=SendMessage(hwnd,EM_GETLINECOUNT,0,0)代码>
插入文本后,
end_lines=SendMessage(hwnd,EM_GETLINECOUNT,0,0);
SendMessage(hwnd、EM_行滚动、0、结束_行-开始_行)代码>发送消息(hwnd、WM\U VSCROLL、SB\U BOTTOM、0L)代码>
文本插入后对我最合适 发送消息(hwnd、WM\U VSCROLL、SB\U BOTTOM、0L)代码>
文本插入后对我最合适 试试这个
SendMessage(RichEdit1.Handle, WM_VSCROLL, SB_BOTTOM, 0);
试试这个
SendMessage(RichEdit1.Handle, WM_VSCROLL, SB_BOTTOM, 0);