Skip to content
This repository has been archived by the owner on Jan 4, 2025. It is now read-only.

Commit

Permalink
Fix KB5015882
Browse files Browse the repository at this point in the history
  • Loading branch information
ALTaleX531 committed Jul 22, 2022
1 parent e80c2e6 commit 6df2dd2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
37 changes: 25 additions & 12 deletions TranslucentFlyouts/ThemeHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,29 @@

namespace TranslucentFlyoutsLib
{
typedef HRESULT(WINAPI*pfnGetThemeClass)(HTHEME hTheme, LPCTSTR pszClassName, int cchClassName);
typedef BOOL(WINAPI*pfnIsThemeClassDefined)(HTHEME hTheme, LPCTSTR pszAppName, LPCTSTR pszClassName, BOOL bMatchClass);
typedef BOOL(WINAPI*pfnIsTopLevelWindow)(HWND hWnd);
typedef UINT(WINAPI *pfnGetWindowDPI)(HWND hwnd);
typedef HRESULT(WINAPI *pfnGetThemeClass)(HTHEME hTheme, LPCTSTR pszClassName, int cchClassName);
typedef BOOL(WINAPI *pfnIsThemeClassDefined)(HTHEME hTheme, LPCTSTR pszAppName, LPCTSTR pszClassName, BOOL bMatchClass);
typedef BOOL(WINAPI *pfnIsTopLevelWindow)(HWND hWnd);

static inline UINT GetWindowDPI(HWND hwnd)
{
static const auto &GetWindowDPI = (pfnGetWindowDPI)GetProcAddress(GetModuleHandle(TEXT("User32")), MAKEINTRESOURCEA(2707));
if (GetWindowDPI)
{
return GetWindowDPI(hwnd);
}
else
{
return 96;
}
}

// From UIRibbon.dll
float inline MsoScaleForWindowDPI(HWND hwnd, float size)
{
return fmaxf(1.0, (float)GetWindowDPI(hwnd) / 96.f) * size;
}

static inline bool IsAllowTransparent()
{
Expand Down Expand Up @@ -62,7 +82,7 @@ namespace TranslucentFlyoutsLib
{
TCHAR pszClass[MAX_PATH + 1] = {};
GetClassName(hWnd, pszClass, MAX_PATH);
return (!_tcscmp(pszClass, pszClassName) and (bRequireTopLevel ? IsTopLevelWindow(hWnd) : TRUE));
return (!_tcscmp(pszClass, pszClassName) and (bRequireTopLevel ? IsTopLevelWindow(hWnd) : !IsTopLevelWindow(hWnd)));
}

static inline bool IsPopupMenuFlyout(HWND hWnd)
Expand Down Expand Up @@ -130,13 +150,6 @@ namespace TranslucentFlyoutsLib
return lbr.lbColor;
}

static inline int GetBrushType(HBRUSH hBrush)
{
LOGBRUSH lbr = {};
GetObject(hBrush, sizeof(lbr), &lbr);
return lbr.lbStyle;
}

static inline void SetPixel(PBYTE pvBits, BYTE b, BYTE g, BYTE r, BYTE a)
{
// Alpha预乘
Expand Down Expand Up @@ -167,7 +180,7 @@ namespace TranslucentFlyoutsLib
{
BitmapInfo.bmiHeader.biCompression = BI_RGB;

BYTE *pvBits = new(std::nothrow) BYTE[BitmapInfo.bmiHeader.biSizeImage];
BYTE *pvBits = new (std::nothrow) BYTE[BitmapInfo.bmiHeader.biSizeImage];

if (pvBits)
{
Expand Down
6 changes: 5 additions & 1 deletion TranslucentFlyouts/Win32HookHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void TranslucentFlyoutsLib::Win32HookStartup()
Detours::Batch(
TRUE,
DrawThemeBackgroundHook,
//
DrawThemeTextExHook,
DrawThemeTextHook,
DrawTextWHook,
Expand All @@ -56,6 +57,7 @@ void TranslucentFlyoutsLib::Win32HookShutdown()
Detours::Batch(
FALSE,
DrawThemeBackgroundHook,
//
DrawThemeTextExHook,
DrawThemeTextHook,
DrawTextWHook,
Expand Down Expand Up @@ -327,6 +329,7 @@ HRESULT WINAPI TranslucentFlyoutsLib::MyDrawThemeTextEx(
// pOptions可以为NULL,使用NULL时与DrawThemeText效果无异
HRESULT hr = S_OK;

// GdiDbgPrint(hdc, pszText);
if (
IsAllowTransparent() and
(
Expand All @@ -341,7 +344,8 @@ HRESULT WINAPI TranslucentFlyoutsLib::MyDrawThemeTextEx(
!(pOptions->dwFlags & DTT_CALCRECT) and
!(pOptions->dwFlags & DTT_COMPOSITED)
)
)
) and
!VerifyCaller(g_hModule)
)
{
DTTOPTS Options = *pOptions;
Expand Down
1 change: 1 addition & 0 deletions TranslucentFlyoutsGUI/TranslucentFlyoutsGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -894,4 +894,5 @@ int APIENTRY _tWinMain(
ShowBalloonTip(g_mainWindow, pszText, pszCaption, 3000, NIIF_INFO);
return -1;
}
return 0;
}

0 comments on commit 6df2dd2

Please sign in to comment.