comctl32.go 2.7 KB

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