Skip to content

Commit

Permalink
Version 0.5
Browse files Browse the repository at this point in the history
- Currently limited to File Explorer immersive context menus only
- Applying acrylic without using layered windows, but by modifying immersive context menu theme data
- Using windows event hooking instead of DLL hooking
- Fixing opaque context menu borders may require patching aero.msstyles file
  • Loading branch information
krlvm committed Apr 4, 2022
1 parent 2acd218 commit dd1678f
Show file tree
Hide file tree
Showing 19 changed files with 213 additions and 684 deletions.
28 changes: 9 additions & 19 deletions AcrylicMenus.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31702.278
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Injector", "Injector\Injector.vcxproj", "{DD8CE104-5003-4C5A-B0FA-AB9AC2E91104}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HookDLL", "HookDLL\HookDLL.vcxproj", "{EEE97587-E526-4E8B-827F-710EBC45D987}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AcrylicMenus", "AcrylicMenus\AcrylicMenus\AcrylicMenus.vcxproj", "{FD755B75-9F8C-4974-87A8-A649A7BCC39F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -15,22 +13,14 @@ Global
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DD8CE104-5003-4C5A-B0FA-AB9AC2E91104}.Debug|x64.ActiveCfg = Debug|x64
{DD8CE104-5003-4C5A-B0FA-AB9AC2E91104}.Debug|x64.Build.0 = Debug|x64
{DD8CE104-5003-4C5A-B0FA-AB9AC2E91104}.Debug|x86.ActiveCfg = Debug|Win32
{DD8CE104-5003-4C5A-B0FA-AB9AC2E91104}.Debug|x86.Build.0 = Debug|Win32
{DD8CE104-5003-4C5A-B0FA-AB9AC2E91104}.Release|x64.ActiveCfg = Release|x64
{DD8CE104-5003-4C5A-B0FA-AB9AC2E91104}.Release|x64.Build.0 = Release|x64
{DD8CE104-5003-4C5A-B0FA-AB9AC2E91104}.Release|x86.ActiveCfg = Release|Win32
{DD8CE104-5003-4C5A-B0FA-AB9AC2E91104}.Release|x86.Build.0 = Release|Win32
{EEE97587-E526-4E8B-827F-710EBC45D987}.Debug|x64.ActiveCfg = Debug|x64
{EEE97587-E526-4E8B-827F-710EBC45D987}.Debug|x64.Build.0 = Debug|x64
{EEE97587-E526-4E8B-827F-710EBC45D987}.Debug|x86.ActiveCfg = Debug|Win32
{EEE97587-E526-4E8B-827F-710EBC45D987}.Debug|x86.Build.0 = Debug|Win32
{EEE97587-E526-4E8B-827F-710EBC45D987}.Release|x64.ActiveCfg = Release|x64
{EEE97587-E526-4E8B-827F-710EBC45D987}.Release|x64.Build.0 = Release|x64
{EEE97587-E526-4E8B-827F-710EBC45D987}.Release|x86.ActiveCfg = Release|Win32
{EEE97587-E526-4E8B-827F-710EBC45D987}.Release|x86.Build.0 = Release|Win32
{FD755B75-9F8C-4974-87A8-A649A7BCC39F}.Debug|x64.ActiveCfg = Debug|x64
{FD755B75-9F8C-4974-87A8-A649A7BCC39F}.Debug|x64.Build.0 = Debug|x64
{FD755B75-9F8C-4974-87A8-A649A7BCC39F}.Debug|x86.ActiveCfg = Debug|Win32
{FD755B75-9F8C-4974-87A8-A649A7BCC39F}.Debug|x86.Build.0 = Debug|Win32
{FD755B75-9F8C-4974-87A8-A649A7BCC39F}.Release|x64.ActiveCfg = Release|x64
{FD755B75-9F8C-4974-87A8-A649A7BCC39F}.Release|x64.Build.0 = Release|x64
{FD755B75-9F8C-4974-87A8-A649A7BCC39F}.Release|x86.ActiveCfg = Release|Win32
{FD755B75-9F8C-4974-87A8-A649A7BCC39F}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{dd8ce104-5003-4c5a-b0fa-ab9ac2e91104}</ProjectGuid>
<RootNamespace>Injector</RootNamespace>
<ProjectGuid>{fd755b75-9f8c-4974-87a8-a649a7bcc39f}</ProjectGuid>
<RootNamespace>AcrylicMenus</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
Expand Down Expand Up @@ -139,10 +139,12 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Injector.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="ThemeHelper.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\HookDLL\resource.h" />
<ClInclude Include="AcrylicHelper.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="ThemeHelper.h" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,24 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="framework.h">
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ThemeHelper.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="AcrylicHelper.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="pch.h">
<ClInclude Include="ThemeHelper.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="AcrylicHelper.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="pch.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="VersionInfo.rc">
<Filter>Resource Files</Filter>
Expand Down
67 changes: 67 additions & 0 deletions AcrylicMenus/AcrylicMenus/ThemeHelper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include "ThemeHelper.h"
#include <iostream>

