mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 20:03:01 +08:00
Windows dialogs - Handle scenario when window is not visible yet. (#1662)
* Handle scenario when window is not visible yet. * Handle scenario when window is not visible yet for all dialogs
This commit is contained in:
parent
229d36207c
commit
a229e04e3e
@ -5,11 +5,19 @@ package windows
|
||||
|
||||
import (
|
||||
"github.com/wailsapp/wails/v2/internal/frontend"
|
||||
"github.com/wailsapp/wails/v2/internal/frontend/desktop/windows/winc/w32"
|
||||
"github.com/wailsapp/wails/v2/internal/go-common-file-dialog/cfd"
|
||||
"golang.org/x/sys/windows"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func (f *Frontend) getHandleForDialog() w32.HWND {
|
||||
if f.mainWindow.IsVisible() {
|
||||
return f.mainWindow.Handle()
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// OpenDirectoryDialog prompts the user to select a directory
|
||||
func (f *Frontend) OpenDirectoryDialog(options frontend.OpenDialogOptions) (string, error) {
|
||||
config := cfd.DialogConfig{
|
||||
@ -21,7 +29,7 @@ func (f *Frontend) OpenDirectoryDialog(options frontend.OpenDialogOptions) (stri
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
thisDialog.SetParentWindowHandle(f.mainWindow.Handle())
|
||||
thisDialog.SetParentWindowHandle(f.getHandleForDialog())
|
||||
defer func(thisDialog cfd.SelectFolderDialog) {
|
||||
err := thisDialog.Release()
|
||||
if err != nil {
|
||||
@ -47,7 +55,7 @@ func (f *Frontend) OpenFileDialog(options frontend.OpenDialogOptions) (string, e
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
thisdialog.SetParentWindowHandle(f.mainWindow.Handle())
|
||||
thisdialog.SetParentWindowHandle(f.getHandleForDialog())
|
||||
defer func(thisdialog cfd.OpenFileDialog) {
|
||||
err := thisdialog.Release()
|
||||
if err != nil {
|
||||
@ -74,7 +82,7 @@ func (f *Frontend) OpenMultipleFilesDialog(dialogOptions frontend.OpenDialogOpti
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
thisdialog.SetParentWindowHandle(f.mainWindow.Handle())
|
||||
thisdialog.SetParentWindowHandle(f.getHandleForDialog())
|
||||
defer func(thisdialog cfd.OpenMultipleFilesDialog) {
|
||||
err := thisdialog.Release()
|
||||
if err != nil {
|
||||
@ -100,7 +108,7 @@ func (f *Frontend) SaveFileDialog(dialogOptions frontend.SaveDialogOptions) (str
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
saveDialog.SetParentWindowHandle(f.mainWindow.Handle())
|
||||
saveDialog.SetParentWindowHandle(f.getHandleForDialog())
|
||||
err = saveDialog.Show()
|
||||
if err != nil {
|
||||
return "", err
|
||||
@ -135,7 +143,7 @@ func (f *Frontend) MessageDialog(options frontend.MessageDialogOptions) (string,
|
||||
flags = windows.MB_OK | windows.MB_ICONWARNING
|
||||
}
|
||||
|
||||
button, _ := windows.MessageBox(windows.HWND(f.mainWindow.Handle()), message, title, flags|windows.MB_SYSTEMMODAL)
|
||||
button, _ := windows.MessageBox(windows.HWND(f.getHandleForDialog()), message, title, flags|windows.MB_SYSTEMMODAL)
|
||||
// This maps MessageBox return values to strings
|
||||
responses := []string{"", "Ok", "Cancel", "Abort", "Retry", "Ignore", "Yes", "No", "", "", "Try Again", "Continue"}
|
||||
result := "Error"
|
||||
|
@ -18,6 +18,7 @@ var (
|
||||
procSetClassLong = moduser32.NewProc("SetClassLongW")
|
||||
procSetClassLongPtr = moduser32.NewProc("SetClassLongPtrW")
|
||||
procShowWindow = moduser32.NewProc("ShowWindow")
|
||||
procIsWindowVisible = moduser32.NewProc("IsWindowVisible")
|
||||
)
|
||||
var (
|
||||
moddwmapi = syscall.NewLazyDLL("dwmapi.dll")
|
||||
|
@ -78,6 +78,11 @@ func ExtendFrameIntoClientArea(hwnd uintptr) {
|
||||
}
|
||||
}
|
||||
|
||||
func IsVisible(hwnd uintptr) bool {
|
||||
ret, _, _ := procIsWindowVisible.Call(hwnd)
|
||||
return ret != 0
|
||||
}
|
||||
|
||||
func IsWindowMaximised(hwnd uintptr) bool {
|
||||
style := uint32(getWindowLong(hwnd, GWL_STYLE))
|
||||
return style&WS_MAXIMIZE != 0
|
||||
|
@ -30,8 +30,8 @@ type Window struct {
|
||||
theme winoptions.Theme
|
||||
themeChanged bool
|
||||
|
||||
OnSuspend func()
|
||||
OnResume func()
|
||||
OnSuspend func()
|
||||
OnResume func()
|
||||
}
|
||||
|
||||
func NewWindow(parent winc.Controller, appoptions *options.App, versionInfo *operatingsystem.WindowsVersionInfo) *Window {
|
||||
@ -158,6 +158,10 @@ func (w *Window) SetMaxSize(maxWidth int, maxHeight int) {
|
||||
w.Form.SetMaxSize(maxWidth, maxHeight)
|
||||
}
|
||||
|
||||
func (w *Window) IsVisible() bool {
|
||||
return win32.IsVisible(w.Handle())
|
||||
}
|
||||
|
||||
func (w *Window) WndProc(msg uint32, wparam, lparam uintptr) uintptr {
|
||||
|
||||
switch msg {
|
||||
|
Loading…
Reference in New Issue
Block a user