-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathwingui.go
94 lines (74 loc) · 1.65 KB
/
wingui.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
*
wingui Golang GUI library
# Usage
### Simple usage:
Generate x.syso file from rc or res file use `windres.exe` tool.
genereate syso:
`windres -i emptyProject/Debug/resource.res -O coff -o vsui.syso`
or
`windres -i ui/ui.rc -O coff -o ui.syso`
main.go
```go
package main
import "github.com/whtiehack/wingui"
func main() {
dlg, _ := wingui.NewDialog(101, 0, nil)
dlg.SetIcon(105)
btnok, _ := wingui.BindNewButton(1002, dlg)
btncancel, _ := wingui.BindNewButton(1003, dlg)
btnok.OnClicked = func() {
dlg.Close()
}
btncancel.OnClicked = btnok.OnClicked
dlg.Show()
// This invoke is optional.
wingui.SetCurrentDialog(dlg.Handle())
wingui.MessageLoop()
}
```
run:
`go run .`
Don't use `go run main.go`, because golang can't load x.syso files.
*/
package wingui
import (
"github.com/lxn/win"
"log"
"os"
"syscall"
)
var hInstance win.HINSTANCE
func init() {
log.SetOutput(os.Stdout)
InitHInstance("")
}
// InitHInstance init hInstance,used by Dialog APIs.
func InitHInstance(lpModuleName string) {
var name *uint16
if lpModuleName != "" {
name = syscall.StringToUTF16Ptr(lpModuleName)
}
hInstance = win.GetModuleHandle(name)
log.Println("hInstance", hInstance)
}
var dlg win.HWND
// MessageLoop start windows message loop.
func MessageLoop() {
// message loop
var msg win.MSG
for win.GetMessage(&msg, 0, 0, 0) > 0 {
if dlg > 0 {
if win.IsDialogMessage(dlg, &msg) {
continue
}
}
win.TranslateMessage(&msg)
win.DispatchMessage(&msg)
}
}
// SetCurrentDialog make sure Message Loop could process dialog msg correct,such as Tabstop msg.
// This is a optional method.
func SetCurrentDialog(h win.HWND) {
dlg = h
}