DWM ( Desktop Windows Manager ) Sample Code

DWM ( Desktop Windows Manager ) Sample Code

Postby Jimmy » Fri Aug 26, 2022 6:59 am

hi,

i have made a Sample for FiveWin using DWM
Image

i use DllCall , like Xbase++ , as i´m not a "C" Programmer
i "think" FiveWin have HB_FUNC() for it but i´m not sure how Function Name is
Code: Select all  Expand view
*+--------------------------------------------------------------------
*+
*+ Source Module => c:\fwh\0\DWM\FWDWM.PRG
*+
*+    Copyright(C) 1983-2022 by Auge & Ohr
*+
*+    Functions: Procedure Main()
*+               Function DwmEnableBlurBehindWindow()
*+               Function DwmExtendFrameIntoClientArea()
*+               Function CreateRectRgn()
*+               Function CreateEllipticRgn()
*+               Function CreateRoundRectRgn()
*+               Function SetWindowRgn()
*+
*+    Reformatted by Click! 2.05.40 on Aug-26-2022 at  8:40 am
*+
*+--------------------------------------------------------------------

#include "fivewin.ch"

#require "hbxpp"
#include "common.ch"
#include "dll.ch"

#define DLL_CDECL                   0x08
#define DLL_STDCALL                 0x20
#define DLL_SYSTEM                  0x04
#if defined( __PLATFORM__WINDOWS )
#define DLL_OSAPI                   DLL_STDCALL
#elif defined( __PLATFORM__OS2 )
#define DLL_OSAPI                   DLL_SYSTEM
#else
#define DLL_OSAPI                   DLL_CDECL
#endif

#define DWM_BB_ENABLE                  0x00000001
#define DWM_BB_BLURREGION              0x00000002
#define DWM_BB_TRANSITIONONMAXIMIZED   0x00000004

STATIC cVar1 := "Name    "
STATIC cVar2 := "Channel "
STATIC cVar3 := "TV ID   "
STATIC cVar4 := "Logo    "
STATIC cVar5 := "URL     "
STATIC cVar6 := "Group   "

STATIC oGet1
STATIC oGet2
STATIC oGet3
STATIC oGet4
STATIC oGet5
STATIC oGet6
STATIC oSay1

*+--------------------------------------------------------------------
*+
*+    Procedure Main()
*+
*+--------------------------------------------------------------------
*+
PROCEDURE Main()

LOCAL oDlg, oFont, oImage, oFont2
LOCAL Hwnd, hRgn, lhRgn
LOCAL nLeftRect, nTopRect, nRightRect, nBottomRect

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0, - 18
#IFDEF __HMG__
   END FONT
#ENDIF
   DEFINE FONT oFont2 NAME "TAHOMA" SIZE 0, - 28
#IFDEF __HMG__
   END FONT
#ENDIF

   DEFINE WINDOW oDlg FROM 0, 0 TO 600, 800 + 16 PIXEL TITLE "DWM" COLOR RGB( 025, 254, 255 ), CLR_BLUE

      @  0,  0 SAY oSay1 PROMPT "Desktop Windows Manager" SIZE 798, 040 PIXEL OF oDlg FONT oFont2 CENTER COLOR RGB( 005, 005, 005 ), RGB( 076, 163, 254 )        

      @ 340, 010 SAY "Name    " GET oGet1 VAR cVar1 SIZE 290, 026 PIXEL OF oDlg FONT oFont NOBORDER COLOR RGB( 005, 005, 005 ), CLR_WHITE        
      @ 374, 010 SAY "Channel " GET oGet2 VAR cVar2 SIZE 120, 026 PIXEL OF oDlg FONT oFont NOBORDER COLOR RGB( 025, 254, 255 ), CLR_GRAY        
      @ 410, 010 SAY "TV ID   " GET oGet3 VAR cVar3 SIZE 370, 026 PIXEL OF oDlg FONT oFont NOBORDER COLOR RGB( 255, 000, 000 ), CLR_YELLOW      
      @ 444, 010 SAY "Logo    " GET oGet4 VAR cVar4 SIZE 370, 026 PIXEL OF oDlg FONT oFont NOBORDER COLOR RGB( 025, 254, 255 ), CLR_GREEN        
      @ 478, 010 SAY "URL     " GET oGet5 VAR cVar5 SIZE 370, 026 PIXEL OF oDlg FONT oFont NOBORDER COLOR RGB( 025, 254, 255 ), CLR_RED          
      @ 512, 010 SAY "Group   " GET oGet6 VAR cVar6 SIZE 370, 026 PIXEL OF oDlg FONT oFont NOBORDER COLOR RGB( 025, 254, 255 ), CLR_BLACK        

