Comments (4)
The problem is that you're making a mess with DestroyWindow
and WmDestroy
. But in order to better understand and control what's going on, I divided your program into 3 files: main.go
, WndMain.go
and WndModal.go
. Each one takes care of 1 thing.
- Program entry point:
main.go
package main
import (
"runtime"
)
func main() {
runtime.LockOSThread()
mainWindow := NewWndMain()
mainWindow.Run()
}
- Main window:
WndMain.go
package main
import (
"github.com/rodrigocfd/windigo/ui"
"github.com/rodrigocfd/windigo/win"
)
// WndMain is the main application window.
type WndMain struct {
wnd ui.WindowMain
btnOpen ui.Button
}
// WndMain constructor.
func NewWndMain() *WndMain {
wnd := ui.NewWindowMain(
ui.WindowMainOpts().
Title("Test").
ClientArea(win.SIZE{Cx: 800, Cy: 600}),
)
mainWindow := &WndMain{
wnd: wnd,
btnOpen: ui.NewButton(
wnd,
ui.ButtonOpts().
Position(win.POINT{X: 10, Y: 10}).
Size(win.SIZE{Cx: 300, Cy: 300}).
Text("Open Modal"),
),
}
mainWindow.events()
return mainWindow
}
// WndMain will run.
func (me *WndMain) Run() {
me.wnd.RunAsMain()
}
// WndMain events are attached here.
func (me *WndMain) events() {
me.btnOpen.On().BnClicked(func() {
modal := NewWndModal()
modal.Show(me.wnd)
})
}
- Modal window:
WndModal.go
package main
import (
"github.com/rodrigocfd/windigo/ui"
"github.com/rodrigocfd/windigo/win"
"github.com/rodrigocfd/windigo/win/co"
)
// WndModal is the modal window, opened by WndMain.
type WndModal struct {
wnd ui.WindowModal
btnClose ui.Button
edit ui.Edit
}
// WndModal constructor.
func NewWndModal() *WndModal {
wnd := ui.NewWindowModal(
ui.WindowModalOpts().
Title("Modal").
ClientArea(win.SIZE{Cx: 300, Cy: 300}),
)
modalWindow := &WndModal{
wnd: wnd,
btnClose: ui.NewButton(
wnd,
ui.ButtonOpts().
Position(win.POINT{X: 10, Y: 10}).
Size(win.SIZE{Cx: 100, Cy: 30}).
Text("Close"),
),
edit: ui.NewEdit(
wnd,
ui.EditOpts().
Position(win.POINT{X: 10, Y: 50}).
Size(win.SIZE{Cx: 280, Cy: 20}).
Text("Hello, world!"),
),
}
modalWindow.events()
return modalWindow
}
// WndModal will be shown; blocks until the modal is closed.
func (me *WndModal) Show(parent ui.AnyParent) {
me.wnd.ShowModal(parent)
}
// WndModal events are attached here.
func (me *WndModal) events() {
me.btnClose.On().BnClicked(func() {
me.wnd.Hwnd().SendMessage(co.WM_CLOSE, 0, 0)
})
}
Although longer, such code structure is much more scalable, allowing your program to grow in complexity while being maintainable.
from windigo.
Thanks for the advise.
Sorry for asking questions, but why this code not works? I think the message box should appear after modal closed, but It doesn't appear.
// WndMain events are attached here.
func (me *WndMain) events() {
me.btnOpen.On().BnClicked(func() {
modal := NewWndModal()
modal.Show(me.wnd)
me.wnd.Hwnd().MessageBox("Modal closed.", "Test", co.MB_ICONINFORMATION)
})
}
from windigo.
This time you found a bug. The modal loop was not being terminated correctly in some cases. It's fixed now, thank you.
from windigo.
Thanks! I confirm this issue resolved.
from windigo.
Related Issues (20)
- The specified resource type cannot be found in the image file. HOT 5
- How to hide console window? HOT 2
- Any plan to support Mac OS? HOT 2
- [Feature] DDE support/bindings HOT 13
- System tray example? HOT 1
- Any more Golang examples? HOT 1
- Can't get WM_KEYDOWN event when button focused HOT 8
- "Cannot add event handling after the window is created" error when trying to add button to visible window HOT 2
- LVM_SETITEMSTATE failed when pressing Ctrl-A to co.LVS_SINGLESEL flagged ListView HOT 2
- MapViewOfFile fails when arch is 386 HOT 12
- Compiling, resource syso workarounds? HOT 3
- How to add List Column to ListView? HOT 2
- How to create Tabs? HOT 3
- Up-Down Control HOT 1
- README example fails to run on WINE HOT 1
- How to create a transparent Window ?
- How to I enable "clickthrough" in windigo?
- How to set environment variables in `CreateProcess`?
- Documentation? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from windigo.