-
Notifications
You must be signed in to change notification settings - Fork 45
/
w32control.go
54 lines (46 loc) · 1.44 KB
/
w32control.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
package gform
import (
"github.com/AllenDang/w32"
)
type W32Control struct {
ControlBase
originalWndProc uintptr
isMouseLeft bool
}
func (this *W32Control) init(className string, parent Controller, exstyle, style uint) {
this.hwnd = CreateWindow(className, parent, exstyle, style)
if this.hwnd == 0 {
panic("cannot create window for " + className)
}
this.isMouseLeft = true
this.originalWndProc = w32.SetWindowLongPtr(this.hwnd, w32.GWLP_WNDPROC, GeneralWndprocCallBack)
this.ControlBase.init(parent)
}
func (this *W32Control) attach(parent Controller, dlgItemID int) {
if parent == nil {
panic("parent cannot be nil")
}
if this.hwnd = w32.GetDlgItem(parent.Handle(), dlgItemID); this.hwnd == 0 {
panic("hwnd cannot be nil")
}
this.isMouseLeft = true
this.originalWndProc = w32.SetWindowLongPtr(this.hwnd, w32.GWLP_WNDPROC, GeneralWndprocCallBack)
this.ControlBase.init(parent)
}
func (this *W32Control) WndProc(msg uint, wparam, lparam uintptr) uintptr {
switch msg {
case w32.WM_CREATE:
internalTrackMouseEvent(this.hwnd)
this.onCreate.Fire(NewEventArg(this, nil))
case w32.WM_MOUSEMOVE:
if this.isMouseLeft {
this.onMouseHover.Fire(NewEventArg(this, nil))
internalTrackMouseEvent(this.hwnd)
this.isMouseLeft = false
}
case w32.WM_MOUSELEAVE:
this.onMouseLeave.Fire(NewEventArg(this, nil))
this.isMouseLeft = true
}
return w32.CallWindowProc(this.originalWndProc, this.hwnd, uint32(msg), wparam, lparam)
}