lxn / walk

A Windows GUI toolkit for the Go Programming Language
Other
6.84k stars 884 forks source link

In Windows 10 environment, the GUI cannot be displayed by using the program compiled in the following code. After the program runs, the program will exit automatically at the speed of light. #629

Open AtlanCI opened 5 years ago

AtlanCI commented 5 years ago

` package main

import ( "fmt" "github.com/lxn/walk" . "github.com/lxn/walk/declarative" ) type MyMainWindow struct { walk.MainWindow } func main() { mw := new(MyMainWindow) var showAboutBoxAction walk.Action MainWindow{ AssignTo: &mw.MainWindow, Title: "Walk Actions Example", MinSize: Size{300, 200}, //菜单项

    MenuItems: []MenuItem{
        Menu{
            Text: "&Help",
            Items: []MenuItem{
                Action{
                    //赋值给谁
                    AssignTo:    &showAboutBoxAction,
                    Text:        "About",
                    //处罚函数
                    OnTriggered: func() {
                        walk.MsgBox(mw, "About", "Walk Actions Example", walk.MsgBoxIconInformation)
                    },
                },
            },
        },
    },

    Layout:  VBox{},
    Children: []Widget{
        PushButton{
            Text: "Enable Special Mode",
            OnClicked: func() {
                fmt.Println("别摸我" )
            },
            },
        },
    }.Create()

} `

AtlanCI commented 5 years ago

Description file `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

PerMonitorV2, PerMonitor True

`

AtlanCI commented 5 years ago

After I change the Create function behind the MainWindow structure to the Run function, it will work properly. `package main

import ( "fmt" "github.com/lxn/walk" . "github.com/lxn/walk/declarative" ) type MyMainWindow struct { walk.MainWindow } func main() { mw := new(MyMainWindow) var showAboutBoxAction walk.Action MainWindow{ AssignTo: &mw.MainWindow, Title: "Walk Actions Example", MinSize: Size{300, 200}, //菜单项

    MenuItems: []MenuItem{
        Menu{
            Text: "&Help",
            Items: []MenuItem{
                Action{
                    //赋值给谁
                    AssignTo:    &showAboutBoxAction,
                    Text:        "About",
                    //处罚函数
                    OnTriggered: func() {
                        walk.MsgBox(mw, "About", "Walk Actions Example", walk.MsgBoxIconInformation)
                    },
                },
            },
        },
    },

    Layout:  VBox{},
    Children: []Widget{
        PushButton{
            Text: "Enable Special Mode",
            OnClicked: func() {
                fmt.Println("别摸我" )
            },
            },
        },
    }.Run()

}

`

AtlanCI commented 5 years ago

I hope this will help you.