mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 19:50:15 +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 (
|
import (
|
||||||
"github.com/wailsapp/wails/v2/internal/frontend"
|
"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"
|
"github.com/wailsapp/wails/v2/internal/go-common-file-dialog/cfd"
|
||||||
"golang.org/x/sys/windows"
|
"golang.org/x/sys/windows"
|
||||||
"syscall"
|
"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
|
// OpenDirectoryDialog prompts the user to select a directory
|
||||||
func (f *Frontend) OpenDirectoryDialog(options frontend.OpenDialogOptions) (string, error) {
|
func (f *Frontend) OpenDirectoryDialog(options frontend.OpenDialogOptions) (string, error) {
|
||||||
config := cfd.DialogConfig{
|
config := cfd.DialogConfig{
|
||||||
@ -21,7 +29,7 @@ func (f *Frontend) OpenDirectoryDialog(options frontend.OpenDialogOptions) (stri
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
thisDialog.SetParentWindowHandle(f.mainWindow.Handle())
|
thisDialog.SetParentWindowHandle(f.getHandleForDialog())
|
||||||
defer func(thisDialog cfd.SelectFolderDialog) {
|
defer func(thisDialog cfd.SelectFolderDialog) {
|
||||||
err := thisDialog.Release()
|
err := thisDialog.Release()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -47,7 +55,7 @@ func (f *Frontend) OpenFileDialog(options frontend.OpenDialogOptions) (string, e
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
thisdialog.SetParentWindowHandle(f.mainWindow.Handle())
|
thisdialog.SetParentWindowHandle(f.getHandleForDialog())
|
||||||
defer func(thisdialog cfd.OpenFileDialog) {
|
defer func(thisdialog cfd.OpenFileDialog) {
|
||||||
err := thisdialog.Release()
|
err := thisdialog.Release()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -74,7 +82,7 @@ func (f *Frontend) OpenMultipleFilesDialog(dialogOptions frontend.OpenDialogOpti
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
thisdialog.SetParentWindowHandle(f.mainWindow.Handle())
|
thisdialog.SetParentWindowHandle(f.getHandleForDialog())
|
||||||
defer func(thisdialog cfd.OpenMultipleFilesDialog) {
|
defer func(thisdialog cfd.OpenMultipleFilesDialog) {
|
||||||
err := thisdialog.Release()
|
err := thisdialog.Release()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -100,7 +108,7 @@ func (f *Frontend) SaveFileDialog(dialogOptions frontend.SaveDialogOptions) (str
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
saveDialog.SetParentWindowHandle(f.mainWindow.Handle())
|
saveDialog.SetParentWindowHandle(f.getHandleForDialog())
|
||||||
err = saveDialog.Show()
|
err = saveDialog.Show()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -135,7 +143,7 @@ func (f *Frontend) MessageDialog(options frontend.MessageDialogOptions) (string,
|
|||||||
flags = windows.MB_OK | windows.MB_ICONWARNING
|
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
|
// This maps MessageBox return values to strings
|
||||||
responses := []string{"", "Ok", "Cancel", "Abort", "Retry", "Ignore", "Yes", "No", "", "", "Try Again", "Continue"}
|
responses := []string{"", "Ok", "Cancel", "Abort", "Retry", "Ignore", "Yes", "No", "", "", "Try Again", "Continue"}
|
||||||
result := "Error"
|
result := "Error"
|
||||||
|
@ -18,6 +18,7 @@ var (
|
|||||||
procSetClassLong = moduser32.NewProc("SetClassLongW")
|
procSetClassLong = moduser32.NewProc("SetClassLongW")
|
||||||
procSetClassLongPtr = moduser32.NewProc("SetClassLongPtrW")
|
procSetClassLongPtr = moduser32.NewProc("SetClassLongPtrW")
|
||||||
procShowWindow = moduser32.NewProc("ShowWindow")
|
procShowWindow = moduser32.NewProc("ShowWindow")
|
||||||
|
procIsWindowVisible = moduser32.NewProc("IsWindowVisible")
|
||||||
)
|
)
|
||||||
var (
|
var (
|
||||||
moddwmapi = syscall.NewLazyDLL("dwmapi.dll")
|
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 {
|
func IsWindowMaximised(hwnd uintptr) bool {
|
||||||
style := uint32(getWindowLong(hwnd, GWL_STYLE))
|
style := uint32(getWindowLong(hwnd, GWL_STYLE))
|
||||||
return style&WS_MAXIMIZE != 0
|
return style&WS_MAXIMIZE != 0
|
||||||
|
@ -30,8 +30,8 @@ type Window struct {
|
|||||||
theme winoptions.Theme
|
theme winoptions.Theme
|
||||||
themeChanged bool
|
themeChanged bool
|
||||||
|
|
||||||
OnSuspend func()
|
OnSuspend func()
|
||||||
OnResume func()
|
OnResume func()
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWindow(parent winc.Controller, appoptions *options.App, versionInfo *operatingsystem.WindowsVersionInfo) *Window {
|
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)
|
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 {
|
func (w *Window) WndProc(msg uint32, wparam, lparam uintptr) uintptr {
|
||||||
|
|
||||||
switch msg {
|
switch msg {
|
||||||
|
Loading…
Reference in New Issue
Block a user