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

Creating a modal window #626

Open
mar1ged opened this issue Sep 26, 2019 · 8 comments
Open

Creating a modal window #626

mar1ged opened this issue Sep 26, 2019 · 8 comments

Comments

@mar1ged
Copy link

mar1ged commented Sep 26, 2019

I need to create a window that can not be put into the background and stays on top of all windows until I close it after a certain button has been clicked.
Normally such behavior is not good style but in this case it is necessary to make sure that I have the full attention of the user because the information displayed in the window is of type "stop the world".
From what I know this would be "modal" or "system modal" but didn't find a way to create such a window with walk.
Is this possible ? It wouldn't matter which API of walk enables me to do this.

@lxn
Copy link
Owner

lxn commented Oct 1, 2019

You may want to try SetWindowPos from the win package with HWND_TOPMOST for hWndInsertAfter.

@mar1ged
Copy link
Author

mar1ged commented Oct 1, 2019

I tried to follow your suggestion, took the test.go from the readme and attempted to add the SetWindowPos you mentioned. Probably this is due to my limited experience with Go, but I failed to get access to mw.hWnd.
Can you give me one more hint ?

@lpintes
Copy link

lpintes commented Oct 2, 2019

Use mw.Handle()

@mar1ged
Copy link
Author

mar1ged commented Oct 2, 2019

@lpintes Thanks for your suggestion, but are you sure ? I can't find Handle() in MainWindow.

w := MainWindow{
Title:   "SCREAMO",
...

grafik

@lpintes
Copy link

lpintes commented Oct 2, 2019

Hello,
Do the following:
Declare the variable of the walk.MainWindow type

var mw walk.MainWindow

Then in window declaration, in the MainWindow { ... }, add a line
AssignTo: &mw,

Then later in the code you can use mw.Handle().

@mar1ged
Copy link
Author

mar1ged commented Oct 2, 2019

@lpintes Thanks again, I'm getting closer.

I defined the variable like this (without * the compiler complained):
var mw *walk.MainWindow

When the Run() returns (for which I have to close the window) mw is no longer <nil> but 0 which is because after closing the original Handle() is lost and thus set to 0.
I guess I need to call Run() in a goroutine, but how can I know that walk opened the window and finished setting the handle value ?
Is there perhaps a better approach ?

@lxn
Copy link
Owner

lxn commented Oct 3, 2019

You should do it similar to the actions example. Switch from calling Run on the declarative.MainWindow, to Create. Then you can do your custom initialization win.SetWindowPos(mw.Handle(), ...) and after that run the message loop via mw.Run.

@mar1ged
Copy link
Author

mar1ged commented Oct 3, 2019

Thanks to @lxn and @lpintes I came up with this solution (based on actions.go, modifications are shown below):

var mw *walk.MainWindow
...
MainWindow{
    AssignTo: &mw,
    Title:    "SCREAMO",
    ...
    },
}.Create()

win.SetWindowPos(mw.Handle(), win.HWND_TOPMOST, -1, -1, -1, -1, win.SWP_NOMOVE|win.SWP_NOREPOSITION|win.SWP_NOSIZE)
mw.Run()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants