這裏是我的代碼,追加的消息給RichEdit文本框:如何自動下滾一個RichEdit的文本框的Win32 C/C++
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文本框給createWindow:
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);
後我追加的代碼,因爲這是別人的解決方案,但對我沒有工作