Document title/path truncation behavior in Win32 binding
This commit is contained in:
@@ -27,6 +27,7 @@ func ForegroundWindow() (hwnd uintptr, title, class string, ok bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func windowTitle(h windows.HWND) string {
|
func windowTitle(h windows.HWND) string {
|
||||||
|
// 512 uint16s; titles over 511 chars are truncated — acceptable for a sensor tag.
|
||||||
const max = 512
|
const max = 512
|
||||||
buf := make([]uint16, max)
|
buf := make([]uint16, max)
|
||||||
n, _, _ := procGetWindowTextW.Call(
|
n, _, _ := procGetWindowTextW.Call(
|
||||||
@@ -34,6 +35,7 @@ func windowTitle(h windows.HWND) string {
|
|||||||
uintptr(unsafe.Pointer(&buf[0])),
|
uintptr(unsafe.Pointer(&buf[0])),
|
||||||
uintptr(max),
|
uintptr(max),
|
||||||
)
|
)
|
||||||
|
// n==0 covers both call failure and a genuinely empty title; both are fine here.
|
||||||
return windows.UTF16ToString(buf[:n])
|
return windows.UTF16ToString(buf[:n])
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,6 +52,8 @@ func windowClass(h windows.HWND) string {
|
|||||||
|
|
||||||
buf := make([]uint16, windows.MAX_PATH)
|
buf := make([]uint16, windows.MAX_PATH)
|
||||||
size := uint32(len(buf))
|
size := uint32(len(buf))
|
||||||
|
// MAX_PATH suffices for almost all paths; an over-long path fails here and
|
||||||
|
// degrades windowClass to "" (window left unclassified), never a crash.
|
||||||
if err := windows.QueryFullProcessImageName(proc, 0, &buf[0], &size); err != nil {
|
if err := windows.QueryFullProcessImageName(proc, 0, &buf[0], &size); err != nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user