diff --git a/common.go b/common.go index 5c4bad3..61e845a 100644 --- a/common.go +++ b/common.go @@ -81,4 +81,11 @@ type WebView interface { // f must be a function // f must return either value and error or just error Bind(name string, f interface{}) error + + // Show shows the native window if hidden. + // It will also restore a minimized window. + Show() + + // Hide hides the native window from the screen and taskbar. + Hide() } diff --git a/internal/w32/w32.go b/internal/w32/w32.go index e76f894..87ffcb9 100644 --- a/internal/w32/w32.go +++ b/internal/w32/w32.go @@ -44,6 +44,7 @@ var ( User32SetWindowPos = user32.NewProc("SetWindowPos") User32IsDialogMessage = user32.NewProc("IsDialogMessage") User32GetAncestor = user32.NewProc("GetAncestor") + User32IsIconic = user32.NewProc("IsIconic") ) const ( @@ -73,7 +74,9 @@ const ( ) const ( - SWShow = 5 + SWHide = 0 + SWShow = 5 + SWRestore = 9 ) const ( diff --git a/webview.go b/webview.go index 8f35aec..cf39c88 100644 --- a/webview.go +++ b/webview.go @@ -44,6 +44,7 @@ type browser interface { Eval(script string) NotifyParentWindowPositionChanged() error Focus() + Show() error } type webview struct { @@ -59,11 +60,12 @@ type webview struct { } type WindowOptions struct { - Title string - Width uint - Height uint - IconId uint - Center bool + Title string + Width uint + Height uint + IconId uint + Center bool + StartHidden bool } type WebViewOptions struct { @@ -333,7 +335,6 @@ func (w *webview) CreateWithOptions(opts WindowOptions) bool { ) setWindowContext(w.hwnd, w) - _, _, _ = w32.User32ShowWindow.Call(w.hwnd, w32.SWShow) _, _, _ = w32.User32UpdateWindow.Call(w.hwnd) _, _, _ = w32.User32SetFocus.Call(w.hwnd) @@ -341,9 +342,30 @@ func (w *webview) CreateWithOptions(opts WindowOptions) bool { return false } w.browser.Resize() + if !opts.StartHidden { + _, _, _ = w32.User32ShowWindow.Call(w.hwnd, w32.SWShow) + _ = w.browser.Show() + } return true } +func (w *webview) Hide() { + _, _, _ = w32.User32ShowWindow.Call(w.hwnd, w32.SWHide) +} + +func (w *webview) Show() { + ret, _, _ := w32.User32IsIconic.Call(w.hwnd) + isMinimized := ret != 0 + + if isMinimized { + _, _, _ = w32.User32ShowWindow.Call(w.hwnd, w32.SWRestore) + } else { + _, _, _ = w32.User32ShowWindow.Call(w.hwnd, w32.SWShow) + } + + _ = w.browser.Show() +} + func (w *webview) Destroy() { _, _, _ = w32.User32PostMessageW.Call(w.hwnd, w32.WMClose, 0, 0) }