#IFDEF __HMG__
   END WINDOW
#ENDIF
   Hwnd := oDlg:hWnd

   nLeftRect := 1
   nTopRect := oDlg:nBottom
   nRightRect := oDlg:nRight
   nBottomRect := 1

   // lhRgn := CreateRoundRectRgn( nLeftRect, nTopRect, nRightRect, nBottomRect, 20, 20 )
   lhRgn := CreateRectRgn( nLeftRect, nTopRect, nRightRect, nBottomRect )
   DwmEnableBlurBehindWindow( Hwnd, lhRgn )

   Hwnd := oSay1:hWnd
   SetWindowRgn( Hwnd, lhRgn )
   DwmExtendFrameIntoClientArea( Hwnd, lhRgn )

   ACTIVATE WINDOW oDlg CENTERED
RETURN

*+--------------------------------------------------------------------
*+
*+    Function DwmEnableBlurBehindWindow()
*+
*+    Called from ( fwdwm.prg )   1 - procedure main()
*+
*+--------------------------------------------------------------------
*+
FUNCTION DwmEnableBlurBehindWindow( hWnd, lhRgn )

LOCAL xRet, bb
LOCAL dwFlags                := DWM_BB_ENABLE
LOCAL fEnable                := 1                                     // .T.
LOCAL hRgnBlur               := lhRgn
LOCAL fTransitionOnMaximized := 1                                     // .T.

   bb := L2BIN( dwFlags ) + ;
                L2BIN( fEnable ) + ;
                L2BIN( hRgnBlur ) + ;
                L2BIN( fTransitionOnMaximized )

   xRet := DllCall( "dwmapi.dll", DLL_OSAPI, "DwmEnableBlurBehindWindow", hWnd, bb )
RETURN xRet

*+--------------------------------------------------------------------
*+
*+    Function DwmExtendFrameIntoClientArea()
*+
*+    Called from ( fwdwm.prg )   1 - procedure main()
*+
*+--------------------------------------------------------------------
*+
FUNCTION DwmExtendFrameIntoClientArea( nHwnd, sMargin )

LOCAL xRet
   xRet := DllCall( "dwmapi.dll", DLL_OSAPI, "DwmExtendFrameIntoClientArea", nHwnd, @sMargin )
RETURN xRet

*+--------------------------------------------------------------------
*+
*+    Function CreateRectRgn()
*+
*+    Called from ( fwdwm.prg )   1 - procedure main()
*+
*+--------------------------------------------------------------------
*+
FUNCTION CreateRectRgn( nLeftRect, nTopRect, nRightRect, nBottomRect )

LOCAL lRet
   lRet := DllCall( "GDI32.DLL", DLL_OSAPI, "CreateRectRgn", nLeftRect, nTopRect, nRightRect, nBottomRect )
RETURN lRet

*+--------------------------------------------------------------------
*+
*+    Function CreateEllipticRgn()
*+
*+--------------------------------------------------------------------
*+
FUNCTION CreateEllipticRgn( nLeftRect, nTopRect, nRightRect, nBottomRect )

LOCAL lRet
   lRet := DllCall( "GDI32.DLL", DLL_OSAPI, "CreateEllipticRgn", nLeftRect, nTopRect, nRightRect, nBottomRect )
RETURN lRet

*+--------------------------------------------------------------------
*+
*+    Function CreateRoundRectRgn()
*+
*+--------------------------------------------------------------------
*+
FUNCTION CreateRoundRectRgn( nLeftRect, nTopRect, nRightRect, nBottomRect, x, y )

LOCAL lRet
   lRet := DllCall( "GDI32.DLL", DLL_OSAPI, "CreateRoundRectRgn", nLeftRect, nTopRect, nRightRect, nBottomRect, x, y )
