Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Hide black console window at application start. #246

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions systray_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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 = &notifyIconData{
Expand Down