-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 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
Showing
19 changed files
with
213 additions
and
684 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.