From de576330bb929b4ded335cf96ace527b21a32bba Mon Sep 17 00:00:00 2001 From: ShenQiLun <97694732@qq.com> Date: Tue, 30 Jun 2026 11:49:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BD=BF=E7=94=A8WM=5FGETTEXTLENGTH?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=9C=AB=E5=B0=BE=E4=BD=8D=E7=BD=AE=E6=8F=92?= =?UTF-8?q?=E5=85=A5=E6=97=A5=E5=BF=97,=20=E9=81=BF=E5=85=8D=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E4=B8=AD=E9=97=B4=E4=BD=8D=E7=BD=AE=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E4=B9=B1=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/server/gui_windows.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/server/gui_windows.go b/cmd/server/gui_windows.go index 368853e..35a9777 100644 --- a/cmd/server/gui_windows.go +++ b/cmd/server/gui_windows.go @@ -36,6 +36,7 @@ const ( WM_CTLCOLOREDIT = 0x0133 EM_SETSEL = 0x00B1 EM_REPLACESEL = 0x00C2 + WM_GETTEXTLENGTH = 0x000E SW_SHOW = 5 IDC_ARROW = 32512 @@ -186,8 +187,9 @@ func appendText(text string) { if hWndEdit == 0 { 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) pSendMessageW.Call(hWndEdit, EM_REPLACESEL, 1, uintptr(unsafe.Pointer(ptr)))