RETURN lRet

*+--------------------------------------------------------------------
*+
*+    Function SetWindowRgn()
*+
*+    Called from ( fwdwm.prg )   1 - procedure main()
*+
*+--------------------------------------------------------------------
*+
FUNCTION SetWindowRgn( Hwnd, lhRgn, lRedraw )

LOCAL lRet
   DEFAULT lRedraw TO .T.
   lRet := DllCall( "USER32.DLL", DLL_OSAPI, "SetWindowRgn", Hwnd, lhRgn, lRedraw )
RETURN lRet

//
//
//

*+ EOF: FWDWM.PRG
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: DWM ( Desktop Windows Manager ) Sample Code

Postby Otto » Fri Aug 26, 2022 8:26 am

Jimmy, thank you.
Where do I get hbxpp?
What exactly is the purpose of this program?
Is it for creating desktop icons?

Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: DWM ( Desktop Windows Manager ) Sample Code

Postby Jimmy » Fri Aug 26, 2022 3:49 pm

hi Otto,
Otto wrote:Where do I get hbxpp?

the CODE should run "direct" under FiveWin without any Problem when request "hbxpp" which is include in FiveWin

as i say i "guess" Fivewin does have most API Function as HB_FUNC()
so DllCall, using Xbase++ Syntax ("hbxpp") , is not need when use HB_FUNC()

i have to learn how those HB_FUNC() are called under FiveWin

Otto wrote:What exactly is the purpose of this program?

since Windows 10 many System Dialog have a "transparency" Panel on left Side e.g. "Windows Update"
but they are most "gray" which can be change to other Color

you can do much more with DWM, look here
https://docs.microsoft.com/de-de/windows/win32/dwm/functions
https://docs.microsoft.com/en-us/windows/win32/api/_dwm/

Otto wrote:Is it for creating desktop icons?

No, but you can create "live Preview" of "TabThumbnails"
https://docs.microsoft.com/de-de/windows/win32/dwm/dwm-sample-customizethumbnail
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: DWM ( Desktop Windows Manager ) Sample Code

Postby Jimmy » Fri Aug 26, 2022 5:56 pm

hi,

i have search in FiveWin and found HB_FUNC() for
Code: Select all  Expand view
  Function CreateRectRgn()
   Function CreateEllipticRgn()
   Function CreateRoundRectRgn()
   Function SetWindowRgn()

now only DWM Function still use Dllcall() and L2BIN()
Code: Select all  Expand view
  Function DwmEnableBlurBehindWindow()
   Function DwmExtendFrameIntoClientArea()

who can help me please to convert it to HB_FUNC()
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: DWM ( Desktop Windows Manager ) Sample Code

Postby Jimmy » Fri Aug 26, 2022 8:37 pm

hi,

got
Code: Select all  Expand view
HB_FUNC( DWMENABLEBLURBEHINDWINDOW )
{
  HRESULT hr = TRUE ;

   // Create and populate the Blur Behind structure
  DWM_BLURBEHIND bb ;

   // Enable Blur Behind and apply to the entire client area
  bb.dwFlags = DWM_BB_ENABLE;
  bb.fEnable = TRUE;
  bb.hRgnBlur =  ( HRGN ) hb_parnl( 2 );
  bb.fTransitionOnMaximized = TRUE;

   // Apply Blur Behind
  hr = DwmEnableBlurBehindWindow( ( HWND ) hb_parnl( 1 ) , &bb);
  hb_retl ((BOOL) hr ) ;
}


now i try HB_FUNC( DWMEXTENDFRAMEINTOCLIENTAREA ) using this Sample
https://docs.microsoft.com/en-us/windows/win32/api/dwmapi/nf-dwmapi-dwmextendframeintoclientarea

Code: Select all  Expand view
HB_FUNC( DWMEXTENDFRAMEINTOCLIENTAREA )
{
  MARGINS margins = {-1};
  HRESULT hr = TRUE ;

  hr = DwmExtendFrameIntoClientArea( (HWND) hb_parnl( 1 ) , &margins) :
  hb_retl ((BOOL) hr ) ;
}


