go-tg-screenshot-bot

Форк
0
390 строк · 9.7 Кб
1
// Copyright 2016 The win Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
4

5
// +build windows
6

7
package win
8

9
import (
10
	"syscall"
11
	"unsafe"
12

13
	"golang.org/x/sys/windows"
14
)
15

16
// Button control messages
17
const (
18
	BCM_FIRST            = 0x1600
19
	BCM_GETIDEALSIZE     = BCM_FIRST + 0x0001
20
	BCM_SETIMAGELIST     = BCM_FIRST + 0x0002
21
	BCM_GETIMAGELIST     = BCM_FIRST + 0x0003
22
	BCM_SETTEXTMARGIN    = BCM_FIRST + 0x0004
23
	BCM_GETTEXTMARGIN    = BCM_FIRST + 0x0005
24
	BCM_SETDROPDOWNSTATE = BCM_FIRST + 0x0006
25
	BCM_SETSPLITINFO     = BCM_FIRST + 0x0007
26
	BCM_GETSPLITINFO     = BCM_FIRST + 0x0008
27
	BCM_SETNOTE          = BCM_FIRST + 0x0009
28
	BCM_GETNOTE          = BCM_FIRST + 0x000A
29
	BCM_GETNOTELENGTH    = BCM_FIRST + 0x000B
30
	BCM_SETSHIELD        = BCM_FIRST + 0x000C
31
)
32

33
const (
34
	CCM_FIRST            = 0x2000
35
	CCM_LAST             = CCM_FIRST + 0x200
36
	CCM_SETBKCOLOR       = 8193
37
	CCM_SETCOLORSCHEME   = 8194
38
	CCM_GETCOLORSCHEME   = 8195
39
	CCM_GETDROPTARGET    = 8196
40
	CCM_SETUNICODEFORMAT = 8197
41
	CCM_GETUNICODEFORMAT = 8198
42
	CCM_SETVERSION       = 0x2007
43
	CCM_GETVERSION       = 0x2008
44
	CCM_SETNOTIFYWINDOW  = 0x2009
45
	CCM_SETWINDOWTHEME   = 0x200b
46
	CCM_DPISCALE         = 0x200c
47
)
48

49
// Common controls styles
50
const (
51
	CCS_TOP           = 1
52
	CCS_NOMOVEY       = 2
53
	CCS_BOTTOM        = 3
54
	CCS_NORESIZE      = 4
55
	CCS_NOPARENTALIGN = 8
56
	CCS_ADJUSTABLE    = 32
57
	CCS_NODIVIDER     = 64
58
	CCS_VERT          = 128
59
	CCS_LEFT          = 129
60
	CCS_NOMOVEX       = 130
61
	CCS_RIGHT         = 131
62
)
63

64
// InitCommonControlsEx flags
65
const (
66
	ICC_LISTVIEW_CLASSES   = 1
67
	ICC_TREEVIEW_CLASSES   = 2
68
	ICC_BAR_CLASSES        = 4
69
	ICC_TAB_CLASSES        = 8
70
	ICC_UPDOWN_CLASS       = 16
71
	ICC_PROGRESS_CLASS     = 32
72
	ICC_HOTKEY_CLASS       = 64
73
	ICC_ANIMATE_CLASS      = 128
74
	ICC_WIN95_CLASSES      = 255
75
	ICC_DATE_CLASSES       = 256
76
	ICC_USEREX_CLASSES     = 512
77
	ICC_COOL_CLASSES       = 1024
78
	ICC_INTERNET_CLASSES   = 2048
79
	ICC_PAGESCROLLER_CLASS = 4096
80
	ICC_NATIVEFNTCTL_CLASS = 8192
81
	INFOTIPSIZE            = 1024
82
	ICC_STANDARD_CLASSES   = 0x00004000
83
	ICC_LINK_CLASS         = 0x00008000
84
)
85

