forked from whtiehack/wingui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
static.go
56 lines (50 loc) · 1.37 KB
/
static.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
package wingui
import (
"github.com/lxn/win"
)
// Static a static label widget for Dialog.
type Static struct {
WindowBase
// Color must set before Dialog init,Widget should bind use DialogConfig.
Color win.COLORREF
//BkMode must set same as Color
BkMode int32
// OnClicked must set appearance Notify to true before use.
OnClicked func()
}
// WndProc Static window WndProc.
func (b *Static) WndProc(msg uint32, wParam, lParam uintptr) uintptr {
// log.Print("static msg", msg, wParam, lParam)
switch msg {
case win.WM_CTLCOLORSTATIC:
// log.Print("static WM_CTLCOLORSTATIC")
if b.Color != 0 && b.BkMode != 0 {
win.SetTextColor(win.HDC(wParam), b.Color) //设置文本颜色
win.SetBkMode(win.HDC(wParam), b.BkMode) //设置背景透明
//返回一个空画刷(必须)
hb := win.GetStockObject(win.NULL_BRUSH)
return uintptr(hb)
}
return 0
case win.WM_COMMAND:
if b.OnClicked != nil {
b.OnClicked()
}
break
}
return b.AsWindowBase().WndProc(msg, wParam, lParam)
}
// NewStatic create a new Static,need bind to Dialog before use.
func NewStatic(idd uintptr) *Static {
return &Static{
WindowBase: WindowBase{idd: idd},
Color: 0,
BkMode: 0,
}
}
// BindNewStatic create a new Static and bind to target dlg.
func BindNewStatic(idd uintptr, dlg *Dialog) (*Static, error) {
b := NewStatic(idd)
err := dlg.BindWidgets(b)
return b, err
}