but i got
Error E2379 FWDWM.prg 239: Statement missing ; in function HB_FUN_DWMEXTENDFRAME...

who can help me which "MARGINS"
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: DWM ( Desktop Windows Manager ) Sample Code

Postby Antonio Linares » Fri Aug 26, 2022 10:35 pm

Dear Jimmy,

You have a little typo here:

hr = DwmExtendFrameIntoClientArea( (HWND) hb_parnl( 1 ) , &margins) :

latest must be ; instead of :

remember that MARGIN is defined as:
Code: Select all  Expand view
typedef struct _MARGINS {
  int cxLeftWidth;
  int cxRightWidth;
  int cyTopHeight;
  int cyBottomHeight;
} MARGINS, *PMARGINS;


so you have to provide other values besides -1
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: DWM ( Desktop Windows Manager ) Sample Code

Postby Jimmy » Sat Aug 27, 2022 9:36 pm

hi Antonio,
Antonio Linares wrote:You have a little typo here:

ooooh ... Yes ... typo ...

so it must be
Code: Select all  Expand view
HB_FUNC( DWMEXTENDFRAMEINTOCLIENTAREA )
{
  MARGINS margins = {-1,-1,-1,-1};
  HRESULT hr ;

  margins.cxLeftWidth    = hb_parnl( 2 ) ;
  margins.cxRightWidth   = hb_parnl( 3 ) ;
  margins.cyTopHeight    = hb_parnl( 4 ) ;
  margins.cyBottomHeight = hb_parnl( 5 ) ;

  hr = DwmExtendFrameIntoClientArea( (HWND) hb_parnl( 1 ) , &margins) ;
  hb_retl ((BOOL) hr ) ;
}

thx for help a "C" Newbie
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: DWM ( Desktop Windows Manager ) Sample Code

Postby Antonio Linares » Sun Aug 28, 2022 4:59 am

Dear Jimmy,

As you are filling the struct members further on, then there is no need to initialize the struct in advance:

MARGINS margins;

margins.cxLeftWidth = hb_parnl( 2 ) ;
margins.cxRightWidth = hb_parnl( 3 ) ;
margins.cyTopHeight = hb_parnl( 4 ) ;
margins.cyBottomHeight = hb_parnl( 5 ) ;

Also I would suggest to use hb_parnll() for the window handle so you get your code 64 bits ready:
( HWND ) hb_parnll( 1 )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: DWM ( Desktop Windows Manager ) Sample Code

Postby Jimmy » Sun Aug 28, 2022 7:56 pm

hi Antonio,
Antonio Linares wrote:Also I would suggest to use hb_parnll() for the window handle so you get your code 64 bits ready:
( HWND ) hb_parnll( 1 )

ahh, YES 64 Bit
i still "think" in 32 Bit

thx for Advice
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: DWM ( Desktop Windows Manager ) Sample Code

Postby mgsoft » Tue Aug 30, 2022 6:38 am

Hi,

Can you please post the revised code?

Thanks
Saludos,

Eduardo
User avatar
mgsoft
 
Posts: 422
Joined: Mon Aug 17, 2009 12:18 pm
Location: España

Re: DWM ( Desktop Windows Manager ) Sample Code

Postby Jimmy » Tue Aug 30, 2022 8:49 pm

hi,

i´m still working on DWM for FiveWin

i have look into FiveWin Source and found HB_FUNC() for
CreateRectRgn()
CreateRoundRectRgn()
SetWindowRgn()

so only DWM API Function was left where i try to use "C" Code as show in Thread

it now compile/link without Error after Antonio help me as i´m NOT a "C" Programmer

---

but it does not work the Way i want ... :(

DwmEnableBlurBehindWindow(Hwnd, lhRgn )
will affect hole Window (Hwnd) regradeless which Coordinate i use for CreateRectRgn()

DwmExtendFrameIntoClientArea( Hwnd, L2Bin(-1), L2Bin(-1), L2Bin(-1), L2Bin(-1) )
seems not to have any Effect on "ClientArea" (under Xbase++ i have oDialig:DrawingArea)

so i have to learn more about FiveWin to work with DWM and HB_FUNC()
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 90 guests