forked from AllenDang/gform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
70 lines (55 loc) · 1.5 KB
/
app.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
package gform
import (
"github.com/AllenDang/w32"
"unsafe"
)
func Init() {
gAppInstance = w32.GetModuleHandle("")
if gAppInstance == 0 {
panic("Error occurred in App.Init")
}
// Initialize the common controls
var initCtrls w32.INITCOMMONCONTROLSEX
initCtrls.DwSize = uint32(unsafe.Sizeof(initCtrls))
initCtrls.DwICC =
w32.ICC_LISTVIEW_CLASSES | w32.ICC_PROGRESS_CLASS | w32.ICC_TAB_CLASSES |
w32.ICC_TREEVIEW_CLASSES | w32.ICC_BAR_CLASSES
w32.InitCommonControlsEx(&initCtrls)
}
func GetAppInstance() w32.HINSTANCE {
return gAppInstance
}
func PreTranslateMessage(msg *w32.MSG) bool {
// This functions is called by the MessageLoop. It processes the
// keyboard accelerator keys and calls Controller.PreTranslateMessage for
// keyboard and mouse events.
processed := false
if (msg.Message >= w32.WM_KEYFIRST && msg.Message <= w32.WM_KEYLAST) ||
(msg.Message >= w32.WM_MOUSEFIRST && msg.Message <= w32.WM_MOUSELAST) {
if msg.Hwnd != 0 {
if controller := GetMsgHandler(msg.Hwnd); controller != nil {
// Search the chain of parents for pretranslated messages.
for p := controller; p != nil; p = p.Parent() {
if processed = p.PreTranslateMessage(msg); processed {
break
}
}
}
}
}
return processed
}
func RunMainLoop() int {
var m w32.MSG
for w32.GetMessage(&m, 0, 0, 0) != 0 {
if !PreTranslateMessage(&m) {
w32.TranslateMessage(&m)
w32.DispatchMessage(&m)
}
}
w32.GdiplusShutdown()
return int(m.WParam)
}
func Exit() {
w32.PostQuitMessage(0)
}