Here is wrapper/library code for the dwmapi.dll that will make it a lot eaisier for you to use DWM in your own code. Just copy to a .pb file and then use TailBite on it to produce a library file that will be placed in your C:\Program Files\PureBasic\PureLibraries\UserLibraries folder.
You will see a 'V_' in front of the actual command, I did this while I was experimenting with Vista DWM to quickly spot the DWM commands in a lot of code lines, you can change them back to the original dwmapi.dll command if you want. You can call the functions directly just like they were PureBasic commands...e.g...V_DwmEnableBlurBehindWindow(hWnd.l,pBlurBehind.l)
Leave this whole thing intact, don't remove any of the private functions. While you can't use the private functions directly, they are used internally to make the other stuff work.
Code: Select all
; Windows Vista DWM Wrapper/Library
; use Tailbite
; do not remove any Private Functions, they are needed.
; Declair Variables
Global V_DwmAttachMilContent.l
Global V_DwmDefWindowProc.l
Global V_DwmDetachMilContent.l
Global V_DwmEnableBlurBehindWindow.l
Global V_DwmEnableComposition.l
Global V_DwmEnableMMCSS.l
Global V_DwmExtendFrameIntoClientArea.l
Global V_DwmFlush.l
Global V_DwmGetColorizationColor.l
Global V_DwmGetCompositionTimingInfo.l
Global V_DwmGetGraphicsStreamClient.l
Global V_DwmGetGraphicsStreamTransformHint.l
Global V_DwmGetTransportAttributes.l
Global V_DwmGetWindowAttribute.l
Global V_DwmIsCompositionEnabled.l
Global V_DwmModifyPreviousDxFrameDuration.l
Global V_DwmQueryThumbnailSourceSize.l
Global V_DwmRegisterThumbnail.l
Global V_DwmSetDxFrameDuration.l
Global V_DwmSetPresentParameters.l
Global V_DwmSetWindowAttribute.l
Global V_DwmUnregisterThumbnail.l
Global V_DwmUpdateThumbnailProperties.l
; Init the functions
ProcedureDLL dwmapi_Init()
Shared DLL.l
DLL = LoadLibrary_("dwmapi.dll")
If DLL
V_DwmAttachMilContent = GetProcAddress_(DLL, "DwmAttachMilContent")
V_DwmDefWindowProc = GetProcAddress_(DLL, "DwmDefWindowProc")
V_DwmDetachMilContent = GetProcAddress_(DLL, "DwmDetachMilContent")
V_DwmEnableBlurBehindWindow = GetProcAddress_(DLL, "DwmEnableBlurBehindWindow")
V_DwmEnableComposition = GetProcAddress_(DLL, "DwmEnableComposition")
V_DwmEnableMMCSS = GetProcAddress_(DLL, "DwmEnableMMCSS")
V_DwmExtendFrameIntoClientArea = GetProcAddress_(DLL, "DwmExtendFrameIntoClientArea")
V_DwmFlush = GetProcAddress_(DLL, "DwmFlush")
V_DwmGetColorizationColor = GetProcAddress_(DLL, "DwmGetColorizationColor")
V_DwmGetCompositionTimingInfo = GetProcAddress_(DLL, "DwmGetCompositionTimingInfo")
V_DwmGetGraphicsStreamClient = GetProcAddress_(DLL, "DwmGetGraphicsStreamClient")
V_DwmGetGraphicsStreamTransformHint = GetProcAddress_(DLL, "DwmGetGraphicsStreamTransformHint")
V_DwmGetTransportAttributes = GetProcAddress_(DLL, "DwmGetTransportAttributes")
V_DwmGetWindowAttribute = GetProcAddress_(DLL, "DwmGetWindowAttribute")
V_DwmIsCompositionEnabled = GetProcAddress_(DLL, "DwmIsCompositionEnabled")
V_DwmModifyPreviousDxFrameDuration = GetProcAddress_(DLL, "DwmModifyPreviousDxFrameDuration")
V_DwmQueryThumbnailSourceSize = GetProcAddress_(DLL, "DwmQueryThumbnailSourceSize")
V_DwmRegisterThumbnail = GetProcAddress_(DLL, "DwmRegisterThumbnail")
V_DwmSetDxFrameDuration = GetProcAddress_(DLL, "DwmSetDxFrameDuration")
V_DwmSetPresentParameters = GetProcAddress_(DLL, "DwmSetPresentParameters")
V_DwmSetWindowAttribute = GetProcAddress_(DLL, "DwmSetWindowAttribute")
V_DwmUnregisterThumbnail = GetProcAddress_(DLL, "DwmUnregisterThumbnail")
V_DwmUpdateThumbnailProperties = GetProcAddress_(DLL, "DwmUpdateThumbnailProperties")
EndIf
EndProcedure
; End function init
ProcedureDLL dwmapi_End()
Shared DLL.l
FreeLibrary_(DLL)
EndProcedure
;
;All the functions
;
;Private Function
ProcedureDLL.l V_DwmAttachMilContent(a.l)
ProcedureReturn CallFunctionFast(V_DwmAttachMilContent,a)
EndProcedure
; callable function
ProcedureDLL.l V_DwmDefWindowProc(hWnd.l,msg.l,wParam.l,lParam.l,plResult.l)
ProcedureReturn CallFunctionFast(V_DwmDefWindowProc,hWnd,msg,wParam,lParam,plResult)
EndProcedure
;Private Function
ProcedureDLL.l V_DwmDetachMilContent(a.l)
ProcedureReturn CallFunctionFast(V_DwmDetachMilContent,a)
EndProcedure
; callable function
ProcedureDLL.l V_DwmEnableBlurBehindWindow(hWnd.l,pBlurBehind.l)
ProcedureReturn CallFunctionFast(V_DwmEnableBlurBehindWindow,hWnd,pBlurBehind)
EndProcedure
; callable function
ProcedureDLL.l V_DwmEnableComposition(a.l) ; #DWM_EC_ENABLECOMPOSITION or #DWM_EC_DISABLECOMPOSITION
ProcedureReturn CallFunctionFast(V_DwmEnableComposition,a)
EndProcedure
; callable function
ProcedureDLL.l V_DwmEnableMMCSS(fEnableMMCSS.l)
ProcedureReturn CallFunctionFast(V_DwmEnableMMCSS,fEnableMMCSS)
EndProcedure
; callable function
ProcedureDLL.l V_DwmExtendFrameIntoClientArea(hWnd.l,pMarInset.l)
ProcedureReturn CallFunctionFast(V_DwmExtendFrameIntoClientArea,hWnd,pMarInset)
EndProcedure
; callable function
ProcedureDLL.l V_DwmFlush(); no parameter, just call
ProcedureReturn CallFunctionFast(V_DwmFlush)
EndProcedure
; callable function
ProcedureDLL.l V_DwmGetColorizationColor(pcrColorization.l,pfOpaqueBlend.l)
ProcedureReturn CallFunctionFast(V_DwmGetColorizationColor,pcrColorization,pfOpaqueBlend)
EndProcedure
; callable function
ProcedureDLL.l V_DwmGetCompositionTimingInfo(hWnd.l,pTimingInfo.l)
ProcedureReturn CallFunctionFast(V_DwmGetCompositionTimingInfo,hWnd,pTimingInfo)
EndProcedure
;Private Function
ProcedureDLL.l V_DwmGetGraphicsStreamClient(a.l,b.l)
ProcedureReturn CallFunctionFast(V_DwmGetGraphicsStreamClient,a,b)
EndProcedure
;Private Function
ProcedureDLL.l V_DwmGetGraphicsStreamTransformHint(a.l,b.l)
ProcedureReturn CallFunctionFast(V_DwmGetGraphicsStreamTransformHint,a,b)
EndProcedure
;Private Function
ProcedureDLL.l V_DwmGetTransportAttributes(a.l,b.l,c.l)
ProcedureReturn CallFunctionFast(V_DwmGetTransportAttributes,a,b,c)
EndProcedure
; callable function
ProcedureDLL.l V_DwmGetWindowAttribute(hWnd.l,dwAttribute.l,pvAttribute.l,cbAttribute.l)
ProcedureReturn CallFunctionFast(V_DwmGetWindowAttribute,hWnd,dwAttribute,pvAttribute,cbAttribute)
EndProcedure
; callable function
ProcedureDLL.l V_DwmIsCompositionEnabled(pfEnabled.l)
ProcedureReturn CallFunctionFast(V_DwmIsCompositionEnabled,pfEnabled)
EndProcedure
; callable function
ProcedureDLL.l V_DwmModifyPreviousDxFrameDuration(hWnd.l,cRefreshes.l,fRelative.l)
ProcedureReturn CallFunctionFast(V_DwmModifyPreviousDxFrameDuration,hWnd,cRefreshes,fRelative)
EndProcedure
; callable function
ProcedureDLL.l V_DwmQueryThumbnailSourceSize(hThumbnail.l,pSize.l)
ProcedureReturn CallFunctionFast(V_DwmQueryThumbnailSourceSize,hThumbnail,pSize)
EndProcedure
; callable function
ProcedureDLL.l V_DwmRegisterThumbnail(hwndDestination.l,hwndSource.l,phThumbnailId.l)
ProcedureReturn CallFunctionFast(V_DwmRegisterThumbnail,hwndDestination,hwndSource,phThumbnailId)
EndProcedure
; callable function
ProcedureDLL.l V_DwmSetDxFrameDuration(hWnd.l,cRefreshes.l)
ProcedureReturn CallFunctionFast(V_DwmSetDxFrameDuration,hWnd,cRefreshes)
EndProcedure
; callable function
ProcedureDLL.l V_DwmSetPresentParameters(hWnd.l,pPresentParams.l)
ProcedureReturn CallFunctionFast(V_DwmSetPresentParameters,hWnd,pPresentParams)
EndProcedure
; callable function
ProcedureDLL.l V_DwmSetWindowAttribute(hWnd.l,dwAttribute.l,pvAttribute.l,cbSize.l)
ProcedureReturn CallFunctionFast(V_DwmSetWindowAttribute,hWnd,dwAttribute,pvAttribute,cbSize)
EndProcedure
; callable function
ProcedureDLL.l V_DwmUnregisterThumbnail(hThumbnailId.l)
ProcedureReturn CallFunctionFast(V_DwmUnregisterThumbnail,hThumbnailId)
EndProcedure
; callable function
ProcedureDLL.l V_DwmUpdateThumbnailProperties(hThumbnailId.l,ptnProperties.l)
ProcedureReturn CallFunctionFast(V_DwmUpdateThumbnailProperties,hThumbnailId,ptnProperties)
EndProcedure
and...here is an example of using the wrapper after you Tailbite it:
Code: Select all
#DWM_BB_ENABLE = 1
#DWM_BB_BLURREGION = 2
#DWM_BB_TRANSITIONONMAXIMIZED = 4
Structure DWM_BLURBEHIND
dwFlags.l
fEnable.b
hRgnBlur.l
fTransitionOnMaximized.b
EndStructure
; the helper function
Procedure DwmDemoBlurBehindWindow(hWnd.l, enable.b = #True, region.l = 0, transitionOnMaximized.b = #False)
blurBehind.DWM_BLURBEHIND
blurBehind\dwFlags = #DWM_BB_ENABLE | #DWM_BB_TRANSITIONONMAXIMIZED
blurBehind\fEnable = enable
blurBehind\fTransitionOnMaximized = transitionOnMaximized
If (enable And 0) <> region
blurBehind\dwFlags = #DWM_BB_BLURREGION
blurBehind\hRgnBlur = region
EndIf
V_DwmEnableBlurBehindWindow(hWnd, @blurBehind) ;the wrapped function
EndProcedure
hWnd.l = OpenWindow(0,100,100,300,300, "Test_V_DWM", #PB_Window_SystemMenu)
rgbcolor = RGB(255, 000, 000)
SetWindowColor(0, rgbcolor)
DwmDemoBlurBehindWindow(hWnd.l, #True, 0, #False)
; or you can just pass the hWnd to the helper function like this
;if you don't want to change anything else
;DwmDemoBlurBehindWindow(hWnd.l)
;
Repeat
Event = WindowEvent()
If Event
Else
Delay(1)
EndIf
Until Event = #PB_Event_CloseWindow