How to hide the Go console window in Windows

I tried various ways to create a Go program that only displays a MessageBox or a standalone GUI window. If I wrote this in C / C ++, I would just define WinMain , leave the main one, and it would be nice to go. It seems to me that as soon as I define the main function, the console window is created automatically. And the main function is required.

 package main func main() { ... } 

To avoid this, I tried an example that creates WinMain

 func WinMain(wproc uintptr) { hInstance := GetModuleHandle(nil) ... } 

But the effect is the same: an empty console window and a GUI window: enter image description here

+5
source share
1 answer

Add -ldflags -H=windowsgui to your go build / install command line. You will see that the console window is missing:

enter image description here

+7
source

Source: https://habr.com/ru/post/1247466/


All Articles