int RecolorizeBitmap(HBITMAP hbm)
{
BITMAP bm;
GetObject(hbm, sizeof(bm), &bm);

if (!hbm || bm.bmBitsPixel != 32)
{
return FALSE;
}

BYTE* pBits = new BYTE[bm.bmWidth * bm.bmHeight * 4];
GetBitmapBits(hbm, bm.bmWidth * bm.bmHeight * 4, pBits);

for (int y = 0; y < bm.bmHeight; y++) {
BYTE* pPixel = (BYTE*)pBits + bm.bmWidth * 4 * y;

for (int x = 0; x < bm.bmWidth; x++) {

int r = pPixel[2] & 0xFFFFFF;
//int g = pPixel[1] & 0xFFFFFF;
//int b = pPixel[0] & 0xFFFFFF;
//int a = pPixel[3] & 0xFFFFFF;

//std::cout << r << " " << g << " " << b << " / " << a << std::endl;

pPixel[0] = 0;
pPixel[1] = 0;
pPixel[2] = 0;

if (r == 238 || r == 43) {
pPixel[3] = 0;
}
else if (r == 255 || r == 65) {
pPixel[3] = 48;
}

pPixel += 4;
}
}


SetBitmapBits(hbm, bm.bmWidth * bm.bmHeight * 4, pBits);

delete[] pBits;
return TRUE;
}

int ModifyThemeData(LPCWSTR pszClassList) {
HBITMAP hBitmap;

HTHEME hTheme = OpenThemeData(GetForegroundWindow(), pszClassList);
GetThemeBitmap(hTheme, 9, 0, TMT_DIBDATA, GBF_DIRECT, &hBitmap);
GetThemeBitmap(hTheme, 14, 0, TMT_DIBDATA, GBF_DIRECT, &hBitmap);
CloseThemeData(hTheme);

return RecolorizeBitmap(hBitmap);
}

int UpdateThemeData() {
ModifyThemeData(L"ImmersiveStart::Menu");
ModifyThemeData(L"ImmersiveStartDark::Menu");

return TRUE;
}
11 changes: 11 additions & 0 deletions AcrylicMenus/AcrylicMenus/ThemeHelper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include <Windows.h>
#include <Uxtheme.h>
#include <vsstyle.h>
#include <vssym32.h>

#pragma comment(lib, "user32.lib")
#pragma comment(lib, "uxtheme.lib")

int UpdateThemeData();
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <winres.h>
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,1
PRODUCTVERSION 1,0,0,1
FILEVERSION 0,5,0,0
PRODUCTVERSION 0,5,0,0
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -17,13 +17,13 @@ BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "krlvm"
VALUE "FileDescription", "AcrylicMenus Hook Injector"
VALUE "FileVersion", "0.2.0.0"
VALUE "InternalName", "Injector"
VALUE "LegalCopyright", "Copyright krlvm (C) 2021"
VALUE "OriginalFilename", "Injector.exe"
VALUE "FileDescription", "AcrylicMenus Executable"
VALUE "FileVersion", "0.5.0.0"
VALUE "InternalName", "AcrylicMenus"
VALUE "LegalCopyright", "Copyright krlvm (C) 2021-2022"
VALUE "OriginalFilename", "AcrylicMenus.exe"
VALUE "ProductName", "AcrylicMenus"
VALUE "ProductVersion", "0.2.0.0"
VALUE "ProductVersion", "0.5.0.0"
END
END
BLOCK "VarFileInfo"
Expand Down
102 changes: 102 additions & 0 deletions AcrylicMenus/AcrylicMenus/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#include <iostream>
#include <Windows.h>

