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)))