Skip to content

Commit

Permalink
now automatically detects new windows and applies the rules
Browse files Browse the repository at this point in the history
  • Loading branch information
rounk-ctrl committed Feb 6, 2022
1 parent 5469af4 commit 3868863
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 14 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
################################################################################
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
################################################################################

/.vs/MicaForEveryone/v16
/MicaForEveryone/x64/Release
/x64/Release
/MicaForEveryone/MicaForEveryone.vcxproj.user
70 changes: 59 additions & 11 deletions MicaForEveryone/MicaForEveryone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// functions
#define MAX_LOADSTRING 100
#define WM_USER_SHELLICON WM_USER + 1
#define DWMWA_USE_IMMERSIVE_DARK_MODE 20
#define DWMWA_MICA_EFFECT 1029
#define DWMWA_SYSTEMBACKDROP_TYPE 38

Expand All @@ -26,6 +25,7 @@ BOOL Acrylic = FALSE;
BOOL Tabbed = FALSE;
BOOL DefaultCol = TRUE;
DWORD nice = TRUE;
HWINEVENTHOOK hEvent;
std::vector<HWND> hwndlist;
MARGINS margins = { -1 };
MENUITEMINFO mi = { 0 };
Expand Down Expand Up @@ -142,12 +142,6 @@ ATOM MyRegisterClass(HINSTANCE hInstance)

return RegisterClassExW(&wcex);
}
wchar_t* convertCharArrayToLPCWSTR(const char* charArray)
{
wchar_t* wString = new wchar_t[32];
MultiByteToWideChar(CP_ACP, 0, charArray, -1, wString, 32);
return wString;
}
//
// FUNCTION: InitInstance(HINSTANCE, int)
//
Expand Down Expand Up @@ -453,7 +447,61 @@ void ShowContextMenu(HWND hwnd, POINT pt)
}
}

VOID CALLBACK WinEventProcCallback(HWINEVENTHOOK hWinEventHook, DWORD dwEvent, HWND hwnd, LONG idObject, LONG idChild, DWORD dwEventThread, DWORD dwmsEventTime)
{
if (dwEvent == EVENT_OBJECT_CREATE) {
if (DefaultCol)
{

}
if (Light)
{
nice = FALSE;
DwmSetWindowAttribute(hwnd, DWMWA_USE_IMMERSIVE_DARK_MODE, &nice, sizeof nice);
}
if (Dark)
{
nice = TRUE;
DwmSetWindowAttribute(hwnd, DWMWA_USE_IMMERSIVE_DARK_MODE, &nice, sizeof nice);
}
if (DefaultBack)
{
int value = 1;
DwmSetWindowAttribute(hwnd, DWMWA_SYSTEMBACKDROP_TYPE, &value, sizeof value);
}
if (Mica)
{
if (os.dwBuildNumber == 22000)
{
nice = TRUE;
DwmSetWindowAttribute(hwnd, DWMWA_MICA_EFFECT, &nice, sizeof nice);
}
if (os.dwBuildNumber >= 22523)
{
int value = 2;
DwmSetWindowAttribute(hwnd, DWMWA_SYSTEMBACKDROP_TYPE, &value, sizeof value);
}
}
if (Acrylic)
{
if (os.dwBuildNumber < 22000)
{
SetWindowLongPtr(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED | WS_EX_NOREDIRECTIONBITMAP);
SetWindowBlur(hwnd);
}
else if (os.dwBuildNumber >= 22523)
{
int value = 3;
DwmSetWindowAttribute(hwnd, DWMWA_SYSTEMBACKDROP_TYPE, &value, sizeof value);
}
}
if (Tabbed)
{
int value = 4;
DwmSetWindowAttribute(hwnd, DWMWA_SYSTEMBACKDROP_TYPE, &value, sizeof value);
}
}
}
//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
Expand All @@ -469,10 +517,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
switch (message)
{
case WM_CREATE:
{

}
break;
hEvent = SetWinEventHook(EVENT_OBJECT_CREATE, EVENT_OBJECT_CREATE, NULL,
WinEventProcCallback, 0, 0, WINEVENT_OUTOFCONTEXT);
break;
case WM_USER_SHELLICON:
// systray msg callback
switch (LOWORD(lParam))
Expand Down Expand Up @@ -502,6 +549,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
}
break;
case WM_DESTROY:
if (hEvent) UnhookWinEvent(hEvent);
PostQuitMessage(0);
break;
default:
Expand Down
8 changes: 5 additions & 3 deletions MicaForEveryone/MicaForEveryone.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#pragma once

#include "resource.h"
#include "framework.h"

#define DWMWA_USE_IMMERSIVE_DARK_MODE 20

enum IMMERSIVE_HC_CACHE_MODE
{
IHCM_USE_CACHED_VALUE,
Expand Down Expand Up @@ -67,6 +71,4 @@ using fnOpenNcThemeData = HTHEME(WINAPI*)(HWND hWnd, LPCWSTR pszClassList); // o
// 1903 18362
using fnShouldSystemUseDarkMode = bool (WINAPI*)(); // ordinal 138
using fnSetPreferredAppMode = PreferredAppMode(WINAPI*)(PreferredAppMode appMode); // ordinal 135, in 1903
using fnIsDarkModeAllowedForApp = bool (WINAPI*)(); // ordinal 139


using fnIsDarkModeAllowedForApp = bool (WINAPI*)(); // ordinal

0 comments on commit 3868863

Please sign in to comment.