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

Commit 9f83adb

Browse files
committed
修改配置读取方式,更新了GUI并添加授权信息等
1 parent 22f4fbc commit 9f83adb

9 files changed

+423
-114
lines changed

TranslucentFlyouts/SettingsHelper.h

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#pragma once
2+
#include "pch.h"
3+
#include "tflapi.h"
4+
5+
namespace TranslucentFlyoutsLib
6+
{
7+
class Settings
8+
{
9+
private:
10+
BYTE bOpacity = (BYTE)GetCurrentFlyoutOpacity();
11+
DWORD dwEffect = GetCurrentFlyoutEffect();
12+
DWORD dwBorder = GetCurrentFlyoutBorder();
13+
DWORD dwPolicy = GetCurrentFlyoutPolicy();
14+
DWORD dwColorizeOption = GetCurrentFlyoutColorizeOption();
15+
public:
16+
inline void Update()
17+
{
18+
bOpacity = (BYTE)GetCurrentFlyoutOpacity();
19+
dwEffect = GetCurrentFlyoutEffect();
20+
dwBorder = GetCurrentFlyoutBorder();
21+
dwPolicy = GetCurrentFlyoutPolicy();
22+
dwColorizeOption = GetCurrentFlyoutColorizeOption();
23+
}
24+
25+
inline BYTE GetOpacity()
26+
{
27+
return bOpacity;
28+
}
29+
30+
inline DWORD GetEffect()
31+
{
32+
return dwEffect;
33+
}
34+
35+
inline DWORD GetBorder()
36+
{
37+
return dwBorder;
38+
}
39+
40+
inline DWORD GetPolicy()
41+
{
42+
return dwPolicy;
43+
}
44+
45+
inline DWORD GetColorizeOption()
46+
{
47+
return dwColorizeOption;
48+
}
49+
};
50+
}

TranslucentFlyouts/TranslucentFlyouts.vcxproj

+1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
<ClInclude Include="AcrylicHelper.h" />
160160
<ClInclude Include="DebugHelper.h" />
161161
<ClInclude Include="HookHelper.h" />
162+
<ClInclude Include="SettingsHelper.h" />
162163
<ClInclude Include="WindowsRuntime.h" />
163164
<ClInclude Include="DetoursHelper.h" />
164165
<ClInclude Include="tflapi.h" />

TranslucentFlyouts/TranslucentFlyouts.vcxproj.filters

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
<ClInclude Include="DebugHelper.h">
4343
<Filter>头文件</Filter>
4444
</ClInclude>
45+
<ClInclude Include="SettingsHelper.h">
46+
<Filter>头文件</Filter>
47+
</ClInclude>
4548
</ItemGroup>
4649
<ItemGroup>
4750
<ClCompile Include="dllmain.cpp">

TranslucentFlyouts/TranslucentFlyoutsLib.cpp

+33-28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "pch.h"
22
#include "tflapi.h"
3+
#include "SettingsHelper.h"
34
#include "DebugHelper.h"
45
#include "ThemeHelper.h"
56
#include "AcrylicHelper.h"
@@ -26,6 +27,10 @@ DetoursHook DeleteDCHook("Gdi32", "DeleteDC", MyDeleteDC);
2627
DetoursHook DeleteObjectHook("Gdi32", "DeleteObject", MyDeleteObject);
2728

2829
thread_local HWND g_hWnd = nullptr;
30+
#pragma data_seg("shared")
31+
Settings g_settings = {};
32+
#pragma data_seg()
33+
#pragma comment(linker,"/SECTION:shared,RWS")
2934

