Go进程改标题

朴实无华。(置顶的文章被jianshu删了,笑死)

import (
    "syscall"
    "unsafe"
)

func SetConsoleTitleW(title string) {
    kernel32, err := syscall.LoadLibrary(`kernel32.dll`)
    if err != nil {
        return
    }

    if sct, err := syscall.GetProcAddress(kernel32, `SetConsoleTitleW`); err == nil {
        if pu, err := syscall.UTF16PtrFromString(title); err == nil {
            _, _, _ = syscall.Syscall(sct, 1, uintptr(unsafe.Pointer(pu)), 0, 0)
        }
    }

    _ = syscall.FreeLibrary(kernel32)
}

你可能感兴趣的:(Go进程改标题)