1// Copyright 2010-2012 The W32 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
7package w32
8
9import (
10	"syscall"
11	"unsafe"
12)
13
14var (
15	modcomctl32 = syscall.NewLazyDLL("comctl32.dll")
16
17	procInitCommonControlsEx    = modcomctl32.NewProc("InitCommonControlsEx")
18	procImageList_Create        = modcomctl32.NewProc("ImageList_Create")
19	procImageList_Destroy       = modcomctl32.NewProc("ImageList_Destroy")
20	procImageList_GetImageCount = modcomctl32.NewProc("ImageList_GetImageCount")
21	procImageList_SetImageCount = modcomctl32.NewProc("ImageList_SetImageCount")
22	procImageList_Add           = modcomctl32.NewProc("ImageList_Add")
23	procImageList_ReplaceIcon   = modcomctl32.NewProc("ImageList_ReplaceIcon")
24	procImageList_Remove        = modcomctl32.NewProc("ImageList_Remove")
25	procTrackMouseEvent         = modcomctl32.NewProc("_TrackMouseEvent")
26)
27
28func InitCommonControlsEx(lpInitCtrls *INITCOMMONCONTROLSEX) bool {
29	ret, _, _ := procInitCommonControlsEx.Call(
30		uintptr(unsafe.Pointer(lpInitCtrls)))
31
32	return ret != 0
33}
34
35func ImageList_Create(cx, cy int, flags uint, cInitial, cGrow int) HIMAGELIST {
36	ret, _, _ := procImageList_Create.Call(
37		uintptr(cx),
38		uintptr(cy),
39		uintptr(flags),
40		uintptr(cInitial),
41		uintptr(cGrow))
42
43	if ret == 0 {
44		panic("Create image list failed")
45	}
46
47	return HIMAGELIST(ret)
48}
49
50func ImageList_Destroy(himl HIMAGELIST) bool {
51	ret, _, _ := procImageList_Destroy.Call(
52		uintptr(himl))
53
54	return ret != 0
55}
56
57func ImageList_GetImageCount(himl HIMAGELIST) int {
58	ret, _, _ := procImageList_GetImageCount.Call(
59		uintptr(himl))
60
61	return int(ret)
62}
63
64func ImageList_SetImageCount(himl HIMAGELIST, uNewCount uint) bool {
65	ret, _, _ := procImageList_SetImageCount.Call(
66		uintptr(himl),
67		uintptr(uNewCount))
68
69	return ret != 0
70}
71
72func ImageList_Add(himl HIMAGELIST, hbmImage, hbmMask HBITMAP) int {
73	ret, _, _ := procImageList_Add.Call(
74		uintptr(himl),
75		uintptr(hbmImage),
76		uintptr(hbmMask))
77
78	return int(ret)
79}
80
81func ImageList_ReplaceIcon(himl HIMAGELIST, i int, hicon HICON) int {
82	ret, _, _ := procImageList_ReplaceIcon.Call(
83		uintptr(himl),
84		uintptr(i),
85		uintptr(hicon))
86
87	return int(ret)
88}
89
90func ImageList_AddIcon(himl HIMAGELIST, hicon HICON) int {
91	return ImageList_ReplaceIcon(himl, -1, hicon)
92}
93
94func ImageList_Remove(himl HIMAGELIST, i int) bool {
95	ret, _, _ := procImageList_Remove.Call(
96		uintptr(himl),
97		uintptr(i))
98
99	return ret != 0
100}
101
102func ImageList_RemoveAll(himl HIMAGELIST) bool {
103	return ImageList_Remove(himl, -1)
104}
105
106func TrackMouseEvent(tme *TRACKMOUSEEVENT) bool {
107	ret, _, _ := procTrackMouseEvent.Call(
108		uintptr(unsafe.Pointer(tme)))
109
110	return ret != 0
111}
112