github.com/eframework-cn/EP.GO.UTIL@v1.0.0/xos/xos_windows.go (about) 1 //-----------------------------------------------------------------------// 2 // GNU GENERAL PUBLIC LICENSE // 3 // Version 2, June 1991 // 4 // // 5 // Copyright (C) EFramework, https://eframework.cn, All rights reserved. // 6 // Everyone is permitted to copy and distribute verbatim copies // 7 // of this license document, but changing it is not allowed. // 8 // SEE LICENSE.md FOR MORE DETAILS. // 9 //-----------------------------------------------------------------------// 10 11 package xos 12 13 import ( 14 "syscall" 15 "time" 16 "unsafe" 17 18 "github.com/eframework-cn/EP.GO.UTIL/xstring" 19 "github.com/eframework-cn/EP.GO.UTIL/xtime" 20 21 "github.com/lxn/win" 22 "golang.org/x/sys/windows" 23 ) 24 25 var ( 26 libkernel32 *windows.LazyDLL 27 setConsoleTitleW *windows.LazyProc 28 ) 29 30 func init() { 31 libkernel32 = windows.NewLazySystemDLL("kernel32.dll") 32 setConsoleTitleW = libkernel32.NewProc("SetConsoleTitleW") 33 } 34 35 func setConsoleTitleWFunc(name *uint16) { 36 syscall.Syscall(setConsoleTitleW.Addr(), 1, uintptr(unsafe.Pointer(name)), 0, 0) 37 } 38 39 func SetCmdTitle(title string) { 40 if s, e := syscall.UTF16PtrFromString(title); e == nil { 41 setConsoleTitleWFunc(s) 42 } 43 } 44 45 func DisableClose() { 46 title := xstring.Format("ESVR-%v", xtime.GetMicrosecond()) 47 if s, e := syscall.UTF16PtrFromString(title); e == nil { 48 setConsoleTitleWFunc(s) 49 time.Sleep(time.Millisecond * 500) 50 hwnd := win.FindWindow(nil, s) 51 menu := win.GetSystemMenu(hwnd, false) 52 win.RemoveMenu(menu, 0xF060, 0x0) 53 } 54 }