Yesterday, 17:13
(This post was last modified: 7 hours ago by Borje Hagsten.)
Don't remember if anyone posted this kind of function in any of the old - now gone - forums, so here it is. Works for me in Windows 10 - hopefully also in later versions. To be compiled with PB/Win 10. Some comments explain.
Code:
'======================================================================
' Small example of how to enable visual styles in CommCtrl.dll v.6 via
' code instead of using manifest file in resource. Maybe not so useful,
' since doing it via xptheme.xml manifest in resource is easy, but here
' it is anyway. Public Domain by Borje Hagsten October 24, 2026.
'
' Added: Made a correction to deactivation via SUB DisableVisualStyles,
' where FreeeLibrary and ReleaseActCtx was added.
' Thank you Stanley Durham for pointing this out.
'======================================================================
#COMPILE EXE
#DIM ALL
'--------------------------------------------------------------------
%UNICODE = 1
#INCLUDE "WIN32API.INC"
'--------------------------------------------------------------------
%IDC_TEXTBOX1 = 531
GLOBAL ghActCtx, gCookie, ghShell32 AS LONG ' need to store these as global.
'======================================================================
FUNCTION PBMAIN () AS LONG
LOCAL hDlg AS LONG
EnableVisualStyles() 'Activate at entry
DIALOG NEW 0, "EnableVisualStyles",,, 185, 65, %WS_CAPTION OR %WS_SYSMENU OR _
%WS_MINIMIZEBOX, 0 TO hDlg
DIALOG SET COLOR hDlg, -1, RGB(196, 196, 196)
'------------------------------------------------------------------
CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX1, "TextBox1", 5, 5, 100, 55
CONTROL ADD BUTTON, hDlg, %IDCANCEL, "&Ok", 110, 46, 70, 14
'------------------------------------------------------------------
DIALOG SHOW MODAL hDlg ' no callback - just a demo of how to..
IF gCookie THEN DisableVisualStyles ' Deactivate at exit
END FUNCTION
'=================================================================================
' Enable visual styles in CommCtrl.dll v.6, using manifest resource in shell32.dll
'---------------------------------------------------------------------------------
FUNCTION EnableVisualStyles() AS DWORD
LOCAL aCtx AS ACTCTX
#IF %DEF(%UNICODE)
LOCAL szSys AS WSTRINGZ * %MAX_PATH
#ELSE
LOCAL szSys AS ASCIIZ * %MAX_PATH
#ENDIF
GetSystemDirectory szSys, SIZEOF(szSys) ' Need path to shell32.dll
aCtx.cbSize = SIZEOF(ACTCTX)
aCtx.dwFlags = %ACTCTX_FLAG_RESOURCE_NAME_VALID OR _
%ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID OR _
%ACTCTX_FLAG_HMODULE_VALID
aCtx.hModule = LoadLibrary("shell32.dll") ' Use the manifest resource in shell32.dll
aCtx.lpResourceName = 124 ' Manifest resource name
aCtx.lpAssemblyDirectory = VARPTR(szSys)
ghShell32 = aCtx.hModule
ghActCtx = CreateActCtx(aCtx) 'push the specified activation context to the top of the activation stack
IF ghActCtx <> %INVALID_HANDLE_VALUE THEN 'vs.hActCtx = dwRes, &vs.cookie = dwCookie, vs.hShell32 = aCtx.hModule
ActivateActCtx(ghActCtx, gCookie)
END IF
FUNCTION = gCookie
END FUNCTION
'=================================================================================
' Disable visual styles
'---------------------------------------------------------------------------------
SUB DisableVisualStyles
IF gCookie THEN DeactivateActCtx(0, gCookie)
IF NOT ghActCtx = %INVALID_HANDLE_VALUE THEN ReleaseActCtx(ghActCtx)
IF ghShell32 THEN FreeLibrary(ghShell32)
END SUB