3035
void SetCurrentMenuFlyout(HWND hWnd)
3136
{
@@ -157,7 +162,7 @@ HRESULT WINAPI TranslucentFlyoutsLib::MyDrawThemeBackground(
157162
if (
158163
IsAllowTransparent() and
159164
VerifyThemeData(hTheme, TEXT("Tooltip")) and
160-
(GetCurrentFlyoutPolicy() & Tooltip) and
165+
(g_settings.GetPolicy() & Tooltip) and
161166
(
162167
iPartId == TTP_STANDARD or
163168
iPartId == TTP_BALLOON or
@@ -170,7 +175,7 @@ HRESULT WINAPI TranslucentFlyoutsLib::MyDrawThemeBackground(
170175
!VerifyThemeBackgroundTransparency(hTheme, iPartId, iStateId)
171176
)
172177
{
173-
if (!DoBufferedPaint(hdc, &Rect, f, (BYTE)GetCurrentFlyoutOpacity()))
178+
if (!DoBufferedPaint(hdc, &Rect, f, (BYTE)g_settings.GetOpacity()))
174179
{
175180
goto Default;
176181
}
@@ -187,15 +192,15 @@ HRESULT WINAPI TranslucentFlyoutsLib::MyDrawThemeBackground(
187192
VerifyThemeData(hTheme, TEXT("Toolbar")) and
188193
(iPartId == 0 and iStateId == 0) and
189194
(
190-
(GetCurrentFlyoutPolicy() & ViewControl) and
195+
(g_settings.GetPolicy() & ViewControl) and
191196
(
192197
IsViewControlFlyout(GetParent(GetWindowFromHDC(hdc))) or
193198
!IsWindow(GetWindowFromHDC(hdc))
194199
)
195200
)
196201
)
197202
{
198-
if (!DoBufferedPaint(hdc, &Rect, f, (BYTE)GetCurrentFlyoutOpacity()))
203+
if (!DoBufferedPaint(hdc, &Rect, f, (BYTE)g_settings.GetOpacity()))
199204
{
200205
goto Default;
201206
}
@@ -207,12 +212,12 @@ HRESULT WINAPI TranslucentFlyoutsLib::MyDrawThemeBackground(
207212
(
208213
VerifyThemeData(hTheme, TEXT("Menu")) and
209214
(
210-
(GetCurrentFlyoutPolicy() & PopupMenu) and
215+
(g_settings.GetPolicy() & PopupMenu) and
211216
!IsViewControlFlyout(GetWindowFromHDC(hdc)) and
212217
!IsViewControlFlyout(GetParent(GetWindowFromHDC(hdc)))
213218
) or
214219
(
215-
(GetCurrentFlyoutPolicy() & ViewControl) and
220+
(g_settings.GetPolicy() & ViewControl) and
216221
(
217222
IsViewControlFlyout(GetWindowFromHDC(hdc)) or
218223
IsViewControlFlyout(GetParent(GetWindowFromHDC(hdc)))
@@ -227,8 +232,8 @@ HRESULT WINAPI TranslucentFlyoutsLib::MyDrawThemeBackground(
227232
{
228233
SetWindowEffect(
229234
GetCurrentMenuFlyout(),
230-
GetCurrentFlyoutEffect(),
231-
GetCurrentFlyoutBorder()
235+
g_settings.GetEffect(),
236+
g_settings.GetBorder()
232237
);
233238
SetCurrentMenuFlyout(nullptr);
234239
}
@@ -238,7 +243,7 @@ HRESULT WINAPI TranslucentFlyoutsLib::MyDrawThemeBackground(
238243
iPartId == MENU_POPUPBACKGROUND or
239244
iPartId == MENU_POPUPGUTTER or
240245
(
241-
GetCurrentFlyoutColorizeOption() == 0 ?
246+
g_settings.GetColorizeOption() == 0 ?
242247
(iPartId == MENU_POPUPITEM and iStateId != MPI_HOT) :
243248
(iPartId == MENU_POPUPITEM)
244249
) or
@@ -253,7 +258,7 @@ HRESULT WINAPI TranslucentFlyoutsLib::MyDrawThemeBackground(
253258
)
254259
)
255260
{
256-
if (!DoBufferedPaint(hdc, &Rect, f, (BYTE)GetCurrentFlyoutOpacity(), BPPF_ERASE | (iPartId == MENU_POPUPBORDERS ? BPPF_NONCLIENT : 0UL)))
261+
if (!DoBufferedPaint(hdc, &Rect, f, (BYTE)g_settings.GetOpacity(), BPPF_ERASE | (iPartId == MENU_POPUPBORDERS ? BPPF_NONCLIENT : 0UL)))
257262
{
258263
goto Default;
259264
}
@@ -322,9 +327,9 @@ HRESULT WINAPI TranslucentFlyoutsLib::MyDrawThemeTextEx(
322327
if (
323328
IsAllowTransparent() and
324329
(
325-
(VerifyThemeData(hTheme, TEXT("Menu")) and GetCurrentFlyoutPolicy() & PopupMenu) or
326-
(VerifyThemeData(hTheme, TEXT("Toolbar")) and GetCurrentFlyoutPolicy() & ViewControl) or
327-
(VerifyThemeData(hTheme, TEXT("Tooltip")) and GetCurrentFlyoutPolicy() & Tooltip)
330+
(VerifyThemeData(hTheme, TEXT("Menu")) and g_settings.GetPolicy() & PopupMenu) or
331+
(VerifyThemeData(hTheme, TEXT("Toolbar")) and g_settings.GetPolicy() & ViewControl) or
332+
(VerifyThemeData(hTheme, TEXT("Tooltip")) and g_settings.GetPolicy() & Tooltip)
328333
) and
329334
pOptions and
330335
(
@@ -404,9 +409,9 @@ HRESULT WINAPI TranslucentFlyoutsLib::MyDrawThemeText(
404409
IsAllowTransparent() and
405410
pRect and
406411
(
407-
(VerifyThemeData(hTheme, TEXT("Menu")) and GetCurrentFlyoutPolicy() & PopupMenu) or
408-
(VerifyThemeData(hTheme, TEXT("Toolbar")) and GetCurrentFlyoutPolicy() & ViewControl) or
409-
(VerifyThemeData(hTheme, TEXT("Tooltip")) and GetCurrentFlyoutPolicy() & Tooltip)
412+
(VerifyThemeData(hTheme, TEXT("Menu")) and g_settings.GetPolicy() & PopupMenu) or
413+
(VerifyThemeData(hTheme, TEXT("Toolbar")) and g_settings.GetPolicy() & ViewControl) or
414+
(VerifyThemeData(hTheme, TEXT("Tooltip")) and g_settings.GetPolicy() & Tooltip)
410415
)
411416
)
412417
{
@@ -621,7 +626,7 @@ BOOL WINAPI TranslucentFlyoutsLib::MySetMenuInfo(
621626
(lpMenuInfo->fMask & MIM_BACKGROUND) and
622627
lpMenuInfo->hbrBack and
623628
IsAllowTransparent() and
624-
(GetCurrentFlyoutPolicy() & PopupMenu)
629+
(g_settings.GetPolicy() & PopupMenu)
625630
)
626631
{
627632
PBYTE pvBits = nullptr;
@@ -639,7 +644,7 @@ BOOL WINAPI TranslucentFlyoutsLib::MySetMenuInfo(
639644
GetBValue(dwColor),
640645
GetGValue(dwColor),
641646
GetRValue(dwColor),
642-
(BYTE)GetCurrentFlyoutOpacity()
647+
(BYTE)g_settings.GetOpacity()
643648
);
644649
// 创建位图画刷
645650
// 只有位图画刷才有Alpha值
@@ -696,7 +701,7 @@ BOOL WINAPI TranslucentFlyoutsLib::MySetMenuItemBitmaps(
696701
{
697702
BOOL bResult = FALSE;
698703

699-
if (IsAllowTransparent() and GetCurrentFlyoutPolicy() & PopupMenu)
704+
if (IsAllowTransparent() and g_settings.GetPolicy() & PopupMenu)
700705
{
701706
PrepareAlpha(hBitmapUnchecked);
702707
PrepareAlpha(hBitmapChecked);
@@ -721,7 +726,7 @@ BOOL WINAPI TranslucentFlyoutsLib::MyInsertMenuItemW(
721726
{
722727
BOOL bResult = FALSE;
723728

724-
if (IsAllowTransparent() and lpmii and (lpmii->fMask & MIIM_CHECKMARKS or lpmii->fMask & MIIM_BITMAP) and GetCurrentFlyoutPolicy() & PopupMenu)
729+
if (IsAllowTransparent() and lpmii and (lpmii->fMask & MIIM_CHECKMARKS or lpmii->fMask & MIIM_BITMAP) and g_settings.GetPolicy() & PopupMenu)
725730
{
726731
PrepareAlpha(lpmii->hbmpItem);
727732
PrepareAlpha(lpmii->hbmpUnchecked);
@@ -745,7 +750,7 @@ BOOL WINAPI TranslucentFlyoutsLib::MySetMenuItemInfoW(
745750
{
746751
BOOL bResult = FALSE;
747752

748-
if (IsAllowTransparent() and lpmii and (lpmii->fMask & MIIM_CHECKMARKS or lpmii->fMask & MIIM_BITMAP) and GetCurrentFlyoutPolicy() & PopupMenu)
753+
if (IsAllowTransparent() and lpmii and (lpmii->fMask & MIIM_CHECKMARKS or lpmii->fMask & MIIM_BITMAP) and g_settings.GetPolicy() & PopupMenu)
749754
{
750755
PrepareAlpha(lpmii->hbmpItem);
751756
PrepareAlpha(lpmii->hbmpUnchecked);
@@ -844,16 +849,16 @@ void TranslucentFlyoutsLib::OnWindowsCreated(HWND hWnd)
844849
{
845850
if (IsAllowTransparent())
846851
{
847-
if (IsPopupMenuFlyout(hWnd) and GetCurrentFlyoutPolicy() & PopupMenu)
852+
if (IsPopupMenuFlyout(hWnd) and g_settings.GetPolicy() & PopupMenu)
848853
{
849854
SetCurrentMenuFlyout(hWnd);
850855
}
851-
if (IsViewControlFlyout(hWnd) and GetCurrentFlyoutPolicy() & ViewControl)
856+
if (IsViewControlFlyout(hWnd) and g_settings.GetPolicy() & ViewControl)
852857
{
853858
SetWindowEffect(
854859
hWnd,
855-
GetCurrentFlyoutEffect(),
856-
GetCurrentFlyoutBorder()
860+
g_settings.GetEffect(),
861+
g_settings.GetBorder()
857862
);
858863
}
859864
}
@@ -868,12 +873,12 @@ void TranslucentFlyoutsLib::OnWindowShowed(HWND hWnd)
868873
{
869874
if (IsAllowTransparent())
870875
{
871-
if (IsTooltipFlyout(hWnd) and GetCurrentFlyoutPolicy() & Tooltip)
876+
if (IsTooltipFlyout(hWnd) and g_settings.GetPolicy() & Tooltip)
872877
{
873878
SetWindowEffect(
874879
hWnd,
875-
GetCurrentFlyoutEffect(),
876-
GetCurrentFlyoutBorder()
880+
g_settings.GetEffect(),
881+
g_settings.GetBorder()
877882
);
878883
}
879884
}

TranslucentFlyouts/tflapi.cpp

+25-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
#include "pch.h"
22
#include "tflapi.h"
3+
#include "SettingsHelper.h"
34
#include "TranslucentFlyoutsLib.h"
45

56
#pragma data_seg("shared")
67
HWINEVENTHOOK g_hHook = nullptr;
78
#pragma data_seg()
89
#pragma comment(linker,"/SECTION:shared,RWS")
910

11+
using namespace TranslucentFlyoutsLib;
1012
extern HMODULE g_hModule;
13+
extern Settings g_settings;
1114

1215
extern "C"
1316
{
@@ -207,11 +210,6 @@ extern "C"
207210
return TRUE;
208211
}
209212

210-
FLOAT WINAPI GetVersionInfo()
211-
{
212-
return 1.01f;
213-
}
214-
215213
BOOL WINAPI IsHookInstalled()
216214
{
217215
return g_hHook != 0;
@@ -233,4 +231,26 @@ extern "C"
233231
}
234232
return TRUE;
235233
}
234+
235+
VOID WINAPI GetVersionString(LPWSTR pszClassName, const int cchClassName)
236+
{
237+
wcscpy_s(pszClassName, cchClassName, L"1.0.1");
238+
}
239+
240+
VOID WINAPI FlushSettingsCache()
241+
{
242+
TCHAR pszMutexName[] = TEXT("Local\\FlushSettingsCache");
243+
HANDLE hMutex = OpenMutex(SYNCHRONIZE, FALSE, pszMutexName);
244+
if (!hMutex)
245+
{
246+
hMutex = CreateMutex(nullptr, TRUE, pszMutexName);
247+
}
248+
else
249+
{
250+
WaitForSingleObject(hMutex, INFINITE);
251+
}
252+
g_settings.Update();
253+
ReleaseMutex(hMutex);
254+
CloseHandle(hMutex);
255+
}
236256
}

TranslucentFlyouts/tflapi.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ TFLAPI BOOL WINAPI SetFlyoutBorder(DWORD dwBorder);
4040
TFLAPI BOOL WINAPI SetFlyoutColorizeOption(DWORD dwColorizeOption);
4141
TFLAPI BOOL WINAPI SetFlyoutPolicy(DWORD dwPolicy);
4242

43-
TFLAPI FLOAT WINAPI GetVersionInfo();
4443
TFLAPI BOOL WINAPI IsHookInstalled();
4544
TFLAPI BOOL WINAPI ClearFlyoutConfig();
45+
TFLAPI VOID WINAPI GetVersionString(LPWSTR pszClassName, const int cchClassName);
46+
TFLAPI VOID WINAPI FlushSettingsCache();
4647

4748
#ifdef __cplusplus
4849
}

0 commit comments

Comments
 (0)