-
Notifications
You must be signed in to change notification settings - Fork 45
/
form.go
95 lines (76 loc) · 1.98 KB
/
form.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
95
package gform
import (
"github.com/AllenDang/w32"
)
type Form struct {
ControlBase
isDialog bool
isDragMove bool
}
func NewForm(parent Controller) *Form {
f := new(Form)
f.init(parent)
f.SetFont(DefaultFont)
f.SetCaption("Form")
return f
}
func (this *Form) init(parent Controller) {
RegClassOnlyOnce("gform_Form")
this.isForm = true
this.isDialog = false
this.isDragMove = false
this.hwnd = CreateWindow("gform_Form", parent, w32.WS_EX_CLIENTEDGE, w32.WS_OVERLAPPEDWINDOW)
this.ControlBase.init(parent)
RegMsgHandler(this)
}
// Public methods
func (this *Form) Center() {
sWidth := w32.GetSystemMetrics(w32.SM_CXFULLSCREEN)
sHeight := w32.GetSystemMetrics(w32.SM_CYFULLSCREEN)
if sWidth != 0 && sHeight != 0 {
w, h := this.Size()
this.SetPos((sWidth/2)-(w/2), (sHeight/2)-(h/2))
}
}
// IconType: 1 - ICON_BIG; 0 - ICON_SMALL
func (this *Form) SetIcon(iconType int, icon *Icon) {
if iconType > 1 {
panic("IconType is invalid")
}
w32.SendMessage(this.hwnd, w32.WM_SETICON, uintptr(iconType), uintptr(icon.Handle()))
}
func (this *Form) EnableMaxButton(b bool) {
ToggleStyle(this.hwnd, b, w32.WS_MAXIMIZEBOX)
}
func (this *Form) EnableMinButton(b bool) {
ToggleStyle(this.hwnd, b, w32.WS_MINIMIZEBOX)
}
func (this *Form) EnableSizable(b bool) {
ToggleStyle(this.hwnd, b, w32.WS_THICKFRAME)
}
func (this *Form) EnableDragMove(b bool) {
this.isDragMove = b
}
func (this *Form) EnableTopMost(b bool) {
tag := w32.HWND_NOTOPMOST
if b {
tag = w32.HWND_TOPMOST
}
w32.SetWindowPos(this.hwnd, tag, 0, 0, 0, 0, w32.SWP_NOMOVE|w32.SWP_NOSIZE)
}
func (this *Form) WndProc(msg uint, wparam, lparam uintptr) uintptr {
switch msg {
case w32.WM_LBUTTONDOWN:
if this.isDragMove {
w32.ReleaseCapture()
w32.SendMessage(this.hwnd, w32.WM_NCLBUTTONDOWN, w32.HTCAPTION, 0)
}
case w32.WM_CLOSE:
this.onClose.Fire(NewEventArg(this, nil))
return 0
case w32.WM_DESTROY:
w32.PostQuitMessage(0)
return 0
}
return w32.DefWindowProc(this.hwnd, uint32(msg), wparam, lparam)
}