hidden_windows.go 658 B

1234567891011121314151617181920212223
  1. // Copyright (C) 2014 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. //go:build windows
  7. // +build windows
  8. package osutil
  9. import "syscall"
  10. func HideConsole() {
  11. getConsoleWindow := syscall.NewLazyDLL("kernel32.dll").NewProc("GetConsoleWindow")
  12. showWindow := syscall.NewLazyDLL("user32.dll").NewProc("ShowWindow")
  13. if getConsoleWindow.Find() == nil && showWindow.Find() == nil {
  14. hwnd, _, _ := getConsoleWindow.Call()
  15. if hwnd != 0 {
  16. showWindow.Call(hwnd, 0)
  17. }
  18. }
  19. }