This repository has been archived by the owner on Jul 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
udwmPrivates.hpp
1219 lines (1147 loc) · 32.2 KB
/
udwmPrivates.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma once
#include "framework.h"
#include "cpprt.h"
#include "wil.h"
#include "HookHelper.hpp"
#include "dcompPrivates.hpp"
namespace AcrylicEverywhere::uDwmPrivates
{
inline HANDLE g_hProcessHeap{ GetProcessHeap() };
inline wil::unique_hmodule g_udwmModule{ nullptr };
inline std::unordered_map<std::string, HookHelper::OffsetStorage> g_offsetMap{};
struct CBaseObject
{
void* operator new(size_t size)
{
return HeapAlloc(g_hProcessHeap, 0, size);
}
void operator delete(void* ptr)
{
if (ptr)
{
HeapFree(g_hProcessHeap, 0, ptr);
}
}
size_t AddRef()
{
return InterlockedIncrement(reinterpret_cast<DWORD*>(this) + 2);
}
size_t Release()
{
auto result{ InterlockedDecrement(reinterpret_cast<DWORD*>(this) + 2) };
if (!result)
{
delete this;
}
return result;
}
HRESULT QueryInterface(REFIID riid, PVOID* ppvObject)
{
*ppvObject = this;
return S_OK;
}
template <typename T, typename... Args>
static HRESULT Create(T** object, Args&&... args) try
{
winrt::com_ptr<T> allocatedObject{ new T(std::forward<Args>(args)...), winrt::take_ownership_from_abi };
THROW_IF_FAILED(allocatedObject->Initialize());
*object = allocatedObject.detach();
return S_OK;
}
catch(...) { return wil::ResultFromCaughtException(); }
protected:
virtual ~CBaseObject() {};
};
#pragma push_macro("UDWM_CALL_ORG")
#pragma push_macro("UDWM_CALL_ORG_STATIC")
#define UDWM_CALL_ORG(name, ...) [&]{ static const auto s_ptr{ AcrylicEverywhere::uDwmPrivates::g_offsetMap.at(#name).To(AcrylicEverywhere::uDwmPrivates::g_udwmModule.get()) }; return (this->*HookHelper::union_cast<decltype(&name)>(s_ptr))(## __VA_ARGS__); } ()
#define UDWM_CALL_ORG_STATIC(name, ...) [&]{ static const auto s_ptr{AcrylicEverywhere::uDwmPrivates::g_offsetMap.at(#name).To(AcrylicEverywhere::uDwmPrivates::g_udwmModule.get())}; return (HookHelper::union_cast<decltype(&name)>(s_ptr))(## __VA_ARGS__);} ()
#define UDWM_CALL_ORG_BY_TYPE(type, object, name, ...) [&]{ static const auto s_ptr{AcrylicEverywhere::uDwmPrivates::g_offsetMap.at(name).To(AcrylicEverywhere::uDwmPrivates::g_udwmModule.get())}; return (object->*HookHelper::union_cast<type>(s_ptr))(## __VA_ARGS__); } ()
#define UDWM_CALL_ORG_STATIC_BY_TYPE(type, name, ...) [&]{ static const auto s_ptr{AcrylicEverywhere::uDwmPrivates::g_offsetMap.at(name).To(AcrylicEverywhere::uDwmPrivates::g_udwmModule.get())}; return (HookHelper::union_cast<type>(s_ptr))(## __VA_ARGS__); } ()
struct CBaseGeometryProxy : CBaseObject {};
struct CBaseTransformProxy : CBaseObject {};
struct CCombinedGeometryProxy : CBaseGeometryProxy {};
struct CRgnGeometryProxy : CBaseGeometryProxy
{
HRESULT STDMETHODCALLTYPE Update(LPCRECT rectangles, UINT count)
{
return UDWM_CALL_ORG(CRgnGeometryProxy::Update, rectangles, count);
}
};
namespace ResourceHelper
{
static HRESULT STDMETHODCALLTYPE CreateCombinedGeometry(CBaseGeometryProxy* geometry1, CBaseGeometryProxy* geometry2, UINT combinedMode, CCombinedGeometryProxy** combinedGeometry)
{
return UDWM_CALL_ORG_STATIC(ResourceHelper::CreateCombinedGeometry, geometry1, geometry2, combinedMode, combinedGeometry);
}
static HRESULT STDMETHODCALLTYPE CreateGeometryFromHRGN(
HRGN hrgn,
uDwmPrivates::CRgnGeometryProxy** geometry
)
{
return UDWM_CALL_ORG_STATIC(ResourceHelper::CreateGeometryFromHRGN, hrgn, geometry);
}
}
struct VisualCollection;
struct CResourceProxy : CBaseObject {};
struct CBaseLegacyMilBrushProxy : CBaseObject {};
struct CSolidColorLegacyMilBrushProxy : CBaseLegacyMilBrushProxy {};
struct CVisualProxy : CBaseObject
{
HRESULT STDMETHODCALLTYPE SetTransform(CBaseTransformProxy* transfrom) { return UDWM_CALL_ORG(CVisualProxy::SetTransform, transfrom); }
HRESULT STDMETHODCALLTYPE SetClip(CBaseGeometryProxy* geometry) { return UDWM_CALL_ORG(CVisualProxy::SetClip, geometry); }
HRESULT STDMETHODCALLTYPE SetSize(double width, double height) { return UDWM_CALL_ORG(CVisualProxy::SetSize, width, height); }
};
struct CVisual : CBaseObject
{
VisualCollection* GetVisualCollection() const
{
if (SystemHelper::g_buildNumber < 26020)
{
return const_cast<VisualCollection*>(reinterpret_cast<VisualCollection const*>(reinterpret_cast<const char*>(this) + 32));
}
return const_cast<VisualCollection*>(reinterpret_cast<VisualCollection const*>(reinterpret_cast<const char*>(this) + 144));
}
CVisualProxy* GetVisualProxy() const
{
return reinterpret_cast<CVisualProxy* const*>(this)[2];
}
CVisual* GetParent() const
{
return reinterpret_cast<CVisual* const*>(this)[3];
}
HRESULT STDMETHODCALLTYPE SetParent(CVisual* visual)
{
return UDWM_CALL_ORG(CVisual::SetParent, visual);
}
bool IsCloneAllowed() const
{
const BYTE* properties{ nullptr };
if (SystemHelper::g_buildNumber < 22000)
{
properties = &reinterpret_cast<BYTE const*>(this)[84];
}
else if (SystemHelper::g_buildNumber < 22621)
{
properties = &reinterpret_cast<BYTE const*>(this)[92];
}
else if (SystemHelper::g_buildNumber < 26020)
{
properties = &reinterpret_cast<BYTE const*>(this)[92];
}
else
{
properties = &reinterpret_cast<BYTE const*>(this)[36];
}
bool allowed{ false };
if (properties)
{
allowed = (*properties & 8) == 0;
}
return allowed;
}
bool AllowVisualTreeClone(bool allow)
{
BYTE* properties{nullptr};
if (SystemHelper::g_buildNumber < 22000)
{
properties = &reinterpret_cast<BYTE*>(this)[84];
}
else if (SystemHelper::g_buildNumber < 22621)
{
properties = &reinterpret_cast<BYTE*>(this)[92];
}
else if (SystemHelper::g_buildNumber < 26020)
{
properties = &reinterpret_cast<BYTE*>(this)[92];
}
else
{
properties = &reinterpret_cast<BYTE*>(this)[36];
}
bool allowed{false};
if (properties)
{
allowed = (*properties & 8) == 0;
if (allow)
{
*properties = *properties & ~8;
}
else
{
*properties |= 8;
}
}
return allowed;
}
bool IsVisible()
{
if (SystemHelper::g_buildNumber < 22000)
{
return *(reinterpret_cast<DWORD*>(this) + 22) == 0;
}
else if (SystemHelper::g_buildNumber < 26020)
{
return *(reinterpret_cast<DWORD*>(this) + 24) == 0;
}
else
{
return *(reinterpret_cast<DWORD*>(this) + 10) == 0;
}
return true;
}
void STDMETHODCALLTYPE SetInsetFromParent(MARGINS* margins)
{
return UDWM_CALL_ORG(CVisual::SetInsetFromParent, margins);
}
HRESULT STDMETHODCALLTYPE SetSize(const SIZE& size)
{
return UDWM_CALL_ORG(CVisual::SetSize, size);
}
void STDMETHODCALLTYPE SetOffset(const POINT& pt)
{
return UDWM_CALL_ORG(CVisual::SetOffset, pt);
}
HRESULT STDMETHODCALLTYPE UpdateOffset()
{
return UDWM_CALL_ORG(CVisual::UpdateOffset, );
}
HRESULT STDMETHODCALLTYPE InitializeVisualTreeClone(CBaseObject* baseObject, UINT cloneOptions)
{
return UDWM_CALL_ORG(CVisual::InitializeVisualTreeClone, baseObject, cloneOptions);
}
void STDMETHODCALLTYPE Unhide()
{
return UDWM_CALL_ORG(CVisual::Unhide, );
}
void STDMETHODCALLTYPE Hide()
{
return UDWM_CALL_ORG(CVisual::Hide, );
}
HRESULT STDMETHODCALLTYPE ConnectToParent(bool connect)
{
return UDWM_CALL_ORG(CVisual::ConnectToParent, connect);
}
void STDMETHODCALLTYPE SetOpacity(double opacity)
{
return UDWM_CALL_ORG(CVisual::SetOpacity, opacity);
}
HRESULT STDMETHODCALLTYPE UpdateOpacity()
{
return UDWM_CALL_ORG(CVisual::UpdateOpacity, );
}
void STDMETHODCALLTYPE SetScale(double x, double y)
{
return UDWM_CALL_ORG(CVisual::SetScale, x, y);
}
HRESULT STDMETHODCALLTYPE SendSetOpacity(double opacity)
{
return UDWM_CALL_ORG(CVisual::SendSetOpacity, opacity);
}
HRESULT STDMETHODCALLTYPE RenderRecursive()
{
return UDWM_CALL_ORG(CVisual::RenderRecursive, );
}
void Cloak(bool cloak)
{
if (!cloak)
{
SetOpacity(1.);
UpdateOpacity();
}
else
{
SetOpacity(0.);
UpdateOpacity();
}
}
void STDMETHODCALLTYPE SetDirtyChildren()
{
if (SystemHelper::g_buildNumber < 26020)
{
return UDWM_CALL_ORG(CVisual::SetDirtyChildren, );
}
else
{
return UDWM_CALL_ORG_BY_TYPE(decltype(&CVisual::SetDirtyChildren), this, "CContainerVisual");
}
}
static HRESULT WINAPI CreateFromSharedHandle(HANDLE handle, CVisual** visual)
{
return UDWM_CALL_ORG_STATIC(CVisual::CreateFromSharedHandle, handle, visual);
}
HRESULT STDMETHODCALLTYPE InitializeFromSharedHandle(HANDLE handle) { return UDWM_CALL_ORG(CVisual::InitializeFromSharedHandle, handle); }
HRESULT WINAPI MoveToFront(bool unknown) { return UDWM_CALL_ORG(CVisual::MoveToFront, unknown); }
HRESULT STDMETHODCALLTYPE Initialize() { return UDWM_CALL_ORG(CVisual::Initialize, ); }
};
struct VisualCollection : CBaseObject
{
HRESULT STDMETHODCALLTYPE RemoveAll() { return UDWM_CALL_ORG(VisualCollection::RemoveAll, ); }
HRESULT STDMETHODCALLTYPE Remove(CVisual* visual) { return UDWM_CALL_ORG(VisualCollection::Remove, visual); }
HRESULT STDMETHODCALLTYPE InsertRelative(
CVisual* visual,
CVisual* referenceVisual,
bool insertAfter,
bool connectNow
)
{
return UDWM_CALL_ORG(VisualCollection::InsertRelative, visual, referenceVisual, insertAfter, connectNow);
}
};
struct IRenderDataBuilder : IUnknown
{
STDMETHOD(DrawBitmap)(UINT bitmapHandleTableIndex) PURE;
STDMETHOD(DrawGeometry)(UINT geometryHandleTableIndex, UINT brushHandleTableIndex) PURE;
STDMETHOD(DrawImage)(const D2D1_RECT_F& rect, UINT imageHandleTableIndex) PURE;
STDMETHOD(DrawMesh2D)(UINT meshHandleTableIndex, UINT brushHandleTableIndex) PURE;
STDMETHOD(DrawRectangle)(const D2D1_RECT_F* rect, UINT brushHandleTableIndex) PURE;
STDMETHOD(DrawTileImage)(UINT imageHandleTableIndex, const D2D1_RECT_F& rect, float opacity, const D2D1_POINT_2F& point) PURE;
STDMETHOD(DrawVisual)(UINT visualHandleTableIndex) PURE;
STDMETHOD(Pop)() PURE;
STDMETHOD(PushTransform)(UINT transformHandleTableInfex) PURE;
STDMETHOD(DrawSolidRectangle)(const D2D1_RECT_F& rect, const D2D1_COLOR_F& color) PURE;
};
struct CRenderDataInstruction : CBaseObject
{
STDMETHOD(WriteInstruction)(
IRenderDataBuilder* builder,
const struct CVisual* visual
) PURE;
};
struct CDrawGeometryInstruction : CRenderDataInstruction
{
static HRESULT STDMETHODCALLTYPE Create(CBaseLegacyMilBrushProxy* brush, CBaseGeometryProxy* geometry, CDrawGeometryInstruction** instruction)
{
return UDWM_CALL_ORG_STATIC(CDrawGeometryInstruction::Create, brush, geometry, instruction);
}
};
struct CRenderDataVisual : CVisual
{
HRESULT STDMETHODCALLTYPE AddInstruction(CRenderDataInstruction* instruction)
{
return UDWM_CALL_ORG(CRenderDataVisual::AddInstruction, instruction);
}
HRESULT STDMETHODCALLTYPE ClearInstructions()
{
return UDWM_CALL_ORG(CRenderDataVisual::ClearInstructions, );
}
};
struct CCanvasVisual : CRenderDataVisual
{
static HRESULT STDMETHODCALLTYPE Create(CCanvasVisual** visual)
{
return UDWM_CALL_ORG_STATIC(CCanvasVisual::Create, visual);
}
};
class CEmptyDrawInstruction : public CRenderDataInstruction
{
DWORD m_refCount{ 1 };
public:
HRESULT STDMETHODCALLTYPE Initialize() { return S_OK; }
STDMETHOD(WriteInstruction)(
IRenderDataBuilder* builder,
const struct CVisual* visual
) override
{
return S_OK;
}
};
class CDrawVisualTreeInstruction : public CRenderDataInstruction
{
DWORD m_refCount{ 1 };
winrt::com_ptr<CVisual> m_visual{ nullptr };
public:
CDrawVisualTreeInstruction(CVisual* visual) : CRenderDataInstruction{} { m_visual.copy_from(visual); }
HRESULT STDMETHODCALLTYPE Initialize() { return S_OK; }
STDMETHOD(WriteInstruction)(
IRenderDataBuilder* builder,
const struct CVisual* visual
) override
{
UINT visualHandleTableIndex{ 0 };
auto visualProxy{ m_visual->GetVisualProxy() };
if (visualProxy)
{
visualHandleTableIndex = *reinterpret_cast<UINT*>(
*reinterpret_cast<ULONG_PTR*>(reinterpret_cast<ULONG_PTR>(visualProxy) + 16) + 24ull
);
}
return builder->DrawVisual(visualHandleTableIndex);
}
};
struct ACCENT_POLICY
{
DWORD AccentState;
DWORD AccentFlags;
DWORD dwGradientColor;
DWORD dwAnimationId;
};
bool IsAccentBlurEnabled(const ACCENT_POLICY* accentPolicy)
{
return accentPolicy->AccentState > 2 && accentPolicy->AccentState < 5;
}
struct CAccent : CVisual
{
static bool STDMETHODCALLTYPE s_IsPolicyActive(const ACCENT_POLICY* accentPolicy)
{
return UDWM_CALL_ORG_STATIC(CAccent::s_IsPolicyActive, accentPolicy);
}
CBaseGeometryProxy* const& GetClipGeometry() const
{
CBaseGeometryProxy* const* geometry{ nullptr };
if (SystemHelper::g_buildNumber < 22000)
{
geometry = &reinterpret_cast<CBaseGeometryProxy* const*>(this)[52];
}
else if (SystemHelper::g_buildNumber < 22621)
{
geometry = &reinterpret_cast<CBaseGeometryProxy* const*>(this)[53];
}
else if (SystemHelper::g_buildNumber < 26020)
{
geometry = &reinterpret_cast<CBaseGeometryProxy* const*>(this)[48];
}
else
{
geometry = &reinterpret_cast<CBaseGeometryProxy* const*>(this)[42];
}
return *geometry;
}
};
struct CTopLevelWindow;
struct CTopLevelWindow3D;
struct CWindowData : CBaseObject
{
HWND GetHwnd() const
{
return reinterpret_cast<const HWND*>(this)[5];
}
POINT GetOffsetToOwner()
{
return UDWM_CALL_ORG(CWindowData::GetOffsetToOwner, );
}
CTopLevelWindow* GetWindow() const
{
CTopLevelWindow* window{nullptr};
if (SystemHelper::g_buildNumber < 22000)
{
window = reinterpret_cast<CTopLevelWindow* const*>(this)[48];
}
else
{
window = reinterpret_cast<CTopLevelWindow* const*>(this)[55];
}
return window;
}
CTopLevelWindow3D* GetWindow3D() const
{
CTopLevelWindow3D* window{ nullptr };
if (SystemHelper::g_buildNumber < 22000)
{
window = reinterpret_cast<CTopLevelWindow3D* const*>(this)[59];
}
else
{
window = reinterpret_cast<CTopLevelWindow3D* const*>(this)[56];
}
return window;
}
ACCENT_POLICY* GetAccentPolicy() const
{
ACCENT_POLICY* accentPolicy{nullptr};
if (SystemHelper::g_buildNumber >= 22000)
{
accentPolicy = (ACCENT_POLICY*)((ULONGLONG)this + 168);
}
else
{
accentPolicy = (ACCENT_POLICY*)((ULONGLONG)this + 152);
}
return accentPolicy;
}
DWORD GetSystemBackdropType() const
{
if (SystemHelper::g_buildNumber >= 22000)
{
return reinterpret_cast<DWORD const*>(this)[204];
}
return 0;
}
bool IsUsingDarkMode() const
{
bool darkMode{ false };
if (SystemHelper::g_buildNumber < 19041)
{
// TO-DO
}
else if (SystemHelper::g_buildNumber < 22000)
{
darkMode = (reinterpret_cast<BYTE const*>(this)[613] & 8) != 0;
}
else if (SystemHelper::g_buildNumber < 22621)
{
darkMode = (reinterpret_cast<BYTE const*>(this)[669] & 4) != 0;
}
else
{
darkMode = (reinterpret_cast<BYTE const*>(this)[677] & 4) != 0; // ok with build 26020
}
return darkMode;
}
DWORD GetNonClientAttribute() const
{
DWORD attribute{ 0 };
if (SystemHelper::g_buildNumber < 19041)
{
// TO-DO
}
else if (SystemHelper::g_buildNumber < 22000)
{
attribute = *reinterpret_cast<const DWORD*>(reinterpret_cast<BYTE const*>(this) + 608);
}
else if (SystemHelper::g_buildNumber < 22621)
{
attribute = *reinterpret_cast<const DWORD*>(reinterpret_cast<BYTE const*>(this) + 664);
}
else
{
attribute = *reinterpret_cast<const DWORD*>(reinterpret_cast<BYTE const*>(this) + 672); // ok with build 26020
}
return attribute;
}
bool STDMETHODCALLTYPE IsImmersiveWindow() const
{
return UDWM_CALL_ORG(CWindowData::IsImmersiveWindow, );
}
};
struct CWindowList : CBaseObject
{
HRESULT STDMETHODCALLTYPE GetExtendedFrameBounds(
HWND hwnd,
RECT* rect
)
{
return UDWM_CALL_ORG(CWindowList::GetExtendedFrameBounds, hwnd, rect);
}
HRESULT STDMETHODCALLTYPE GetSyncedWindowDataByHwnd(HWND hwnd, CWindowData** windowData)
{
return UDWM_CALL_ORG(CWindowList::GetSyncedWindowDataByHwnd, hwnd, windowData);
}
void STDMETHODCALLTYPE RegisterAccentState(CWindowData* data, UINT accentState)
{
return UDWM_CALL_ORG(CWindowList::RegisterAccentState, data, accentState);
}
};
struct CTopLevelWindow : CVisual
{
void GetBorderMargins(MARGINS* margins) const
{
if (SystemHelper::g_buildNumber < 19041)
{
// TO-DO
}
else if (SystemHelper::g_buildNumber < 26020)
{
UDWM_CALL_ORG_BY_TYPE(RECT * (STDMETHODCALLTYPE uDwmPrivates::CTopLevelWindow::*)(MARGINS*) const, this, "CTopLevelWindow::GetBorderMargins", margins);
}
else
{
UDWM_CALL_ORG_BY_TYPE(void (STDMETHODCALLTYPE uDwmPrivates::CTopLevelWindow::*)(MARGINS*) const, this, "CTopLevelWindow::GetFrameMargins", margins);
}
}
HRESULT STDMETHODCALLTYPE SetWindowOffscreen(bool offscreen)
{
return UDWM_CALL_ORG(CTopLevelWindow::SetWindowOffscreen, offscreen);
}
bool STDMETHODCALLTYPE TreatAsActiveWindow()
{
return UDWM_CALL_ORG(CTopLevelWindow::TreatAsActiveWindow, );
}
HRESULT STDMETHODCALLTYPE ValidateVisual()
{
return UDWM_CALL_ORG(CTopLevelWindow::ValidateVisual, );
}
RECT* STDMETHODCALLTYPE GetActualWindowRect(
RECT* rect,
char eraseOffset,
char includeNonClient,
bool excludeBorderMargins
)
{
return UDWM_CALL_ORG(CTopLevelWindow::GetActualWindowRect, rect, eraseOffset, includeNonClient, excludeBorderMargins);
}
CWindowData* GetWindowData() const
{
CWindowData* windowData{ nullptr };
if (SystemHelper::g_buildNumber < 19041)
{
// TO-DO
}
else if (SystemHelper::g_buildNumber <= 18363)
{
windowData = reinterpret_cast<CWindowData* const*>(this)[90];
}
else if (SystemHelper::g_buildNumber < 22000)
{
windowData = reinterpret_cast<CWindowData* const*>(this)[91];
}
else if (SystemHelper::g_buildNumber < 26020)
{
windowData = reinterpret_cast<CWindowData* const*>(this)[94];
}
else
{
windowData = reinterpret_cast<CWindowData* const*>(this)[89];
}
return windowData;
}
CVisual* GetVisual() const
{
CVisual* visual{ nullptr };
if (SystemHelper::g_buildNumber < 19041)
{
// TO-DO
}
else if (SystemHelper::g_buildNumber < 22000)
{
visual = reinterpret_cast<CVisual* const*>(this)[33];
}
else if (SystemHelper::g_buildNumber < 22621)
{
visual = reinterpret_cast<CVisual* const*>(this)[34];
}
else if (SystemHelper::g_buildNumber < 26020)
{
visual = reinterpret_cast<CVisual* const*>(this)[36];
}
else
{
visual = reinterpret_cast<CVisual* const*>(this)[31];
}
return visual;
}
CAccent* GetAccent() const
{
CAccent* accent{ nullptr };
if (SystemHelper::g_buildNumber < 22000)
{
accent = reinterpret_cast<CAccent* const*>(this)[34];
}
else if (SystemHelper::g_buildNumber < 22621)
{
accent = reinterpret_cast<CAccent* const*>(this)[35];
}
else if (SystemHelper::g_buildNumber < 26020)
{
accent = reinterpret_cast<CAccent* const*>(this)[37];
}
else
{
accent = reinterpret_cast<CAccent* const*>(this)[34];
}
return accent;
}
CVisual* GetLegacyVisual() const
{
CVisual* visual{ nullptr };
if (SystemHelper::g_buildNumber < 22000)
{
visual = reinterpret_cast<CVisual* const*>(this)[36];
}
else if (SystemHelper::g_buildNumber < 22621)
{
visual = reinterpret_cast<CVisual* const*>(this)[37];
}
else if (SystemHelper::g_buildNumber < 26020)
{
visual = reinterpret_cast<CVisual* const*>(this)[39];
}
else
{
visual = reinterpret_cast<CVisual* const*>(this)[40];
}
return visual;
}
CVisual* GetClientBlurVisual() const
{
CVisual* visual{ nullptr };
if (SystemHelper::g_buildNumber < 22000)
{
visual = reinterpret_cast<CVisual* const*>(this)[37];
}
else if (SystemHelper::g_buildNumber < 22621)
{
visual = reinterpret_cast<CVisual* const*>(this)[39];
}
else if (SystemHelper::g_buildNumber < 26020)
{
visual = reinterpret_cast<CVisual* const*>(this)[37];
}
else
{
visual = reinterpret_cast<CVisual* const*>(this)[40];
}
return visual;
}
CVisual* GetSystemBackdropVisual() const
{
CVisual* visual{ nullptr };
if (SystemHelper::g_buildNumber < 22000)
{
}
else if (SystemHelper::g_buildNumber < 22621)
{
visual = reinterpret_cast<CVisual* const*>(this)[38];
}
else if (SystemHelper::g_buildNumber < 26020)
{
visual = reinterpret_cast<CVisual* const*>(this)[40];
}
else
{
visual = reinterpret_cast<CVisual* const*>(this)[35];
}
return visual;
}
CVisual* GetAccentColorVisual() const
{
CVisual* visual{ nullptr };
if (SystemHelper::g_buildNumber < 22000)
{
}
else if (SystemHelper::g_buildNumber < 22621)
{
}
else if (SystemHelper::g_buildNumber < 26020)
{
visual = reinterpret_cast<CVisual* const*>(this)[41];
}
else
{
visual = reinterpret_cast<CVisual* const*>(this)[36];
}
return visual;
}
auto GetNCBackgroundVisuals() const
{
std::vector<winrt::com_ptr<CVisual>> visuals{};
if (GetLegacyVisual())
{
visuals.emplace_back(nullptr).copy_from(GetLegacyVisual());
}
if (GetAccent())
{
visuals.emplace_back(nullptr).copy_from(GetAccent());
}
if (GetClientBlurVisual())
{
visuals.emplace_back(nullptr).copy_from(GetClientBlurVisual());
}
if (GetSystemBackdropVisual())
{
visuals.emplace_back(nullptr).copy_from(GetSystemBackdropVisual());
}
if (GetAccentColorVisual())
{
visuals.emplace_back(nullptr).copy_from(GetAccentColorVisual());
}
return visuals;
}
bool IsNCBackgroundVisualsCloneAllAllowed()
{
for (const auto& visual : GetNCBackgroundVisuals())
{
if (!visual->IsCloneAllowed())
{
return false;
}
}
return true;
}
CSolidColorLegacyMilBrushProxy* const* GetBorderMilBrush() const
{
CSolidColorLegacyMilBrushProxy* const* brush{ nullptr };
if (SystemHelper::g_buildNumber < 19041)
{
// TO-DO
}
else if (SystemHelper::g_buildNumber < 22000)
{
brush = &reinterpret_cast<CSolidColorLegacyMilBrushProxy* const*>(this)[94];
}
else if (SystemHelper::g_buildNumber < 22621)
{
brush = &reinterpret_cast<CSolidColorLegacyMilBrushProxy* const*>(this)[98];
}
else if (SystemHelper::g_buildNumber < 26020)
{
auto legacyBackgroundVisual{ reinterpret_cast<CVisual* const*>(this)[39] };
if (legacyBackgroundVisual)
{
brush = &reinterpret_cast<CSolidColorLegacyMilBrushProxy* const*>(legacyBackgroundVisual)[38];
}
}
else
{
auto legacyBackgroundVisual{ reinterpret_cast<CVisual* const*>(this)[34] };
if (legacyBackgroundVisual)
{
brush = &reinterpret_cast<CSolidColorLegacyMilBrushProxy* const*>(legacyBackgroundVisual)[32];
}
}
return brush;
}
CBaseGeometryProxy* const& GetClipGeometry() const
{
CBaseGeometryProxy* const* geometry{ nullptr };
if (SystemHelper::g_buildNumber < 22000)
{
geometry = &reinterpret_cast<CBaseGeometryProxy* const*>(this)[46];
}
else
{
geometry = &reinterpret_cast<CBaseGeometryProxy* const*>(this)[53];
}
return *geometry;
}
CRgnGeometryProxy* const* GetBorderGeometry() const
{
CRgnGeometryProxy* const* geometry{ nullptr };
if (SystemHelper::g_buildNumber < 19041)
{
// TO-DO
}
else if (SystemHelper::g_buildNumber < 22000)
{
geometry = &reinterpret_cast<CRgnGeometryProxy* const*>(this)[69];
}
else if (SystemHelper::g_buildNumber < 22621)
{
geometry = &reinterpret_cast<CRgnGeometryProxy* const*>(this)[71];
}
else if (SystemHelper::g_buildNumber < 26020)
{
auto legacyBackgroundVisual{ reinterpret_cast<CVisual* const*>(this)[39] };
if (legacyBackgroundVisual)
{
geometry = &reinterpret_cast<CRgnGeometryProxy* const*>(legacyBackgroundVisual)[40];
}
}
else
{
auto legacyBackgroundVisual{ reinterpret_cast<CVisual* const*>(this)[34] };
if (legacyBackgroundVisual)
{
geometry = &reinterpret_cast<CRgnGeometryProxy* const*>(legacyBackgroundVisual)[34];
}
}
return geometry;
}
CRgnGeometryProxy* const* GetTitlebarGeometry() const
{
CRgnGeometryProxy* const* geometry{ nullptr };
if (SystemHelper::g_buildNumber < 19041)
{
// TO-DO
}
else if (SystemHelper::g_buildNumber < 22000)
{
geometry = &reinterpret_cast<CRgnGeometryProxy* const*>(this)[70];
}
else if (SystemHelper::g_buildNumber < 22621)
{
geometry = &reinterpret_cast<CRgnGeometryProxy* const*>(this)[72];
}
else if (SystemHelper::g_buildNumber < 26020)
{
auto legacyBackgroundVisual{ reinterpret_cast<CVisual* const*>(this)[39] };
if (legacyBackgroundVisual)
{
geometry = &reinterpret_cast<CRgnGeometryProxy* const*>(legacyBackgroundVisual)[39];
}
}
else
{
auto legacyBackgroundVisual{ reinterpret_cast<CVisual* const*>(this)[33] };
if (legacyBackgroundVisual)
{
geometry = &reinterpret_cast<CRgnGeometryProxy* const*>(legacyBackgroundVisual)[33];
}
}
return geometry;
}
bool HasNonClientBackground() const
{
auto windowData{ GetWindowData() };
if ((windowData->GetNonClientAttribute() & 8) == 0)
{
return false;
}
if (windowData->IsImmersiveWindow())
{
return false;
}
bool nonClientEmpty{false};
if (SystemHelper::g_buildNumber < 19041)
{
// TO-DO
}
else if (SystemHelper::g_buildNumber < 22000)
{
nonClientEmpty = !reinterpret_cast<DWORD const*>(this)[153] &&
!reinterpret_cast<DWORD const*>(this)[154] &&
!reinterpret_cast<DWORD const*>(this)[155] &&
!reinterpret_cast<DWORD const*>(this)[156];
}
else if (SystemHelper::g_buildNumber < 22621)
{
nonClientEmpty = !reinterpret_cast<DWORD const*>(this)[157] &&
!reinterpret_cast<DWORD const*>(this)[158] &&
!reinterpret_cast<DWORD const*>(this)[159] &&
!reinterpret_cast<DWORD const*>(this)[160];
}
else if (SystemHelper::g_buildNumber < 26020)
{
nonClientEmpty = !reinterpret_cast<DWORD const*>(this)[161] &&
!reinterpret_cast<DWORD const*>(this)[162] &&
!reinterpret_cast<DWORD const*>(this)[163] &&
!reinterpret_cast<DWORD const*>(this)[164];
}
else
{
nonClientEmpty = !reinterpret_cast<DWORD const*>(this)[151] &&
!reinterpret_cast<DWORD const*>(this)[152] &&
!reinterpret_cast<DWORD const*>(this)[153] &&
!reinterpret_cast<DWORD const*>(this)[154];
}
if (nonClientEmpty)
{
return false;
}
return true;
}
bool IsSystemBackdropApplied()
{
bool systemBackdropApplied{false};
if (SystemHelper::g_buildNumber < 19041)
{
// TO-DO
}
else if (SystemHelper::g_buildNumber < 22000)
{
systemBackdropApplied = false;
}
else if (SystemHelper::g_buildNumber < 22621)
{
systemBackdropApplied = *reinterpret_cast<DWORD*>(reinterpret_cast<ULONG_PTR>(GetWindowData()) + 204);
}
else if (SystemHelper::g_buildNumber < 26020)
{
systemBackdropApplied = (reinterpret_cast<DWORD const*>(this)[210] <= 3);
}
else