86
// WM_NOTITY messages
87
const (
88
	NM_FIRST              = 0
89
	NM_OUTOFMEMORY        = ^uint32(0)  // NM_FIRST - 1
90
	NM_CLICK              = ^uint32(1)  // NM_FIRST - 2
91
	NM_DBLCLK             = ^uint32(2)  // NM_FIRST - 3
92
	NM_RETURN             = ^uint32(3)  // NM_FIRST - 4
93
	NM_RCLICK             = ^uint32(4)  // NM_FIRST - 5
94
	NM_RDBLCLK            = ^uint32(5)  // NM_FIRST - 6
95
	NM_SETFOCUS           = ^uint32(6)  // NM_FIRST - 7
96
	NM_KILLFOCUS          = ^uint32(7)  // NM_FIRST - 8
97
	NM_CUSTOMDRAW         = ^uint32(11) // NM_FIRST - 12
98
	NM_HOVER              = ^uint32(12) // NM_FIRST - 13
99
	NM_NCHITTEST          = ^uint32(13) // NM_FIRST - 14
100
	NM_KEYDOWN            = ^uint32(14) // NM_FIRST - 15
101
	NM_RELEASEDCAPTURE    = ^uint32(15) // NM_FIRST - 16
102
	NM_SETCURSOR          = ^uint32(16) // NM_FIRST - 17
103
	NM_CHAR               = ^uint32(17) // NM_FIRST - 18
104
	NM_TOOLTIPSCREATED    = ^uint32(18) // NM_FIRST - 19
105
	NM_LAST               = ^uint32(98) // NM_FIRST - 99
106
	TRBN_THUMBPOSCHANGING = 0xfffffa22  // TRBN_FIRST - 1
107
)
108

109
// ProgressBar messages
110
const (
111
	PBM_SETPOS      = WM_USER + 2
112
	PBM_DELTAPOS    = WM_USER + 3
113
	PBM_SETSTEP     = WM_USER + 4
114
	PBM_STEPIT      = WM_USER + 5
115
	PBM_SETMARQUEE  = WM_USER + 10
116
	PBM_SETRANGE32  = 1030
117
	PBM_GETRANGE    = 1031
118
	PBM_GETPOS      = 1032
119
	PBM_SETBARCOLOR = 1033
120
	PBM_SETBKCOLOR  = CCM_SETBKCOLOR
121
)
122

123
// ProgressBar styles
124
const (
125
	PBS_SMOOTH   = 0x01
126
	PBS_VERTICAL = 0x04
127
	PBS_MARQUEE  = 0x08
128
)
129

130
// TrackBar (Slider) messages
131
const (
132
	TBM_GETPOS      = WM_USER
133
	TBM_GETRANGEMIN = WM_USER + 1
134
	TBM_GETRANGEMAX = WM_USER + 2
135
	TBM_SETPOS      = WM_USER + 5
136
	TBM_SETRANGEMIN = WM_USER + 7
137
	TBM_SETRANGEMAX = WM_USER + 8
138
	TBM_SETPAGESIZE = WM_USER + 21
139
	TBM_GETPAGESIZE = WM_USER + 22
140
	TBM_SETLINESIZE = WM_USER + 23
141
	TBM_GETLINESIZE = WM_USER + 24
142
)
143

144
// TrackBar (Slider) styles
145
const (
146
	TBS_VERT     = 0x002
147
	TBS_TOOLTIPS = 0x100
148
)
149

150
// ImageList creation flags
151
const (
152
	ILC_MASK          = 0x00000001
153
	ILC_COLOR         = 0x00000000
154
	ILC_COLORDDB      = 0x000000FE
155
	ILC_COLOR4        = 0x00000004
156
	ILC_COLOR8        = 0x00000008
157
	ILC_COLOR16       = 0x00000010
158
	ILC_COLOR24       = 0x00000018
159
	ILC_COLOR32       = 0x00000020
160
	ILC_PALETTE       = 0x00000800
161
	ILC_MIRROR        = 0x00002000
162
	ILC_PERITEMMIRROR = 0x00008000
163
)
164

165
// ImageList_Draw[Ex] flags
166
const (
167
	ILD_NORMAL      = 0x00000000
168
	ILD_TRANSPARENT = 0x00000001
169
	ILD_BLEND25     = 0x00000002
170
	ILD_BLEND50     = 0x00000004
171
	ILD_MASK        = 0x00000010
172
	ILD_IMAGE       = 0x00000020
173
	ILD_SELECTED    = ILD_BLEND50
174
	ILD_FOCUS       = ILD_BLEND25
175
	ILD_BLEND       = ILD_BLEND50
176
)
177

178
// LoadIconMetric flags
179
const (
180
	LIM_SMALL = 0
181
	LIM_LARGE = 1
182
)
183