#include "AcrylicHelper.h"
#include "ThemeHelper.h"

#define ACRYLIC_OPACITY_LIGHT 196
#define EXPLORER_TINT_LIGHT 0xEEEEEE

#define ACRYLIC_OPACITY_DARK 196
#define EXPLORER_TINT_DARK 0x2B2B2B

HWINEVENTHOOK g_hook;
HKEY hKeyPersonalization;

bool IsExplorerDarkTheme()
{
DWORD dwBufferSize(sizeof(DWORD));
DWORD nResult(0);
LONG nError = RegQueryValueEx(
hKeyPersonalization,
L"AppsUseLightTheme",
0,
NULL,
reinterpret_cast<LPBYTE>(&nResult),
&dwBufferSize
);
return ERROR_SUCCESS == nError ? !nResult : FALSE;
}

void CALLBACK HandleWinEvent(HWINEVENTHOOK hook, DWORD event, HWND hwnd,
LONG idObject, LONG idChild,
DWORD dwEventThread, DWORD dwmsEventTime)
{
WCHAR szClass[256];
GetClassName(hwnd, szClass, sizeof(szClass));
if (wcscmp(szClass, L"#32768") == 0)
{
bool bIsExplorerDark = IsExplorerDarkTheme();
AcrylicHelper::ApplyAcrylic(hwnd,
bIsExplorerDark ? ACRYLIC_OPACITY_DARK : ACRYLIC_OPACITY_LIGHT,
bIsExplorerDark ? EXPLORER_TINT_DARK : EXPLORER_TINT_LIGHT);
}
}

void RegisterEventHook(DWORD pid)
{
g_hook = SetWinEventHook(
EVENT_OBJECT_CREATE, EVENT_OBJECT_CREATE,
NULL,
HandleWinEvent,
pid, 0,
WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);
}

void UnregisterEventHook()
{
UnhookWinEvent(g_hook);
}

bool GetExplorerPID(DWORD &pid)
{
HWND hwnd = FindWindow(L"Shell_TrayWnd", NULL);
return GetWindowThreadProcessId(hwnd, &pid);
}

int main()
{
std::cout << "AcrylicMenus v0.5 Preview" << std::endl;
std::cout << "https://github.com/krlvm/AcrylicMenus" << std::endl;
std::cout << "(c) krlvm, 2021" << std::endl;
std::cout << std::endl;

DWORD pid;
if (!GetExplorerPID(pid)) {
std::cout << "Please, start a File Explorer process to attach" << std::endl;
return -1;
}

UpdateThemeData();
RegOpenKeyEx(
HKEY_CURRENT_USER,
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
0, KEY_READ, &hKeyPersonalization
);

RegisterEventHook(pid);
std::cout << "Attached to File Explorer (PID=" << pid << ")" << std::endl;
std::cout << "AcrylicMenus should be restarted after Explorer restart to take effect" << std::endl;
std::cout << "You need to restart your PC if context menus became black after stop" << std::endl;
std::cout << std::endl;
std::cout << "Close this window to unregister event hook" << std::endl;

MSG msg;
while (true) {
GetMessage(&msg, NULL, 0, 0);
TranslateMessage(&msg);
DispatchMessage(&msg);
}

UnregisterEventHook();
}
2 changes: 0 additions & 2 deletions HookDLL/resource.h → AcrylicMenus/AcrylicMenus/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Microsoft Visual C++ generated include file.
// Used by VersionInfo.rc
//
#define VS_VERSION_INFO 1
#define IDC_STATIC -1

// Next default values for new objects
//
Expand Down
Loading

0 comments on commit dd1678f

Please sign in to comment.