hidden_windows.go 639 B

12345678910111213141516171819202122
  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. // +build windows
  7. package osutil
  8. import "syscall"
  9. func HideConsole() {
  10. getConsoleWindow := syscall.NewLazyDLL("kernel32.dll").NewProc("GetConsoleWindow")
  11. showWindow := syscall.NewLazyDLL("user32.dll").NewProc("ShowWindow")
  12. if getConsoleWindow.Find() == nil && showWindow.Find() == nil {
  13. hwnd, _, _ := getConsoleWindow.Call()
  14. if hwnd != 0 {
  15. showWindow.Call(hwnd, 0)
  16. }
  17. }
  18. }