Skip to content

Commit

Permalink
常规修复
Browse files Browse the repository at this point in the history
  • Loading branch information
ALTaleX531 committed Aug 9, 2023
1 parent f6bee65 commit 155c48a
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 12 deletions.
3 changes: 3 additions & 0 deletions TFMain/DXHelper.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "pch.h"
#include "Utils.hpp"
#include "Hooking.hpp"
#include "DXHelper.hpp"

Expand Down Expand Up @@ -246,6 +247,8 @@ void LazyD3D::CreateDeviceResources()
{
try
{
auto CleanUp{Utils::RoInit()};

com_ptr<IDXGIDevice3> dxgiDevice{nullptr};
com_ptr<ID3D11Device> d3dDevice{nullptr};

Expand Down
6 changes: 4 additions & 2 deletions TFMain/MenuAnimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,9 @@ namespace TranslucentFlyouts::MenuAnimation
Attach();

Utils::CloakWindow(m_menuWindow, TRUE);
SetCapture(m_menuWindow);

window = CreateWindowExW(
WS_EX_NOREDIRECTIONBITMAP | WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_PALETTEWINDOW,
WS_EX_NOREDIRECTIONBITMAP | WS_EX_LAYERED | WS_EX_TOPMOST | WS_EX_TOOLWINDOW,
L"Static",
L"PopupIn Animation",
WS_POPUP,
Expand Down Expand Up @@ -315,6 +314,9 @@ namespace TranslucentFlyouts::MenuAnimation
EffectHelper::EnableWindowDarkMode(window, info.useDarkMode);

menuHandler.ApplyEffect(L"Menu"sv, m_backdropWindow, info.useDarkMode);
menuHandler.HandleRoundCorners(L"Menu"sv, m_backdropWindow);
COLORREF color{DWMWA_COLOR_NONE};
DwmSetWindowAttribute(m_backdropWindow, DWMWA_BORDER_COLOR, &color, sizeof(color));
EffectHelper::EnableWindowDarkMode(m_backdropWindow, info.useDarkMode);
}
else
Expand Down
65 changes: 59 additions & 6 deletions TFMain/MenuHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ thread_local decltype(MenuHandler::g_sharedContext) MenuHandler::g_sharedContext
thread_local decltype(MenuHandler::g_sharedMenuInfo) MenuHandler::g_sharedMenuInfo{false, false};
const UINT MenuHandler::WM_MHDETACH{RegisterWindowMessageW(L"TranslucentFlyouts.MenuHandler.Detach")};
const wstring_view MenuHandler::BackgroundBrushPropName{L"TranslucentFlyouts.MenuHandler.BackgroundBrush"};
const wstring_view MenuHandler::BorderMarkerPropName{L"TranslucentFlyouts.MenuHandler.BorderMarker"};

MenuHandler& MenuHandler::GetInstance()
{
Expand Down Expand Up @@ -58,7 +59,18 @@ void MenuHandler::MenuOwnerMsgCallback(HWND hwnd, UINT message, WPARAM wParam, L

if (g_sharedMenuInfo.useUxTheme)
{
GetInstance().HandleSysBorderColors(L"Menu"sv, menuWindow, g_sharedMenuInfo.useDarkMode, g_sharedMenuInfo.borderColor);
DWORD cornerType
{
RegHelper::GetDword(
L"Menu",
L"CornerType",
3
)
};
if (cornerType != 1 && SUCCEEDED(GetInstance().HandleSysBorderColors(L"Menu"sv, menuWindow, g_sharedMenuInfo.useDarkMode, g_sharedMenuInfo.borderColor)))
{
SetPropW(menuWindow, BorderMarkerPropName.data(), reinterpret_cast<HANDLE>(HANDLE_FLAG_INHERIT));
}
GetInstance().HandleRoundCorners(L"Menu"sv, menuWindow);
}
}
Expand Down Expand Up @@ -420,7 +432,18 @@ LRESULT CALLBACK MenuHandler::SubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam,
result = DefSubclassProc(hWnd, uMsg, wParam, lParam);
g_sharedContext.menuDC = nullptr;

GetInstance().HandleSysBorderColors(L"Menu"sv, hWnd, g_sharedMenuInfo.useDarkMode, g_sharedMenuInfo.borderColor);
DWORD cornerType
{
RegHelper::GetDword(
L"Menu",
L"CornerType",
3
)
};
if (cornerType != 1 && SUCCEEDED(GetInstance().HandleSysBorderColors(L"Menu"sv, hWnd, g_sharedMenuInfo.useDarkMode, g_sharedMenuInfo.borderColor)))
{
SetPropW(hWnd, BorderMarkerPropName.data(), reinterpret_cast<HANDLE>(HANDLE_FLAG_INHERIT));
}
GetInstance().HandleRoundCorners(L"Menu"sv, hWnd);
}

Expand Down Expand Up @@ -500,7 +523,18 @@ LRESULT CALLBACK MenuHandler::SubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam,
else
{
menuHandler.ApplyEffect(L"Menu"sv, hWnd, info.useDarkMode);
GetInstance().HandleSysBorderColors(L"Menu"sv, hWnd, info.useDarkMode, info.borderColor);
DWORD cornerType
{
RegHelper::GetDword(
L"Menu",
L"CornerType",
3
)
};
if (cornerType != 1 && SUCCEEDED(GetInstance().HandleSysBorderColors(L"Menu"sv, hWnd, info.useDarkMode, info.borderColor)))
{
SetPropW(hWnd, BorderMarkerPropName.data(), reinterpret_cast<HANDLE>(HANDLE_FLAG_INHERIT));
}
GetInstance().HandleRoundCorners(L"Menu"sv, hWnd);

try
Expand Down Expand Up @@ -618,7 +652,14 @@ LRESULT CALLBACK MenuHandler::SubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam,
GetWindowRect(hWnd, &paintRect);
OffsetRect(&paintRect, -paintRect.left, -paintRect.top);

menuHandler.HandlePopupMenuNCBorderColors(hdc.get(), g_sharedMenuInfo.useDarkMode, paintRect);
if (!GetPropW(hWnd, BorderMarkerPropName.data()))
{
menuHandler.HandlePopupMenuNCBorderColors(hdc.get(), g_sharedMenuInfo.useDarkMode, paintRect);
}
else
{
LOG_LAST_ERROR_IF(!FrameRect(hdc.get(), &paintRect, GetStockBrush(BLACK_BRUSH)));
}
}
}

Expand All @@ -642,21 +683,33 @@ LRESULT CALLBACK MenuHandler::SubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam,
GetWindowRect(hWnd, &paintRect);
OffsetRect(&paintRect, -paintRect.left, -paintRect.top);

menuHandler.HandlePopupMenuNCBorderColors(hdc.get(), g_sharedMenuInfo.useDarkMode, paintRect);
if (!GetPropW(hWnd, BorderMarkerPropName.data()))
{
menuHandler.HandlePopupMenuNCBorderColors(hdc.get(), g_sharedMenuInfo.useDarkMode, paintRect);
}
else
{
LOG_LAST_ERROR_IF(!FrameRect(hdc.get(), &paintRect, GetStockBrush(BLACK_BRUSH)));
}
}
}

