From c21536f0e9ed71e4d28c09ea6754d369c15ce964 Mon Sep 17 00:00:00 2001 From: Yancharuk Alexander Date: Thu, 29 Dec 2022 11:46:28 +0300 Subject: [PATCH] Fix: Hide black console window at application start. Despite that pShowWindow.Call() with SW_HIDE at application init, right after start console window still hangs on. So there is need to get this console handler and minimize it. Exactly this is what this commit does. --- systray_windows.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/systray_windows.go b/systray_windows.go index 6bdc803d..b564efe0 100644 --- a/systray_windows.go +++ b/systray_windows.go @@ -25,8 +25,9 @@ var ( pDeleteDC = g32.NewProc("DeleteDC") pSelectObject = g32.NewProc("SelectObject") - k32 = windows.NewLazySystemDLL("Kernel32.dll") - pGetModuleHandle = k32.NewProc("GetModuleHandleW") + k32 = windows.NewLazySystemDLL("Kernel32.dll") + pGetModuleHandle = k32.NewProc("GetModuleHandleW") + pGetConsoleWindow = k32.NewProc("GetConsoleWindow") s32 = windows.NewLazySystemDLL("Shell32.dll") pShellNotifyIcon = s32.NewProc("Shell_NotifyIconW") @@ -302,6 +303,7 @@ func (t *winTray) initInstance() error { const IDC_ARROW = 32512 // Standard arrow // https://msdn.microsoft.com/en-us/library/windows/desktop/ms633548(v=vs.85).aspx const SW_HIDE = 0 + const SW_SHOWMINIMIZED = 2 const CW_USEDEFAULT = 0x80000000 // https://msdn.microsoft.com/en-us/library/windows/desktop/ms632600(v=vs.85).aspx const ( @@ -416,6 +418,16 @@ func (t *winTray) initInstance() error { uintptr(t.window), ) + cw, _, err := pGetConsoleWindow.Call() + if cw == 0 { + return err + } + + pShowWindow.Call( + uintptr(cw), + uintptr(SW_SHOWMINIMIZED), + ) + t.muNID.Lock() defer t.muNID.Unlock() t.nid = ¬ifyIconData{