184
const (
185
	CDDS_PREPAINT      = 0x00000001
186
	CDDS_POSTPAINT     = 0x00000002
187
	CDDS_PREERASE      = 0x00000003
188
	CDDS_POSTERASE     = 0x00000004
189
	CDDS_ITEM          = 0x00010000
190
	CDDS_ITEMPREPAINT  = CDDS_ITEM | CDDS_PREPAINT
191
	CDDS_ITEMPOSTPAINT = CDDS_ITEM | CDDS_POSTPAINT
192
	CDDS_ITEMPREERASE  = CDDS_ITEM | CDDS_PREERASE
193
	CDDS_ITEMPOSTERASE = CDDS_ITEM | CDDS_POSTERASE
194
	CDDS_SUBITEM       = 0x00020000
195
)
196

197
const (
198
	CDIS_SELECTED         = 0x0001
199
	CDIS_GRAYED           = 0x0002
200
	CDIS_DISABLED         = 0x0004
201
	CDIS_CHECKED          = 0x0008
202
	CDIS_FOCUS            = 0x0010
203
	CDIS_DEFAULT          = 0x0020
204
	CDIS_HOT              = 0x0040
205
	CDIS_MARKED           = 0x0080
206
	CDIS_INDETERMINATE    = 0x0100
207
	CDIS_SHOWKEYBOARDCUES = 0x0200
208
	CDIS_NEARHOT          = 0x0400
209
	CDIS_OTHERSIDEHOT     = 0x0800
210
	CDIS_DROPHILITED      = 0x1000
211
)
212

213
const (
214
	CDRF_DODEFAULT         = 0x00000000
215
	CDRF_NEWFONT           = 0x00000002
216
	CDRF_SKIPDEFAULT       = 0x00000004
217
	CDRF_DOERASE           = 0x00000008
218
	CDRF_NOTIFYPOSTPAINT   = 0x00000010
219
	CDRF_NOTIFYITEMDRAW    = 0x00000020
220
	CDRF_NOTIFYSUBITEMDRAW = 0x00000020
221
	CDRF_NOTIFYPOSTERASE   = 0x00000040
222
	CDRF_SKIPPOSTPAINT     = 0x00000100
223
)
224

225
const (
226
	LVIR_BOUNDS       = 0
227
	LVIR_ICON         = 1
228
	LVIR_LABEL        = 2
229
	LVIR_SELECTBOUNDS = 3
230
)
231

232
const (
233
	LPSTR_TEXTCALLBACK = ^uintptr(0)
234
	I_CHILDRENCALLBACK = -1
235
	I_IMAGECALLBACK    = -1
236
	I_IMAGENONE        = -2
237
)
238

239
type HIMAGELIST HANDLE
240

241
type INITCOMMONCONTROLSEX struct {
242
	DwSize, DwICC uint32
243
}
244

245
type NMCUSTOMDRAW struct {
246
	Hdr         NMHDR
247
	DwDrawStage uint32
248
	Hdc         HDC
249
	Rc          RECT
250
	DwItemSpec  uintptr
251
	UItemState  uint32
252
	LItemlParam uintptr
253
}
254

255
var (
256
	// Library
257
	libcomctl32 *windows.LazyDLL
258

259
	// Functions
260
	imageList_Add         *windows.LazyProc
261
	imageList_AddMasked   *windows.LazyProc
262
	imageList_Create      *windows.LazyProc
263
	imageList_Destroy     *windows.LazyProc
264
	imageList_DrawEx      *windows.LazyProc
265
	imageList_ReplaceIcon *windows.LazyProc
266
	initCommonControlsEx  *windows.LazyProc
267
	loadIconMetric        *windows.LazyProc
268
	loadIconWithScaleDown *windows.LazyProc
269
)
270

271
func init() {
272
	// Library
273
	libcomctl32 = windows.NewLazySystemDLL("comctl32.dll")
274

275
	// Functions
276
	imageList_Add = libcomctl32.NewProc("ImageList_Add")
277
	imageList_AddMasked = libcomctl32.NewProc("ImageList_AddMasked")
278
	imageList_Create = libcomctl32.NewProc("ImageList_Create")
279
	imageList_Destroy = libcomctl32.NewProc("ImageList_Destroy")
280
	imageList_DrawEx = libcomctl32.NewProc("ImageList_DrawEx")
281
	imageList_ReplaceIcon = libcomctl32.NewProc("ImageList_ReplaceIcon")
282
	initCommonControlsEx = libcomctl32.NewProc("InitCommonControlsEx")
283
	loadIconMetric = libcomctl32.NewProc("LoadIconMetric")
284
	loadIconWithScaleDown = libcomctl32.NewProc("LoadIconWithScaleDown")
285
}
286

