Set DarkMode for Form Title Bar, DwmSetWindowAttribute

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
IMATECH
Posts: 188
Joined: Sun May 27, 2012 9:33 pm
Location: Brazil: Goiânia-GO.

Set DarkMode for Form Title Bar, DwmSetWindowAttribute

Post by IMATECH »

I need help to use windows api "Dwmapi.dll"

hmg

Code: Select all

#define DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 19
#define DWMWA_USE_IMMERSIVE_DARK_MODE 20

Proc main

  DEFINE WINDOW Form1
    ...
  END WINDOW

  // Do nothing
  // Wrong API call used :-/
  DwmSetWindowAttribute( GetFormHandle( 'Form1' ), DWMWA_USE_IMMERSIVE_DARK_MODE, .T., 0 )

  Form1.Activate()

C/C++

Code: Select all

#include <windows.h>
#include <shellapi.h>
#include <Uxtheme.h>
#include "hbapi.h"

VOID *hDWMAPI = NULL;
typedef HRESULT (WINAPI * func_DwmSetWindowAttribute) (HWND, HB_INT dwAttribute, HB_BOOL pvAttribute, HB_INT cbAttribute);

BOOL HMG_DWMAPI ()
{
   if (hDWMAPI == NULL)
       hDWMAPI = LoadLibrary( "Dwmapi.dll");
   if (hDWMAPI)
      return TRUE;
   else
      return FALSE;
}

// DwmSetWindowAttribute(IntPtr hwnd, DWMWINDOWATTRIBUTE dwAttribute, ref int pvAttribute, int cbAttribute);
HB_FUNC ( DWMSETWINDOWATTRIBUTE )
{
   HWND    hWnd = (HWND) hb_parnl (1);
   HRESULT nRet = ( HRESULT ) NULL;

   if (hWnd == NULL) hWnd = GetActiveWindow();

   if( HMG_DWMAPI() )
   {
      func_DwmSetWindowAttribute pDwmSetWindowAttribute = ( func_DwmSetWindowAttribute ) GetProcAddress( hDWMAPI, "DwmSetWindowAttribute" );
      if( pDwmSetWindowAttribute )
         nRet = ( HRESULT ) pDwmSetWindowAttribute( hWnd, hb_parnl(2), hb_parnl(3), sizeof( hb_parnl(3) ) );
      FreeLibrary( hDWMAPI );
   }
   hb_retl( ( nRet == S_OK ) );
}
Reference:
https://stackoverflow.com/questions/571 ... windows-10

Thanks for help,
Regards :-)
M., Ronaldo

By: IMATECH

Imation Tecnologia
User avatar
IMATECH
Posts: 188
Joined: Sun May 27, 2012 9:33 pm
Location: Brazil: Goiânia-GO.

Re: Set DarkMode for Form Title Bar, DwmSetWindowAttribute

Post by IMATECH »

Found solution at:

\MiniGUI\SAMPLES\Advanced\ComboColor\demo.prg

Image
Thanks to Grigory Filatov and Verchenko Andrey
M., Ronaldo

By: IMATECH

Imation Tecnologia
edk
Posts: 999
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Set DarkMode for Form Title Bar, DwmSetWindowAttribute

Post by edk »

+1
Post Reply