Page 2 of 3

Posted: Sun Feb 11, 2007 11:53 pm
by SFSxOI
Thanks DoubleDutch,

PM me about the library. Its still in development but I like the gadget bluring idea of yours.

Posted: Mon Feb 12, 2007 1:11 am
by rsts
Yes, I've also installed Vista but since it doesn't recognize my sydata ide card I need to wait a bit before I move over to it (it's back to xp for now).

keep the demo's/code snipets coming :)

cheers

Posted: Mon Feb 12, 2007 7:49 pm
by fsw
I suppose this transparency stuff could be done with XP already:

Just enum all windows, get the hwnd and use SetLayeredAttribute on each of them.
After that set the top level window to not transparent.
Done.

Posted: Mon Feb 12, 2007 10:18 pm
by SFSxOI
fsw wrote:I suppose this transparency stuff could be done with XP already:

Just enum all windows, get the hwnd and use SetLayeredAttribute on each of them.
After that set the top level window to not transparent.
Done.
Yes, if transparency was all we were talking about then your correct, but there is much more.

Posted: Fri Feb 16, 2007 2:29 pm
by SFSxOI
Been playing around with the DwmRegisterThumbnail function. I've been using the example from the MSDN at http://msdn2.microsoft.com/en-us/library/aa969541.aspx
has pictures and everything if you want to take a look. Anyway, i've discovered something interesting, actually a few things, in the MSDN. First, the example code is not correct, it uses a reserved parameter in the DwmRegisterThumbnail function that did not make it into the Vista release as a functioning member. You can still put it in the function as a parameter and not get any errors, but the function only takes three parameters and thats it. Second i've discovered the that the DwmUpdateThumbnailProperties function doesn't seem to want to work with PureBasic no matter what, its supposed to return S_OK (a 0) if the function call is sucessful but it seems its not as reliable as it should be, and i'm not sure I've implemented it correctly in the code i had posted here ....Sooo...i'm going to remove the code example for DWMThumbnail I had in this post until I can figure out whats going on with it.

Posted: Fri Feb 16, 2007 8:03 pm
by SFSxOI
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

Posted: Sat Feb 17, 2007 2:29 am
by SFSxOI
OK, heres another one using the DwmSetWindowAttribute function. This will control non-client area rendering and produce a window without a border or menu bar that you can still click on and move around with the mouse - drag it just like any other window, only the window client area is rendered. This uses the wrapper/library I posted earlier in this thread.

Code: Select all

#Style = #WS_VISIBLE | #WS_SYSMENU

Enumeration ;DWMNCRENDERINGPOLICY
  #DWMNCRP_USEWINDOWSTYLE
  #DWMNCRP_DISABLED
  #DWMNCRP_ENABLED
  #DWMNCRP_LAST
EndEnumeration

Enumeration ;DWMWINDOWATTRIBUTE
#DWMWA_NCRENDERING_ENABLED = 1
#DWMWA_NCRENDERING_POLICY
#DWMWA_TRANSITIONS_FORCEDISABLED
#DWMWA_ALLOW_NCPAINT
#DWMWA_CAPTION_BUTTON_BOUNDS
#DWMWA_NONCLIENT_RTL_LAYOUT
#DWMWA_FORCE_ICONIC_REPRESENTATION
#DWMWA_FLIP3D_POLICY
#DWMWA_EXTENDED_FRAME_BOUNDS
#DWMWA_LAST
EndEnumeration

Procedure DisableNCRendering(hWnd.l)

ncrp=#DWMNCRP_DISABLED

    ;disable non-client area rendering on window
    ; we use the wrapped function
    If V_DwmSetWindowAttribute(hWnd, #DWMWA_NCRENDERING_POLICY, @ncrp, SizeOf(ncrp)) = #S_OK
    
    ;do more stuff
    EndIf 
  ProcedureReturn #S_OK
EndProcedure

Procedure WindowCallback(Window, Message, wParam, lParam) 
  Select Message 
    Case #WM_CLOSE 
      If MessageBox_(Window, "You sure?", "EXIT", #MB_YESNO) = #IDYES 
        DestroyWindow_(Window) 
      Else 
        Result  = 0 
      EndIf 
    Case #WM_DESTROY 
      PostQuitMessage_(0) 
      Result = 0 
    Default 
      Result = DefWindowProc_(Window, Message, wParam, lParam) 
  EndSelect 
  ProcedureReturn Result 
EndProcedure

WindowClass.s  = "dwmwclass" 
wc.WNDCLASSEX 
wc\cbSize  = SizeOf(WNDCLASSEX) 
wc\lpfnWndProc  = @WindowCallback() 
wc\hCursor  = LoadCursor_(0, #IDC_ARROW) 
wc\hbrBackground  = #COLOR_WINDOW+1  
wc\lpszClassName  = @WindowClass 
RegisterClassEx_(@wc)

hWnd.l = CreateWindowEx_(#WS_EX_DLGMODALFRAME, WindowClass, "DWM_Test", #Style, 10, 10, 300, 300, 0, 0, 0, 0)
Debug DisableNCRendering(hWnd.l)

While GetMessage_(msg.MSG, #Null, 0, 0 ) 
  TranslateMessage_(msg) 
  DispatchMessage_(msg) 
Wend
You can do some tricks with this and DWM also, like a totally invisible window for example by setting the:
wc.WNDCLASSEX
wc\hbrBackground = #Null ; instead of COLOR_WINDOW+1

and ...you will get a totally invisible window, no borders or anything. You can paint on and render to this invisible window also so it looks like your just drawing on the desktop or your bitmaps and .png's are just there with nothing behind them. Its the same code as above but with just that one change to wc\hbrBackground = #Null

How about your own custom install splash screens with your 3D graphics and buttons and things just appearing to float on top of the desktop (really attached to the invisible window) and (appearing to be) free of the traditional rectangular background.

here is a pic of what non-client rendering does:
http://www.123pichosting.com/viewer.php ... render.JPG
Of course i couldn't supply a pic of the invisible window because its...well...invisible :)

And here is the code that produced the above pic:

Code: Select all

#Style = #WS_VISIBLE | #WS_SYSMENU
#DWM_BB_ENABLE = 1
#DWM_BB_BLURREGION = 2
#DWM_BB_TRANSITIONONMAXIMIZED = 4

Enumeration ;DWMWINDOWATTRIBUTE
#DWMWA_NCRENDERING_ENABLED = 1
#DWMWA_NCRENDERING_POLICY
#DWMWA_TRANSITIONS_FORCEDISABLED
#DWMWA_ALLOW_NCPAINT
#DWMWA_CAPTION_BUTTON_BOUNDS
#DWMWA_NONCLIENT_RTL_LAYOUT
#DWMWA_FORCE_ICONIC_REPRESENTATION
#DWMWA_FLIP3D_POLICY
#DWMWA_EXTENDED_FRAME_BOUNDS
#DWMWA_LAST
EndEnumeration

Enumeration ;DWMNCRENDERINGPOLICY
  #DWMNCRP_USEWINDOWSTYLE
  #DWMNCRP_DISABLED
  #DWMNCRP_ENABLED
  #DWMNCRP_LAST
EndEnumeration

Structure DWM_BLURBEHIND
  dwFlags.l
  fEnable.b
  hRgnBlur.l
  fTransitionOnMaximized.b
EndStructure

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

Procedure DisableNCRendering(hWnd.l)

ncrp=#DWMNCRP_DISABLED

    ;disable non-client area rendering on window
    If V_DwmSetWindowAttribute(hWnd, #DWMWA_NCRENDERING_POLICY, @ncrp, SizeOf(ncrp)) = #S_OK
    
    ;do more stuff
    EndIf 
  ProcedureReturn #S_OK
EndProcedure

Procedure WindowCallback(Window, Message, wParam, lParam) 
  Select Message 
    Case #WM_CLOSE 
      If MessageBox_(Window, "You sure?", "EXIT", #MB_YESNO) = #IDYES 
        DestroyWindow_(Window) 
      Else 
        Result  = 0 
      EndIf 
    Case #WM_DESTROY 
      PostQuitMessage_(0) 
      Result = 0 
    Default 
      Result = DefWindowProc_(Window, Message, wParam, lParam) 
  EndSelect 
  ProcedureReturn Result 
EndProcedure

WindowClass.s  = "dwmwclass" 
wc.WNDCLASSEX 
wc\cbSize  = SizeOf(WNDCLASSEX) 
wc\lpfnWndProc  = @WindowCallback() 
wc\hCursor  = LoadCursor_(0, #IDC_ARROW) 
wc\hbrBackground  = #Null
wc\lpszClassName  = @WindowClass 
RegisterClassEx_(@wc)

hWnd.l = CreateWindowEx_(#WS_EX_DLGMODALFRAME, WindowClass, "DWM_Test", #Style, 10, 10, 300, 300, 0, 0, 0, 0)
DisableNCRendering(hWnd)
DwmDemoBlurBehindWindow(hWnd)

While GetMessage_(msg.MSG, #Null, 0, 0 ) 
  TranslateMessage_(msg) 
  DispatchMessage_(msg) 
Wend
Notice here i'm once again using the 'wc\hbrBackground = #Null'. This window has blur behind applied so you can see the non-client rendering effect - notice no border or title bar visible, but if you click in the upper right corner the X will appear. If I wasn't applying blurbehind the window would be invisible.

Posted: Mon Feb 19, 2007 2:25 am
by SFSxOI
Someone asked a question previously about GDI in Vista. GDI++ is alive and well in Vista, but it got a lot eaisier to use considering the uxtheme functions in Vista and makes it a whole lot eaisier to do some GDI type things without using GDI directly and a whole lot simpler code. Here are some pics using the uxtheme functions in uxtheme.dll, the following functions were used from uxtheme.dll:

BeginBufferedPaint
GetBufferedPaintTargetRect
BufferedPaintSetAlpha

Here is the initial effect of the uxtheme coding in DWM on the menu bar and border
http://www.123pichosting.com/viewer.php ... e_ice1.JPG

Kind of a neat effect, same as above but now that the window is over another window the border and title bar changes color to black when the window becomes the foreground window. (Not actually black, more of a very dark grey)
http://www.123pichosting.com/viewer.php ... e_ice2.JPG

Here - painting the client part of the window
http://www.123pichosting.com/viewer.php ... e_ice3.JPG

Here - painted the client again
http://www.123pichosting.com/viewer.php ... e_ice4.JPG

Here is a glass window effect using the alpha setting for the BufferedPaintSetAlpha uxtheme function and the DwmEnableBlurBehindWindow function for DWM. This is the 'clear' glass effect (even though its really 'frosted' or translucent), thats the desktop behind it.
http://www.123pichosting.com/viewer.php ... e_ice5.JPG

Can also change other system windows, see the menubar and frame and the desktop icons behind it.
http://www.123pichosting.com/viewer.php?id=3555IE1.jpg

The above windows were created using the API and not PureBasic commands. Windows produced with PurBasic commands seem to balk at allowing the Vista DWM/uxtheme to 'repaint' them in most cases.

seems this thread has made it to other places in the world also:
http://forum.games-creators.org/showthread.php?p=41897

Posted: Thu Feb 22, 2007 1:15 pm
by va!n

Code: Select all

; PB_DWM_IsCompositionEnabled 
Procedure IsCompositionEnabled() 

Lib = LoadLibrary_("dwmapi.dll") 

  If Lib 
    *pAfunc = GetProcAddress_(Lib, "DwmIsCompositionEnabled") ; get pointer to function 
    CallFunctionFast(*pAfunc, *pfEnabled.b) ; call the function 
    FreeLibrary_(Lib) 
  EndIf 

ProcedureReturn ; returns 1 if DWM composition enabled, 0 if not 

EndProcedure 

Debug IsCompositionEnabled() 
Whenever i try to compile one of the posted examples using CallFunctionFast() under Vista Ulimate, i get an Invalid Memory Access error O.O

Posted: Thu Feb 22, 2007 3:58 pm
by SFSxOI
Try this

Code: Select all

; PB_DWM_IsCompositionEnabled 
Procedure IsCompositionEnabled() 

Lib = LoadLibrary_("dwmapi.dll") 

  If Lib 
    *pAfunc = GetProcAddress_(Lib, "DwmIsCompositionEnabled") ; get pointer to function
 pfEnabled.b = #False
    If CallFunctionFast(*pAfunc, @pfEnabled) <> pfEnabled ; call the function
    enabled.l = #True
    EndIf
  FreeLibrary_(Lib)
  EndIf
 

ProcedureReturn enabled ; returns 1 if DWM composition enabled, 0 if not 

EndProcedure 

Debug IsCompositionEnabled() 
The example I posted previously was in error. I though I'd corrected it but evidently I didn't, I copy and pasted the wrong code. I'll change it a little later when I get home. ' sorry bout that. I've got a library/wrapper working for DWM if you want to use it, things will be a whole lot eaisier. Its still being tested but everything seems to work now, if you want the beta of it PM me with an email and i'll send it to you. I plan on finishing it and posting it in the next few days also.

pfEnabled will be either true or false depending on if composition is enabled or not.

Posted: Thu Feb 22, 2007 9:10 pm
by va!n
does not work too.. illegal mem access...

Posted: Thu Feb 22, 2007 10:22 pm
by SFSxOI
va!n wrote:does not work too.. illegal mem access...
OK, here it is for real this time :)

Code: Select all

Procedure IsCompositionEnabled() 

Lib = LoadLibrary_("dwmapi.dll") 

  If Lib 
    *pAfunc = GetProcAddress_(Lib, "DwmIsCompositionEnabled") ; get pointer to function 
 ;pfEnabled.b = #False 
    If CallFunctionFast(*pAfunc, pfEnabled) 
    enabled.b = #True 
    EndIf 
  FreeLibrary_(Lib) 
  EndIf 
  
ProcedureReturn enabled ; returns 1 if DWM composition enabled, 0 if not 

EndProcedure
I'm using a wrapper now so I got it mixed up between the wrapper function I use now and having to open up a library in code. Got home and took a look, the above will work if you open the library in your code. here it is with the wrapper i'm using:

Code: Select all

Procedure IsCompositionEnabledDWM()
isenabled.b = 0
outrslt.b = DwmIsCompositionEnabled(@isenabled) <> isenabled
ProcedureReturn outrslt
EndProcedure
So much eaisier with the wrapper. Also, the MSDN has a slight error possibly for this function. It lists the function like this:

Code: Select all

HRESULT DwmIsCompositionEnabled(BOOL *pfEnabled)

which kind of indicates the way you had it with *pfEnabled, but.....
In PureBasic it doesn't work if you do *pfEnabled but if you do @pfEnabled it works OK. Maybe there is a mistake in the MSDN?

Posted: Sun Feb 25, 2007 2:16 am
by SFSxOI
OK, finally finished up the wrapper/library. Here is the link for the download:

http://rapidshare.com/files/18271005/vistadwm.zip.html

It will make things a whole lot eaisier. Instructions, examples, an include file, and the wrapper/librray file is in the .zip

Code: Select all

Structure MARGINS
  cxLeftWidth.l
  cxRightWidth.l
  cyTopHeight.l
  cyBottomHeight.l
EndStructure

hwnd.l = OpenWindow(0,100,100,500,400, "Test_V_DWM", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)

CreateGadgetList(hwnd)
  ExplorerListGadget(1, 50, 50, 400, 200, "C:\", #PB_Explorer_GridLines | #PB_Explorer_BorderLess)
  ;helper function
  If V_IsCompositionEnabledDWM()
    Margin.MARGINS
    Margin\cxLeftWidth = 51
    Margin\cxRightWidth = 51
    Margin\cyTopHeight = 51
    Margin\cyBottomHeight = 151
    ; wrapped function
    SetWindowColor(0, #Black)
    DwmExtendFrameIntoClientArea(hwnd, @Margin) 
  EndIf
 
Repeat 
    Event = WindowEvent() 
    If Event
    Else  
      Delay(1)
    EndIf 
  Until Event = #PB_Event_CloseWindow
http://www.123pichosting.com/viewer.php ... ture_x.JPG

Posted: Wed Feb 28, 2007 11:31 pm
by SFSxOI
One of the problems with trying to render something on glass is the transparency factor. It seems that using a PureBasic text gadget doesn't work if the area behind it has the Vista DWM glass effect 'blurring' (its really translucency). The gadget shows up but the fonts look terrible you can see thru them, it just doesn't look good at all. I knew you could draw text on glass using the way that Vista does it which is by using the uxtheme API DrawThemeTextEx but I wanted to do it with methods people were already familiar with which was GDI. To top it off, for some reason white is the most difficult color for glass also.

I came across this article at:
http://www.codeproject.com/vista/texton ... ct=1685558 that said drawing text on glass could be accomplished with GDI Plus. I set out to try it, but the answer I was looking for was right here in the forum all the time with a GDI Plus wrapper and library by flype.

So I put two and two together...and...heres how to draw text on DWM glass:

Code: Select all

XIncludeFile "gdiplus.pbi"


*token = Gdiplus_New(1, @DebugEventProc())

hwnd.l = OpenWindow(0, 0, 0, 640, 480, "DWM Text On Glass", #PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_ScreenCentered) 
 If hwnd  
  Repeat
    
    Select WaitWindowEvent()
      
      Case #PB_Event_Repaint
        If Gdiplus_StartDrawing(WindowOutput(0))
          Gdiplus_Cls()
          SetWindowColor(0, ARGB(#Black, 0)) 
          V_SheetGlassClientDWM(hwnd) 
          Gdiplus_String("This is an example of...", 80, 40, 600, 200, "Arial", 20, #FontStyleBold|#FontStyleUnderline, ARGB(#White, 254), ARGB(#White, 254))
          Gdiplus_String("DWM Text On Glass with GDI+ and PureBasic", 100, 140, 500, 200, "Arial", 20, #FontStyleBold|#FontStyleUnderline, ARGB(#White, 254), ARGB(#White, 254))
          Gdiplus_String("...that works", 100, 200, 400, 200, "Arial", 20, #FontStyleBold|#FontStyleUnderline, ARGB(#White, 254), ARGB(#White, 254)) 
          Gdiplus_Line(350, 280, 230, 280, 20, ARGB(#Yellow), 18, 18)
          Gdiplus_StopDrawing() 
        EndIf
        
      Case #PB_Event_CloseWindow
        Break
        
    EndSelect
  
  ForEver
  
EndIf

Gdiplus_Del(0)
Gdiplus_Del(*token)
And...heres what it looks like using the work by flype with the code above:
http://www.123pichosting.com/viewer.php ... _glass.jpg

The GDI code is by flype from one of his examples, I just used what he posted.

The two lines:

Code: Select all

SetWindowColor(0, ARGB(#Black, 0)) 
V_SheetGlassClientDWM(hwnd)
 
You have to set the window color background to ARGB black to have the sheet glass effect work properly, the V_SheetGlassClientDWM(hwnd) command is from the wrapper/library I posted previously. The pic also shows a little bit of graphics with the fat yellow line. Now if I can just figure out how to get PureBasic gadgets into a graphics path and apply ARGB to them....

The same basic problem exists for graphics on glass, but once again flype's library to the rescue. Here is an example of drawing an image on glass using the flype GDI Plus library:

Code: Select all

XIncludeFile "gdiplus.pbi"

Define *token, *gfx, *img1, width.l, height.l

hwnd.l = OpenWindow(0, 0, 0, 640, 480, "DWM Text On Glass", #PB_Window_SystemMenu|#PB_Window_ScreenCentered) 
  If hwnd
  *token = Gdiplus_New()
  
  GdipCreateBitmapFromFile("1.wmf", @*img1)
    
  If *img1
    
    GdipGetImageWidth(*img1, @width)
    GdipGetImageHeight(*img1, @height)
    
    GdipCreateFromHWND(WindowID(0), @*gfx)
    
    Repeat
      
      Select WaitWindowEvent()
        
        Case #PB_Event_Repaint
        Gdiplus_Cls()
        SetWindowColor(0, ARGB(#Black, 0))
        V_SheetGlassClientDWM(hwnd)
          GdipDrawImageI(*gfx, *img1, 0, 0)
                          
        Case #PB_Event_CloseWindow
          Break
          
      EndSelect
      
    ForEver
    
    GdipDisposeImage(*img1)
    GdipDeleteGraphics(*gfx)
    
  EndIf
  
  GdiplusShutdown(*token)
  
EndIf
and here is a pic with an image on glass: http://www.123pichosting.com/viewer.php ... _glass.jpg

Once again, i'm using flype's GDI Plus library and wrapper (and even the pics he supplied with his examples - nice doggie :) ) so the credit for this solution goes to him, its his code and i just adapted it for Vista DWM use by adding the SetWindowColor(0, ARGB(#Black, 0)) and V_SheetGlassClientDWM(hwnd) commands.

Posted: Wed Mar 07, 2007 1:33 am
by SFSxOI
Someone asked me about multiple graphics on glass. I couldn't come up with a really good streamlined version of this but here is one way to to it:

Code: Select all

;uses the flype DGI Plus wrapper at http://purebasic.myftp.org/?filename=files/44/PB4_UserLibs/UserLib_PB40_libgdiplus.zip

XIncludeFile "gdiplus.pbi"

Define *token, *gfx, *img1, *img2, *img3, *img4, *img5, *img6, *img7
Define widtha.l, widthb.l, widthc.l, widthd.l, widthe.l, widthf.l, widthg.l
Define heighta.l, heightb.l, heightc.l, heightd.l, heighte.l, heightf.l, heightg.l

hwnd.l = OpenWindow(0, 0, 0, 640, 480, "DWM Graphics On Glass", #PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_ScreenCentered) 
  If hwnd
  *token = Gdiplus_New()
  ; startup GDI Plus
  ; create bitmaps
  GdipCreateBitmapFromFile("twin.png", @*img1)
  GdipCreateBitmapFromFile("paintbrush.png", @*img2)
  GdipCreateBitmapFromFile("tophat.png", @*img3)
  GdipCreateBitmapFromFile("light.png", @*img4)
  GdipCreateBitmapFromFile("wv_home_nav_pearl.png", @*img5)
  GdipCreateBitmapFromFile("ie7.png", @*img6)
  GdipCreateBitmapFromFile("Doc11.png", @*img7)
    
  If *img1
    ;get the image width & height
    GdipGetImageWidth(*img1, @widtha)
    GdipGetImageHeight(*img1, @heighta)
    GdipGetImageWidth(*img2, @widthb)
    GdipGetImageHeight(*img2, @heightb)
    GdipGetImageWidth(*img3, @widthc)
    GdipGetImageHeight(*img3, @heightc)
    GdipGetImageWidth(*img4, @widthd)
    GdipGetImageHeight(*img4, @heightd)
    GdipGetImageWidth(*img5, @widthe)
    GdipGetImageHeight(*img5, @heighte)
    GdipGetImageWidth(*img6, @widthf)
    GdipGetImageHeight(*img6, @heightf)
    GdipGetImageWidth(*img7, @widthg)
    GdipGetImageHeight(*img7, @heightg)
    ; graphics path
    GdipCreateFromHWND(WindowID(0), @*gfx)
    
    Repeat
      ; draw in the repaint
      Select WaitWindowEvent()
        
        Case #PB_Event_Repaint
        Gdiplus_Cls()
        SetWindowColor(0, ARGB(#Black, 0))
        ;the wrapper/library function for sheet glass
        V_SheetGlassClientDWM(hwnd)
          ;draw the graphics
          GdipDrawImageI(*gfx, *img1, 250, 5)
          GdipDrawImageI(*gfx, *img2, 200, 150)
          GdipDrawImageI(*gfx, *img3, 50, 200)
          GdipDrawImageI(*gfx, *img4, 420, 210)
          GdipDrawImageI(*gfx, *img5, 440, 5)
          GdipDrawImageI(*gfx, *img6, 10, 10)
          GdipDrawImageI(*gfx, *img7, 45, 420)
                          
        Case #PB_Event_CloseWindow
          Break
          
      EndSelect
      
    ForEver
    
    GdipDisposeImage(*img1)
    GdipDisposeImage(*img2)
    GdipDisposeImage(*img3)
    GdipDisposeImage(*img4)
    GdipDisposeImage(*img5)
    GdipDisposeImage(*img6)
    GdipDisposeImage(*img7)
    GdipDeleteGraphics(*gfx)
    
  EndIf
  
  GdiplusShutdown(*token)
  
EndIf
Still using the flype wrapper from:
http://purebasic.myftp.org/?filename=fi ... diplus.zip

and...using a wrapper for DWM

here's a pic:

http://www.123pichosting.com/viewer.php ... aphics.jpg

Forget where I got the graphics from, had them for a while, but you can substitute your own. I'm building my own push buttons for glass (the PureBasic gadgets look terrible on glass)