-
Notifications
You must be signed in to change notification settings - Fork 1
/
paintManager.go
284 lines (241 loc) · 7.07 KB
/
paintManager.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
package gd
import (
"fmt"
"unsafe"
"github.com/fjs-icu/win"
)
type PaintManagerUI struct {
HWndPaint win.HWND
Name string
HDCPaint win.HDC
HDcOffscreen win.HDC
HDcBackground win.HDC
// Root DoControlUI
R1 []interface{}
R2 []interface{}
// RootXml *WindowXml
WindowUI *WindowUI
DialogBuilder
BStartPaint bool // 是否开始绘制
}
func (c *PaintManagerUI) Init(hWnd win.HWND, pstrName string) {
// 移除之前所有的控件
fmt.Println("1====", hWnd)
if c == nil {
fmt.Println(" c nil")
return
}
//初始化
c.Name = pstrName
// if( m_hWndPaint != hWnd ) {
// m_hWndPaint = hWnd;
// m_hDcPaint = ::GetDC(hWnd);
// m_aPreMessages.Add(this);
// }
fmt.Println("2====")
if c.HWndPaint != hWnd {
fmt.Println("HWndPaint ====", hWnd)
c.HWndPaint = hWnd
c.HDCPaint = win.GetDC(hWnd)
}
// c.Root = new(ControlUI)
build := new(DialogBuilder)
build.Create("test1.xml", c)
}
func (c *PaintManagerUI) MessageHandler(msg uint32, wParam, lParam uintptr) (bool, uintptr) {
if c.HWndPaint == 0 {
return false, 0
}
//fmt.Println("HWndPaint ====", c.HWndPaint)
// 处理分发事件...
switch msg {
case win.WM_NCHITTEST:
{
// 移动无标题栏的窗口(鼠标在客户区拖动移动窗口,非标题栏区域)
return c.OnNcHitTest(msg, wParam, lParam)
}
// case win.WM_ERASEBKGND:
case win.WM_PAINT:
var ps win.PAINTSTRUCT
hdc := win.BeginPaint(c.HWndPaint, &ps)
defer win.EndPaint(c.HWndPaint, &ps)
// if c.Root == nil {
// // 如果没有根目录,则绘制黑色区域
// DrawColor(hdc, ps.RcPaint, 0xffff0000)
// return true
// }
// 分层
// 刷新子区域
// 绘制所有区域
iSaveDc := win.SaveDC(hdc)
// c.Root.Paint(hdc, ps.RcPaint)
for _, v := range c.R1 {
// if v2, ok := v.(*XMLContainer); ok {
// fmt.Println("属于 XMLContainer ")
// v2.Paint(hdc, ps.RcPaint)
// // v2.DoPaint(hdc, ps.RcPaint)
// // for _, v3 := range v2.Item {
// // if v4, ok := v3.(*XMLControlUI); ok {
// // v3.
// // fmt.Println("XMLControlUI", v4)
// // }
// // }
// }
// if v2, ok := v.(*XMLControl); ok {
// fmt.Println("属于 XMLControl ")
// v2.Paint(hdc, ps.RcPaint)
// // v2.DoPaint(hdc, ps.RcPaint)
// // for _, v3 := range v2.Item {
// // if v4, ok := v3.(*XMLControlUI); ok {
// // v3.
// // fmt.Println("XMLControlUI", v4)
// // }
// // }
// }
if v2, ok := v.(DoControlUI); ok {
fmt.Println("属于 DoControlUI ")
v2.Paint(hdc, ps.RcPaint)
// v2.DoPaint(hdc, ps.RcPaint)
// for _, v3 := range v2.Item {
// if v4, ok := v3.(*XMLControlUI); ok {
// v3.
// fmt.Println("XMLControlUI", v4)
// }
// }
}
}
win.RestoreDC(hdc, iSaveDc)
// var ps win.PAINTSTRUCT
// hdc := win.BeginPaint(c.HWndPaint, &ps)
// var cl Color
// cl = 0xFFFFFFFF
// cl = RGB(255, 44, 0)
// sysColor := win.COLOR_BTNFACE
// var lb win.LOGBRUSH
// lb.LbStyle = win.BS_SOLID
// lb.LbColor = 0xff3300
// lb.LbHatch = 0
// hPen := win.HGDIOBJ(win.ExtCreatePen(win.PS_SOLID, 2, &lb, 0, nil))
// hOldOpen := win.SelectObject(hdc, hPen)
// win.SetBkMode(hdc, win.TRANSPARENT)
// var bgRC win.RECT
// win.GetWindowRect(c.HWndPaint, &bgRC)
// var rc win.RECT
// win.GetWindowRect(c.HWndPaint, &rc)
// win.SetBrushOrgEx(hdc, bgRC.Left-rc.Left, bgRC.Top-rc.Top, nil)
// win.SetBkColor(hdc, win.COLORREF(win.GetSysColor(sysColor)))
// cc := win.GetBkColor(hdc)
// fmt.Println("cc ", cc)
// cc2 := win.GetBkColor(hdc)
// fmt.Println("cc ", cc2)
// cleardevice()
// var ps win.PAINTSTRUCT
// hdc := win.BeginPaint(c.HWndPaint, &ps)
// var pt win.POINT
// win.MoveToEx(hdc, 0, 0, &pt)
// win.LineTo(hdc, 100, 100)
// win.Rectangle_(hdc, 100, 100, 100, 100)
// win.EndPaint(c.HWndPaint, &ps)
// win.SelectObject(hdc, hOldOpen)
// win.DeleteObject(hPen)
// fmt.Println("paint....")
// win.InvalidateRect(c.HWndPaint, nil, false)
return true, 0
case win.WM_GETMINMAXINFO:
// 鼠标移动窗口,改变窗口大小,都会调用
return c.OnGetMinMaxInfo(msg, wParam, lParam)
case win.WM_SIZE:
return c.OnSize(msg, wParam, lParam)
}
return false, 0
}
func (c *PaintManagerUI) OnSize(msg uint32, wParam, lParam uintptr) (bool, uintptr) {
szRoundcorner := c.WindowUI.Roundcorner
if !win.IsIconic(c.HWndPaint) && (szRoundcorner.Cx > 0 || szRoundcorner.Cy > 0) {
var rcClient win.RECT
win.GetClientRect(c.HWndPaint, &rcClient)
hrgn := win.CreateRoundRectRgn(rcClient.Left, rcClient.Top, rcClient.Right, rcClient.Bottom, szRoundcorner.Cx, szRoundcorner.Cy)
win.SetWindowRgn(c.HWndPaint, hrgn, true)
win.DeleteObject(win.HGDIOBJ(hrgn))
}
return true, 0
}
func (c *PaintManagerUI) OnGetMinMaxInfo(msg uint32, wParam, lParam uintptr) (bool, uintptr) {
var lpmmi *win.MINMAXINFO
lpmmi = (*win.MINMAXINFO)(unsafe.Pointer(lParam))
if lpmmi != nil {
if c.WindowUI.MininfoUI.Cx > 0 {
lpmmi.PtMinTrackSize.X = c.WindowUI.MininfoUI.Cx
}
if c.WindowUI.MininfoUI.Cy > 0 {
lpmmi.PtMinTrackSize.Y = c.WindowUI.MininfoUI.Cy
}
if c.WindowUI.MaxinfoUI.Cx > 0 {
lpmmi.PtMaxTrackSize.X = c.WindowUI.MaxinfoUI.Cx
}
if c.WindowUI.MaxinfoUI.Cy > 0 {
lpmmi.PtMaxTrackSize.Y = c.WindowUI.MaxinfoUI.Cy
}
}
return true, 0
}
func (c *PaintManagerUI) OnNcHitTest(msg uint32, wParam, lParam uintptr) (bool, uintptr) {
x := int32(win.GET_X_LPARAM(lParam))
y := int32(win.GET_Y_LPARAM(lParam))
var pt win.POINT
pt.X = x
pt.Y = y
win.ScreenToClient(c.HWndPaint, &pt)
var rcClient win.RECT
win.GetClientRect(c.HWndPaint, &rcClient)
if !win.IsZoomed(c.HWndPaint) {
rcSizeBox := c.WindowUI.SizeBox
if pt.Y < rcClient.Top+rcSizeBox.Top {
if pt.X < rcClient.Left+rcSizeBox.Left {
return true, win.HTTOPLEFT
}
if pt.X > rcClient.Right-rcSizeBox.Right {
return true, win.HTTOPRIGHT
}
return true, win.HTTOP
} else if pt.Y > rcClient.Bottom-rcSizeBox.Bottom {
if pt.X < rcClient.Left+rcSizeBox.Left {
return true, win.HTBOTTOMLEFT
}
if pt.X > rcClient.Right-rcSizeBox.Right {
return true, win.HTBOTTOMRIGHT
}
return true, win.HTBOTTOM
}
if pt.X < rcClient.Left+rcSizeBox.Left {
return true, win.HTLEFT
}
if pt.X > rcClient.Right-rcSizeBox.Right {
return true, win.HTRIGHT
}
}
rcCaption := c.WindowUI.Caption
if (pt.X >= rcClient.Left+rcCaption.Left) && (pt.X < rcClient.Right-rcCaption.Right) && pt.Y >= rcCaption.Top && pt.Y < rcCaption.Bottom {
// 判断当前点是什么控件,如果是按钮等不能实现拖动控件
// 判断当前点所在的最外层控件是否隐藏,判断当前点处于最里层的控件是什么. 暂未想好如何实现.
return true, win.HTCAPTION
}
return true, win.HTCLIENT
}
var ii int
func (c *PaintManagerUI) TranslateMessage(msg *win.MSG) bool {
// 往几个子模块发送消息
// msg.HWnd
// win.GetWindowSty
fmt.Println("TranslateMessage ...")
ustyle := win.GetWindowStyle(msg.HWnd)
fmt.Println("ustyle : ", ustyle)
ii++
if ii > 2 {
return true
}
return false
}
func (c *PaintManagerUI) SetInitSize(cx, cy int32) {
c.WindowUI.SetInitSize(cx, cy, c.HWndPaint)
}