if (uMsg == WM_NCDESTROY || uMsg == WM_MHDETACH)
{
auto brush{reinterpret_cast<HBRUSH>(GetPropW(hWnd, BackgroundBrushPropName.data()))};
if (brush)
if (GetLastError() == ERROR_SUCCESS)
{
MENUINFO mi{.cbSize{sizeof(mi)}, .fMask{MIM_BACKGROUND}, .hbrBack{brush}};
LOG_HR_IF(E_FAIL, !SetMenuInfo(reinterpret_cast<HMENU>(DefSubclassProc(hWnd, MN_GETHMENU, 0, 0)), &mi));

RemovePropW(hWnd, BackgroundBrushPropName.data());
}

if (GetPropW(hWnd, BorderMarkerPropName.data()))
{
RemovePropW(hWnd, BorderMarkerPropName.data());
}

if (uMsg == WM_MHDETACH)
{
RemovePropW(hWnd, L"IsZachMenuDWMAttributeSet");
Expand Down
1 change: 1 addition & 0 deletions TFMain/MenuHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ namespace TranslucentFlyouts

static const UINT WM_MHDETACH;
static const std::wstring_view BackgroundBrushPropName;
static const std::wstring_view BorderMarkerPropName;

bool m_internalError{false};
std::list<HWND> m_hookedWindowList{};
Expand Down
4 changes: 0 additions & 4 deletions TFMain/TFMain.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<ModuleDefinitionFile>GlobalFunctions.def</ModuleDefinitionFile>
<DelayLoadDLLs>dcomp.dll;d2d1.dll;d3d11.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand Down Expand Up @@ -151,7 +150,6 @@
<GenerateDebugInformation>DebugFull</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<ModuleDefinitionFile>GlobalFunctions.def</ModuleDefinitionFile>
<DelayLoadDLLs>dcomp.dll;d2d1.dll;d3d11.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand All @@ -170,7 +168,6 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<ModuleDefinitionFile>GlobalFunctions.def</ModuleDefinitionFile>
<DelayLoadDLLs>dcomp.dll;d2d1.dll;d3d11.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand Down Expand Up @@ -202,7 +199,6 @@
<GenerateDebugInformation>DebugFull</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<ModuleDefinitionFile>GlobalFunctions.def</ModuleDefinitionFile>
<DelayLoadDLLs>dcomp.dll;d2d1.dll;d3d11.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
Expand Down

0 comments on commit 155c48a

Please sign in to comment.