fix: 使用WM_GETTEXTLENGTH获取末尾位置插入日志, 避免点击中间位置导致日志乱序

This commit is contained in:
ShenQiLun 2026-06-30 11:49:18 +08:00
parent f7efcc5378
commit de576330bb

View File

@ -36,6 +36,7 @@ const (
WM_CTLCOLOREDIT = 0x0133 WM_CTLCOLOREDIT = 0x0133
EM_SETSEL = 0x00B1 EM_SETSEL = 0x00B1
EM_REPLACESEL = 0x00C2 EM_REPLACESEL = 0x00C2
WM_GETTEXTLENGTH = 0x000E
SW_SHOW = 5 SW_SHOW = 5
IDC_ARROW = 32512 IDC_ARROW = 32512
@ -186,8 +187,9 @@ func appendText(text string) {
if hWndEdit == 0 { if hWndEdit == 0 {
return return
} }
// 光标移到末尾 // 获取文本长度,将光标移到末尾(避免鼠标点击中间位置导致日志插入到光标处)
pSendMessageW.Call(hWndEdit, EM_SETSEL, ^uintptr(0), ^uintptr(0)) textLen, _, _ := pSendMessageW.Call(hWndEdit, WM_GETTEXTLENGTH, 0, 0)
pSendMessageW.Call(hWndEdit, EM_SETSEL, textLen, textLen)
// 插入文本 // 插入文本
ptr, _ := syscall.UTF16PtrFromString(text) ptr, _ := syscall.UTF16PtrFromString(text)
pSendMessageW.Call(hWndEdit, EM_REPLACESEL, 1, uintptr(unsafe.Pointer(ptr))) pSendMessageW.Call(hWndEdit, EM_REPLACESEL, 1, uintptr(unsafe.Pointer(ptr)))