-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d9dad85
commit 8cb9d0f
Showing
13 changed files
with
292 additions
and
10 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
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 |
---|---|---|
@@ -1 +1 @@ | ||
include win32style win32style.dll | ||
include win32material win32material.dll |
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 |
---|---|---|
@@ -1,24 +1,24 @@ | ||
"""Setup for win32style""" | ||
"""Setup for win32material""" | ||
from distutils.core import setup | ||
|
||
with open("README.md", "r") as file: | ||
long_description = file.read() | ||
|
||
setup( | ||
name="win32material", | ||
version="1.0.4", | ||
version="1.0.5", | ||
description="Apply some window effects to the Win32 Applications", | ||
long_description=long_description, | ||
long_description_content_type="text/markdown", | ||
author="littlewhitecloud", | ||
exclude_package_data={ | ||
"": ["win32style.def"], | ||
"": ["win32style.h"], | ||
"": ["win32style.cpp"], | ||
"": ["win32material.def"], | ||
"": ["win32material.h"], | ||
"": ["win32material.cpp"], | ||
}, | ||
package_data={ | ||
"": ["*.dll"], | ||
}, | ||
url="https://github.com/littlewhitecloud/win32material", | ||
packages=["win32style"], | ||
packages=["win32material"], | ||
) |
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,16 @@ | ||
from ctypes import c_char_p, windll | ||
#from pywinstyles import * | ||
from tkinter import Tk | ||
|
||
from win32material import * | ||
|
||
|
||
w = Tk() | ||
w.title("example") | ||
w.geometry("1080x570") | ||
w.iconbitmap("") | ||
w.config(background="black") | ||
|
||
ApplyMica(windll.user32.GetParent(w.winfo_id()), True) | ||
|
||
w.mainloop() |
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,18 @@ | ||
"""Load functions""" | ||
from platform import platform | ||
|
||
if not platform().startswith("Windows-10") and not platform().startswith("Windows-11"): | ||
raise OSError("To use this package, you need to use Windows 10 or above") | ||
|
||
from .win32material import ( | ||
BORDERTYPE, | ||
MICAMODE, | ||
MICATHEME, | ||
ApplyAcrylic, | ||
ApplyDarkMode, | ||
ApplyMica, | ||
ChangeBorderColor, | ||
ChangeTitlebarColor, | ||
ChangeTitleColor, | ||
SetBorderType, | ||
) |
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,5 @@ | ||
echo off | ||
|
||
cl /LD /DEF: .\win32material.def .\win32material.cpp | ||
|
||
del win32material.exp win32material.obj |
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,112 @@ | ||
// win32material.cpp - Define different materials and functions for win32 applications | ||
|
||
#undef UNICODE | ||
#undef _UNICODE | ||
|
||
#include <windows.h> | ||
#include <dwmapi.h> | ||
|
||
#include "win32material.h" | ||
|
||
#pragma comment(lib, "dwmapi.lib") | ||
#pragma comment(lib, "user32.lib") | ||
|
||
static void ExtendFrameIntoClientArea(HWND hwnd) | ||
{ | ||
// Set the margins | ||
const MARGINS margins = {-1}; | ||
// Extend frame into client area | ||
DwmExtendFrameIntoClientArea(hwnd, &margins); | ||
} | ||
|
||
static void ApplyMicaEffect(HWND hwnd, bool theme, bool micaalt, bool extend, bool flag = true) | ||
{ | ||
// Set the mica value | ||
const int value = flag ? micaalt ? 0x04 : 0x02 : micaalt ? 0x04 | ||
: 0x01; | ||
// Set the mica entry | ||
const int entry = flag ? 38 : 1029; | ||
|
||
if (extend) // extend frame into client area | ||
ExtendFrameIntoClientArea(hwnd); | ||
|
||
// Set the window's theme | ||
DwmSetWindowAttribute(hwnd, 20, &theme, sizeof(int)); | ||
// Set the window's backdrop | ||
DwmSetWindowAttribute(hwnd, entry, &value, sizeof(int)); | ||
} | ||
|
||
void ApplyDocumentMica(HWND hwnd, bool theme, bool micaalt, bool extend) | ||
{ | ||
/* | ||
Windows 11 23523+ | ||
hwnd: HWND : the window's hwnd | ||
theme: bool : the window's theme | ||
micaalt: bool : determine which type of mica | ||
extend: bool : extend to the client area | ||
*/ | ||
ApplyMicaEffect(hwnd, theme, micaalt, extend); | ||
} | ||
|
||
void ApplyUndocumentMica(HWND hwnd, bool theme, bool micaalt, bool extend) | ||
{ | ||
/* | ||
Windows 11 23523- | ||
hwnd: HWND : the window's hwnd | ||
theme: bool : the window's theme | ||
micaalt: bool : determine which type of mica | ||
extend: bool : extend to the client area | ||
*/ | ||
ApplyMicaEffect(hwnd, theme, micaalt, extend, false); | ||
} | ||
|
||
void ApplyAcrylic(HWND hwnd, bool extend = false, DWORD hexcolor = 0) | ||
{ | ||
pfnSetWindowCompositionAttribute SetWindowCompositionAttribute = (pfnSetWindowCompositionAttribute)GetProcAddress(GetModuleHandle("user32.dll"), "SetWindowCompositionAttribute"); | ||
DWORD gradientcolor = DWORD(0x50F5F5F5); | ||
if (hexcolor) | ||
gradientcolor = hexcolor; | ||
|
||
ApplyDarkMode(hwnd); | ||
|
||
ACCENT_POLICY accentpolicy = {}; | ||
|
||
accentpolicy.AccentState = 3; | ||
accentpolicy.GradientColor = gradientcolor; | ||
// Set the WindowCompositionArrtibuteData | ||
WINDOWCOMPOSITIONATTRIBDATA data; | ||
data.Attrib = 30; | ||
data.pvData = &accentpolicy; | ||
data.cbData = sizeof(accentpolicy); | ||
|
||
// Set the window's backdrop | ||
SetWindowCompositionAttribute(hwnd, &data); | ||
if (extend) | ||
ExtendFrameIntoClientArea(hwnd); | ||
} | ||
|
||
void ChangeTitlebarColor(HWND hwnd, DWORD hexcolor) | ||
{ | ||
DwmSetWindowAttribute(hwnd, 35, &hexcolor, sizeof(int)); | ||
} | ||
|
||
void ChangeBorderColor(HWND hwnd, DWORD hexcolor) | ||
{ | ||
DwmSetWindowAttribute(hwnd, 34, &hexcolor, sizeof(int)); | ||
} | ||
|
||
void ChangeTitleColor(HWND hwnd, DWORD hexcolor) | ||
{ | ||
DwmSetWindowAttribute(hwnd, 36, &hexcolor, sizeof(int)); | ||
} | ||
|
||
void SetBorderType(HWND hwnd, int type) | ||
{ | ||
DwmSetWindowAttribute(hwnd, 33, &type, sizeof(int)); | ||
} | ||
|
||
void ApplyDarkMode(HWND hwnd) | ||
{ | ||
bool flag = true; | ||
DwmSetWindowAttribute(hwnd, 20, &flag, sizeof(int)); | ||
} |
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,9 @@ | ||
EXPORTS | ||
ApplyAcrylic @1 | ||
ApplyDocumentMica @2 | ||
ApplyUndocumentMica @3 | ||
ChangeTitlebarColor @4 | ||
ChangeBorderColor @5 | ||
ChangeTitleColor @6 | ||
SetBorderType @7 | ||
ApplyDarkMode @8 |
Binary file not shown.
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,43 @@ | ||
// win32material.h - Define the functions and structs | ||
|
||
#pragma once | ||
|
||
#ifdef WIN32MATERIAL_EXPORTS | ||
#define DLLEXPORT __declspec(dllexport) | ||
#else | ||
#define DLLEXPORT __declspec(dllimport) | ||
#endif | ||
|
||
typedef struct _WINDOWCOMPOSITIONATTRIBDATA | ||
{ | ||
DWORD Attrib; | ||
PVOID pvData; | ||
SIZE_T cbData; | ||
} WINDOWCOMPOSITIONATTRIBDATA; | ||
|
||
typedef struct _ACCENT_POLICY | ||
{ | ||
DWORD AccentState; | ||
DWORD AccentFlags; | ||
DWORD GradientColor; | ||
DWORD AnimationId; | ||
} ACCENT_POLICY; | ||
|
||
WINUSERAPI BOOL WINAPI SetWindowCompositionAttribute( | ||
_In_ HWND hWnd, | ||
_Inout_ WINDOWCOMPOSITIONATTRIBDATA *pAttrData); | ||
|
||
typedef BOOL(WINAPI *pfnSetWindowCompositionAttribute)(HWND, WINDOWCOMPOSITIONATTRIBDATA *); | ||
|
||
extern "C" | ||
{ | ||
DLLEXPORT void ApplyAcrylic(HWND hwnd, DWORD hexcolor); | ||
DLLEXPORT void ApplyDocumentMica(HWND hwnd, bool theme, bool micaalt, bool extend); | ||
DLLEXPORT void ApplyUndocumentMica(HWND hwnd, bool theme, bool micaalt, bool extend); | ||
|
||
DLLEXPORT void ChangeTitlebarColor(HWND hwnd, DWORD color); | ||
DLLEXPORT void ChangeBorderColor(HWND hwnd, DWORD hexcolor); | ||
DLLEXPORT void ChangeTitleColor(HWND hwnd, DWORD hexcolor); | ||
DLLEXPORT void SetBorderType(HWND hwnd, int type); | ||
DLLEXPORT void ApplyDarkMode(HWND hwnd); | ||
} |
Binary file not shown.
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,79 @@ | ||
"""Export the funtions to Python""" | ||
from ctypes import windll | ||
from pathlib import Path | ||
|
||
material = windll.LoadLibrary(str(Path(__file__).parent / f"win32material.dll")) # Rewrite it in python later | ||
|
||
class MICATHEME: | ||
LIGHT: bool = False | ||
DARK: bool = True | ||
|
||
|
||
class MICAMODE: | ||
DEFAULT: bool = False | ||
ALT: bool = True | ||
|
||
|
||
class BORDERTYPE: | ||
RECTANGULAR: int = 1 | ||
ROUND: int = 2 | ||
SMALLROUND: int = 3 | ||
|
||
|
||
def ApplyMica( | ||
hwnd: int, theme: bool = True, micaalt: bool = True, extend: bool = True | ||
) -> None: | ||
"""Apply mica effect to Win32 Applications | ||
Args: | ||
hwnd(int): The target window's hwnd | ||
theme(bool): | ||
false -> light | ||
true -> dark | ||
micaalt(bool): | ||
false -> default | ||
true -> alt | ||
extend(bool): | ||
false -> only apply to titlebar | ||
true -> extend to the window | ||
""" | ||
from sys import getwindowsversion | ||
|
||
if getwindowsversion().build < 22000: | ||
raise OSError("Use Windows 11 to apply mica effect") | ||
|
||
if getwindowsversion().build < 22523: | ||
material.ApplyUndocumentMica(hwnd, theme, micaalt, extend) | ||
else: | ||
material.ApplyDocumentMica(hwnd, theme, micaalt, extend) | ||
|
||
|
||
def ApplyAcrylic(hwnd: int, extend: bool = False, hexcolor: int | bool = False) -> None: | ||
"""Apply acrylic effect to Win32 Applications | ||
Args: | ||
hwnd(int): The target window's hwnd | ||
hexcolor(int): The effect's hexcolor | ||
""" | ||
material.ApplyAcrylic(hwnd, extend, hexcolor) | ||
|
||
|
||
def ChangeTitlebarColor(hwnd: int, color: str) -> None: | ||
color = f"{color[5:7]}{color[3:5]}{color[1:3]}" | ||
material.ChangeTitlebarColor(hwnd, int(color, base=16)) | ||
|
||
|
||
def ChangeBorderColor(hwnd: int, color: str) -> None: | ||
color = f"{color[5:7]}{color[3:5]}{color[1:3]}" | ||
material.ChangeBorderColor(hwnd, int(color, base=16)) | ||
|
||
|
||
def ChangeTitleColor(hwnd: int, color: str) -> None: | ||
color = f"{color[5:7]}{color[3:5]}{color[1:3]}" | ||
material.ChangeTitleColor(hwnd, int(color, base=16)) | ||
|
||
|
||
def SetBorderType(hwnd: int, type: BORDERTYPE | int) -> None: | ||
material.SetBorderType(hwnd, type) | ||
|
||
|
||
def ApplyDarkMode(hwnd: int) -> None: | ||
material.ApplyDarkMode(hwnd) |