287
func ImageList_Add(himl HIMAGELIST, hbmImage, hbmMask HBITMAP) int32 {
288
	ret, _, _ := syscall.Syscall(imageList_Add.Addr(), 3,
289
		uintptr(himl),
290
		uintptr(hbmImage),
291
		uintptr(hbmMask))
292

293
	return int32(ret)
294
}
295

296
func ImageList_AddMasked(himl HIMAGELIST, hbmImage HBITMAP, crMask COLORREF) int32 {
297
	ret, _, _ := syscall.Syscall(imageList_AddMasked.Addr(), 3,
298
		uintptr(himl),
299
		uintptr(hbmImage),
300
		uintptr(crMask))
301

302
	return int32(ret)
303
}
304

305
func ImageList_Create(cx, cy int32, flags uint32, cInitial, cGrow int32) HIMAGELIST {
306
	ret, _, _ := syscall.Syscall6(imageList_Create.Addr(), 5,
307
		uintptr(cx),
308
		uintptr(cy),
309
		uintptr(flags),
310
		uintptr(cInitial),
311
		uintptr(cGrow),
312
		0)
313

314
	return HIMAGELIST(ret)
315
}
316

317
func ImageList_Destroy(hIml HIMAGELIST) bool {
318
	ret, _, _ := syscall.Syscall(imageList_Destroy.Addr(), 1,
319
		uintptr(hIml),
320
		0,
321
		0)
322

323
	return ret != 0
324
}
325

326
func ImageList_DrawEx(himl HIMAGELIST, i int32, hdcDst HDC, x, y, dx, dy int32, rgbBk COLORREF, rgbFg COLORREF, fStyle uint32) bool {
327
	ret, _, _ := syscall.Syscall12(imageList_DrawEx.Addr(), 10,
328
		uintptr(himl),
329
		uintptr(i),
330
		uintptr(hdcDst),
331
		uintptr(x),
332
		uintptr(y),
333
		uintptr(dx),
334
		uintptr(dy),
335
		uintptr(rgbBk),
336
		uintptr(rgbFg),
337
		uintptr(fStyle),
338
		0,
339
		0)
340

341
	return ret != 0
342
}
343

344
func ImageList_ReplaceIcon(himl HIMAGELIST, i int32, hicon HICON) int32 {
345
	ret, _, _ := syscall.Syscall(imageList_ReplaceIcon.Addr(), 3,
346
		uintptr(himl),
347
		uintptr(i),
348
		uintptr(hicon))
349

350
	return int32(ret)
351
}
352

353
func InitCommonControlsEx(lpInitCtrls *INITCOMMONCONTROLSEX) bool {
354
	ret, _, _ := syscall.Syscall(initCommonControlsEx.Addr(), 1,
355
		uintptr(unsafe.Pointer(lpInitCtrls)),
356
		0,
357
		0)
358

359
	return ret != 0
360
}
361

362
func LoadIconMetric(hInstance HINSTANCE, lpIconName *uint16, lims int32, hicon *HICON) HRESULT {
363
	if loadIconMetric.Find() != nil {
364
		return HRESULT(0)
365
	}
366
	ret, _, _ := syscall.Syscall6(loadIconMetric.Addr(), 4,
367
		uintptr(hInstance),
368
		uintptr(unsafe.Pointer(lpIconName)),
369
		uintptr(lims),
370
		uintptr(unsafe.Pointer(hicon)),
371
		0,
372
		0)
373

374
	return HRESULT(ret)
375
}
376

377
func LoadIconWithScaleDown(hInstance HINSTANCE, lpIconName *uint16, w int32, h int32, hicon *HICON) HRESULT {
378
	if loadIconWithScaleDown.Find() != nil {
379
		return HRESULT(0)
380
	}
381
	ret, _, _ := syscall.Syscall6(loadIconWithScaleDown.Addr(), 5,
382
		uintptr(hInstance),
383
		uintptr(unsafe.Pointer(lpIconName)),
384
		uintptr(w),
385
		uintptr(h),
386
		uintptr(unsafe.Pointer(hicon)),
387
		0)
388

389
	return HRESULT(ret)
390
}
391

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.