forked from Hakkin/twitchpipe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hide_windows.go
50 lines (40 loc) · 947 Bytes
/
hide_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// +build windows
package main
import (
"flag"
"syscall"
"unsafe"
"rsc.io/getopt"
)
var (
user32 = syscall.NewLazyDLL("user32.dll")
kernel32 = syscall.NewLazyDLL("kernel32.dll")
)
var (
getWindowThreadProcessID = user32.NewProc("GetWindowThreadProcessId")
showWindowAsync = user32.NewProc("ShowWindowAsync")
getConsoleWindow = kernel32.NewProc("GetConsoleWindow")
getCurrentProcessID = kernel32.NewProc("GetCurrentProcessId")
)
func init() {
flag.BoolVar(&hideConsole, "h", false, "Hide own console window")
getopt.Aliases(
"h", "hide-console",
)
}
func hideWindow() {
console, _, _ := getConsoleWindow.Call()
if console == 0 {
return
}
var consolePID uint32
getWindowThreadProcessID.Call(
console,
uintptr(unsafe.Pointer(&consolePID)),
)
selfPIDPtr, _, _ := getCurrentProcessID.Call()
selfPID := uint32(selfPIDPtr)
if selfPID == consolePID {
showWindowAsync.Call(console, 0)
}
}