dwmapi.go 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. "fmt"
  8. "syscall"
  9. "unsafe"
  10. )
  11. // DEFINED IN THE DWM API BUT NOT IMPLEMENTED BY MS:
  12. // DwmAttachMilContent
  13. // DwmDetachMilContent
  14. // DwmEnableComposition
  15. // DwmGetGraphicsStreamClient
  16. // DwmGetGraphicsStreamTransformHint
  17. var (
  18. moddwmapi = syscall.NewLazyDLL("dwmapi.dll")
  19. procDwmDefWindowProc = moddwmapi.NewProc("DwmDefWindowProc")
  20. procDwmEnableBlurBehindWindow = moddwmapi.NewProc("DwmEnableBlurBehindWindow")
  21. procDwmEnableMMCSS = moddwmapi.NewProc("DwmEnableMMCSS")
  22. procDwmExtendFrameIntoClientArea = moddwmapi.NewProc("DwmExtendFrameIntoClientArea")
  23. procDwmFlush = moddwmapi.NewProc("DwmFlush")
  24. procDwmGetColorizationColor = moddwmapi.NewProc("DwmGetColorizationColor")
  25. procDwmGetCompositionTimingInfo = moddwmapi.NewProc("DwmGetCompositionTimingInfo")
  26. procDwmGetTransportAttributes = moddwmapi.NewProc("DwmGetTransportAttributes")
  27. procDwmGetWindowAttribute = moddwmapi.NewProc("DwmGetWindowAttribute")
  28. procDwmInvalidateIconicBitmaps = moddwmapi.NewProc("DwmInvalidateIconicBitmaps")
  29. procDwmIsCompositionEnabled = moddwmapi.NewProc("DwmIsCompositionEnabled")
  30. procDwmModifyPreviousDxFrameDuration = moddwmapi.NewProc("DwmModifyPreviousDxFrameDuration")
  31. procDwmQueryThumbnailSourceSize = moddwmapi.NewProc("DwmQueryThumbnailSourceSize")
  32. procDwmRegisterThumbnail = moddwmapi.NewProc("DwmRegisterThumbnail")
  33. procDwmRenderGesture = moddwmapi.NewProc("DwmRenderGesture")
  34. procDwmSetDxFrameDuration = moddwmapi.NewProc("DwmSetDxFrameDuration")
  35. procDwmSetIconicLivePreviewBitmap = moddwmapi.NewProc("DwmSetIconicLivePreviewBitmap")
  36. procDwmSetIconicThumbnail = moddwmapi.NewProc("DwmSetIconicThumbnail")
  37. procDwmSetPresentParameters = moddwmapi.NewProc("DwmSetPresentParameters")
  38. procDwmSetWindowAttribute = moddwmapi.NewProc("DwmSetWindowAttribute")
  39. procDwmShowContact = moddwmapi.NewProc("DwmShowContact")
  40. procDwmTetherContact = moddwmapi.NewProc("DwmTetherContact")
  41. procDwmTransitionOwnedWindow = moddwmapi.NewProc("DwmTransitionOwnedWindow")
  42. procDwmUnregisterThumbnail = moddwmapi.NewProc("DwmUnregisterThumbnail")
  43. procDwmUpdateThumbnailProperties = moddwmapi.NewProc("DwmUpdateThumbnailProperties")
  44. )
  45. func DwmDefWindowProc(hWnd HWND, msg uint, wParam, lParam uintptr) (bool, uint) {
  46. var result uint
  47. ret, _, _ := procDwmDefWindowProc.Call(
  48. uintptr(hWnd),
  49. uintptr(msg),
  50. wParam,
  51. lParam,
  52. uintptr(unsafe.Pointer(&result)))
  53. return ret != 0, result
  54. }
  55. func DwmEnableBlurBehindWindow(hWnd HWND, pBlurBehind *DWM_BLURBEHIND) HRESULT {
  56. ret, _, _ := procDwmEnableBlurBehindWindow.Call(
  57. uintptr(hWnd),
  58. uintptr(unsafe.Pointer(pBlurBehind)))
  59. return HRESULT(ret)
  60. }
  61. func DwmEnableMMCSS(fEnableMMCSS bool) HRESULT {
  62. ret, _, _ := procDwmEnableMMCSS.Call(
  63. uintptr(BoolToBOOL(fEnableMMCSS)))
  64. return HRESULT(ret)
  65. }
  66. func DwmExtendFrameIntoClientArea(hWnd HWND, pMarInset *MARGINS) HRESULT {
  67. ret, _, _ := procDwmExtendFrameIntoClientArea.Call(
  68. uintptr(hWnd),
  69. uintptr(unsafe.Pointer(pMarInset)))
  70. return HRESULT(ret)
  71. }
  72. func DwmFlush() HRESULT {
  73. ret, _, _ := procDwmFlush.Call()
  74. return HRESULT(ret)
  75. }
  76. func DwmGetColorizationColor(pcrColorization *uint32, pfOpaqueBlend *BOOL) HRESULT {
  77. ret, _, _ := procDwmGetColorizationColor.Call(
  78. uintptr(unsafe.Pointer(pcrColorization)),
  79. uintptr(unsafe.Pointer(pfOpaqueBlend)))
  80. return HRESULT(ret)
  81. }
  82. func DwmGetCompositionTimingInfo(hWnd HWND, pTimingInfo *DWM_TIMING_INFO) HRESULT {
  83. ret, _, _ := procDwmGetCompositionTimingInfo.Call(
  84. uintptr(hWnd),
  85. uintptr(unsafe.Pointer(pTimingInfo)))
  86. return HRESULT(ret)
  87. }
  88. func DwmGetTransportAttributes(pfIsRemoting *BOOL, pfIsConnected *BOOL, pDwGeneration *uint32) HRESULT {
  89. ret, _, _ := procDwmGetTransportAttributes.Call(
  90. uintptr(unsafe.Pointer(pfIsRemoting)),
  91. uintptr(unsafe.Pointer(pfIsConnected)),
  92. uintptr(unsafe.Pointer(pDwGeneration)))
  93. return HRESULT(ret)
  94. }
  95. // TODO: verify handling of variable arguments
  96. func DwmGetWindowAttribute(hWnd HWND, dwAttribute uint32) (pAttribute interface{}, result HRESULT) {
  97. var pvAttribute, pvAttrSize uintptr
  98. switch dwAttribute {
  99. case DWMWA_NCRENDERING_ENABLED:
  100. v := new(BOOL)
  101. pAttribute = v
  102. pvAttribute = uintptr(unsafe.Pointer(v))
  103. pvAttrSize = unsafe.Sizeof(*v)
  104. case DWMWA_CAPTION_BUTTON_BOUNDS, DWMWA_EXTENDED_FRAME_BOUNDS:
  105. v := new(RECT)
  106. pAttribute = v
  107. pvAttribute = uintptr(unsafe.Pointer(v))
  108. pvAttrSize = unsafe.Sizeof(*v)
  109. case DWMWA_CLOAKED:
  110. panic(fmt.Sprintf("DwmGetWindowAttribute(%d) is not currently supported.", dwAttribute))
  111. default:
  112. panic(fmt.Sprintf("DwmGetWindowAttribute(%d) is not valid.", dwAttribute))
  113. }
  114. ret, _, _ := procDwmGetWindowAttribute.Call(
  115. uintptr(hWnd),
  116. uintptr(dwAttribute),
  117. pvAttribute,
  118. pvAttrSize)
  119. result = HRESULT(ret)
  120. return
  121. }
  122. func DwmInvalidateIconicBitmaps(hWnd HWND) HRESULT {
  123. ret, _, _ := procDwmInvalidateIconicBitmaps.Call(
  124. uintptr(hWnd))
  125. return HRESULT(ret)
  126. }
  127. func DwmIsCompositionEnabled(pfEnabled *BOOL) HRESULT {
  128. ret, _, _ := procDwmIsCompositionEnabled.Call(
  129. uintptr(unsafe.Pointer(pfEnabled)))
  130. return HRESULT(ret)
  131. }
  132. func DwmModifyPreviousDxFrameDuration(hWnd HWND, cRefreshes int, fRelative bool) HRESULT {
  133. ret, _, _ := procDwmModifyPreviousDxFrameDuration.Call(
  134. uintptr(hWnd),
  135. uintptr(cRefreshes),
  136. uintptr(BoolToBOOL(fRelative)))
  137. return HRESULT(ret)
  138. }
  139. func DwmQueryThumbnailSourceSize(hThumbnail HTHUMBNAIL, pSize *SIZE) HRESULT {
  140. ret, _, _ := procDwmQueryThumbnailSourceSize.Call(
  141. uintptr(hThumbnail),
  142. uintptr(unsafe.Pointer(pSize)))
  143. return HRESULT(ret)
  144. }
  145. func DwmRegisterThumbnail(hWndDestination HWND, hWndSource HWND, phThumbnailId *HTHUMBNAIL) HRESULT {
  146. ret, _, _ := procDwmRegisterThumbnail.Call(
  147. uintptr(hWndDestination),
  148. uintptr(hWndSource),
  149. uintptr(unsafe.Pointer(phThumbnailId)))
  150. return HRESULT(ret)
  151. }
  152. func DwmRenderGesture(gt GESTURE_TYPE, cContacts uint, pdwPointerID *uint32, pPoints *POINT) {
  153. procDwmRenderGesture.Call(
  154. uintptr(gt),
  155. uintptr(cContacts),
  156. uintptr(unsafe.Pointer(pdwPointerID)),
  157. uintptr(unsafe.Pointer(pPoints)))
  158. return
  159. }
  160. func DwmSetDxFrameDuration(hWnd HWND, cRefreshes int) HRESULT {
  161. ret, _, _ := procDwmSetDxFrameDuration.Call(
  162. uintptr(hWnd),
  163. uintptr(cRefreshes))
  164. return HRESULT(ret)
  165. }
  166. func DwmSetIconicLivePreviewBitmap(hWnd HWND, hbmp HBITMAP, pptClient *POINT, dwSITFlags uint32) HRESULT {
  167. ret, _, _ := procDwmSetIconicLivePreviewBitmap.Call(
  168. uintptr(hWnd),
  169. uintptr(hbmp),
  170. uintptr(unsafe.Pointer(pptClient)),
  171. uintptr(dwSITFlags))
  172. return HRESULT(ret)
  173. }
  174. func DwmSetIconicThumbnail(hWnd HWND, hbmp HBITMAP, dwSITFlags uint32) HRESULT {
  175. ret, _, _ := procDwmSetIconicThumbnail.Call(
  176. uintptr(hWnd),
  177. uintptr(hbmp),
  178. uintptr(dwSITFlags))
  179. return HRESULT(ret)
  180. }
  181. func DwmSetPresentParameters(hWnd HWND, pPresentParams *DWM_PRESENT_PARAMETERS) HRESULT {
  182. ret, _, _ := procDwmSetPresentParameters.Call(
  183. uintptr(hWnd),
  184. uintptr(unsafe.Pointer(pPresentParams)))
  185. return HRESULT(ret)
  186. }
  187. func DwmSetWindowAttribute(hWnd HWND, dwAttribute uint32, pvAttribute LPCVOID, cbAttribute uint32) HRESULT {
  188. ret, _, _ := procDwmSetWindowAttribute.Call(
  189. uintptr(hWnd),
  190. uintptr(dwAttribute),
  191. uintptr(pvAttribute),
  192. uintptr(cbAttribute))
  193. return HRESULT(ret)
  194. }
  195. func DwmShowContact(dwPointerID uint32, eShowContact DWM_SHOWCONTACT) {
  196. procDwmShowContact.Call(
  197. uintptr(dwPointerID),
  198. uintptr(eShowContact))
  199. return
  200. }
  201. func DwmTetherContact(dwPointerID uint32, fEnable bool, ptTether POINT) {
  202. procDwmTetherContact.Call(
  203. uintptr(dwPointerID),
  204. uintptr(BoolToBOOL(fEnable)),
  205. uintptr(unsafe.Pointer(&ptTether)))
  206. return
  207. }
  208. func DwmTransitionOwnedWindow(hWnd HWND, target DWMTRANSITION_OWNEDWINDOW_TARGET) {
  209. procDwmTransitionOwnedWindow.Call(
  210. uintptr(hWnd),
  211. uintptr(target))
  212. return
  213. }
  214. func DwmUnregisterThumbnail(hThumbnailId HTHUMBNAIL) HRESULT {
  215. ret, _, _ := procDwmUnregisterThumbnail.Call(
  216. uintptr(hThumbnailId))
  217. return HRESULT(ret)
  218. }
  219. func DwmUpdateThumbnailProperties(hThumbnailId HTHUMBNAIL, ptnProperties *DWM_THUMBNAIL_PROPERTIES) HRESULT {
  220. ret, _, _ := procDwmUpdateThumbnailProperties.Call(
  221. uintptr(hThumbnailId),
  222. uintptr(unsafe.Pointer(ptnProperties)))
  223. return HRESULT(ret)
  224. }