WIXBUG4931 Fix drawing of image static controls
Andrij Abyzov committed
Feb 8, 2021 at 20:00 UTC
931d4e4d641155ab0c90fe7717abb12db4736317
1 file changed
+51
-2
src/dutil/thmutil.cpp
+51
-2
@@ -40,6 +40,7 @@ const DWORD GROW_FONT_INSTANCES = 3;
40
const DWORD GROW_WINDOW_TEXT = 250;
41
const LPCWSTR THEME_WC_HYPERLINK = L"ThemeHyperLink";
42
const LPCWSTR THEME_WC_PANEL = L"ThemePanel";
43
+const LPCWSTR THEME_WC_STATICOWNERDRAW = L"ThemeStaticOwnerDraw";
44
45
static Gdiplus::GdiplusStartupInput vgsi;
46
static Gdiplus::GdiplusStartupOutput vgso = { };
@@ -47,6 +48,8 @@ static ULONG_PTR vgdiToken = 0;
48
static ULONG_PTR vgdiHookToken = 0;
49
static HMODULE vhHyperlinkRegisteredModule = NULL;
50
static HMODULE vhPanelRegisteredModule = NULL;
51
+static HMODULE vhStaticOwnerDrawRegisteredModule = NULL;
52
+static WNDPROC vpfnStaticOwnerDrawBaseWndProc = NULL;
53
static HMODULE vhModuleMsftEdit = NULL;
54
static HMODULE vhModuleRichEd = NULL;
55
static HCURSOR vhCursorHand = NULL;
@@ -348,6 +351,12 @@ static LRESULT CALLBACK PanelWndProc(
351
__in WPARAM wParam,
352
__in LPARAM lParam
353
);
354
+static LRESULT CALLBACK StaticOwnerDrawWndProc(
355
+ __in HWND hWnd,
356
+ __in UINT uMsg,
357
+ __in WPARAM wParam,
358
+ __in LPARAM lParam
359
+ );
360
static HRESULT LocalizeControls(
361
__in DWORD cControls,
362
__in THEME_CONTROL* rgControls,
@@ -479,6 +488,13 @@ DAPI_(void) ThemeUninitialize()
488
vhPanelRegisteredModule = NULL;
489
}
490
491
+ if (vhStaticOwnerDrawRegisteredModule)
492
+ {
493
+ ::UnregisterClassW(THEME_WC_STATICOWNERDRAW, vhStaticOwnerDrawRegisteredModule);
494
+ vhStaticOwnerDrawRegisteredModule = NULL;
495
+ vpfnStaticOwnerDrawBaseWndProc = NULL;
496
+ }
497
+
498
if (vgdiToken)
499
{
500
GdipUninitialize(vgdiToken);
@@ -1598,6 +1614,8 @@ static HRESULT RegisterWindowClasses(
1614
HRESULT hr = S_OK;
1615
WNDCLASSW wcHyperlink = { };
1616
WNDCLASSW wcPanel = { };
1617
+ WNDCLASSW wcStaticOwnerDraw = { };
1618
+ WNDPROC pfnStaticOwnerDrawBaseWndProc = NULL;
1619
1620
vhCursorHand = ::LoadCursorA(NULL, IDC_HAND);
1621
@@ -1630,6 +1648,22 @@ static HRESULT RegisterWindowClasses(
1648
}
1649
vhPanelRegisteredModule = hModule;
1650
1651
+ if (!::GetClassInfoW(NULL, WC_STATICW, &wcStaticOwnerDraw))
1652
+ {
1653
+ ThmExitWithLastError(hr, "Failed to get static window class.");
1654
+ }
1655
+
1656
+ pfnStaticOwnerDrawBaseWndProc = wcStaticOwnerDraw.lpfnWndProc;
1657
+ wcStaticOwnerDraw.lpfnWndProc = StaticOwnerDrawWndProc;
1658
+ wcStaticOwnerDraw.hInstance = hModule;
1659
+ wcStaticOwnerDraw.lpszClassName = THEME_WC_STATICOWNERDRAW;
1660
+ if (!::RegisterClassW(&wcStaticOwnerDraw))
1661
+ {
1662
+ ThmExitWithLastError(hr, "Failed to register OwnerDraw window class.");
1663
+ }
1664
+ vhStaticOwnerDrawRegisteredModule = hModule;
1665
+ vpfnStaticOwnerDrawBaseWndProc = pfnStaticOwnerDrawBaseWndProc;
1666
+
1667
1668
LExit:
1669
return hr;
@@ -4919,6 +4953,21 @@ static LRESULT CALLBACK PanelWndProc(
4953
return ControlGroupDefWindowProc(pTheme, hWnd, uMsg, wParam, lParam);
4954
}
4955
4956
+static LRESULT CALLBACK StaticOwnerDrawWndProc(
4957
+ __in HWND hWnd,
4958
+ __in UINT uMsg,
4959
+ __in WPARAM wParam,
4960
+ __in LPARAM lParam
4961
+ )
4962
+{
4963
+ switch (uMsg)
4964
+ {
4965
+ case WM_UPDATEUISTATE:
4966
+ return ::DefWindowProc(hWnd, uMsg, wParam, lParam);
4967
+ default:
4968
+ return (*vpfnStaticOwnerDrawBaseWndProc)(hWnd, uMsg, wParam, lParam);
4969
+ }
4970
+}
4971
4972
static HRESULT LoadControls(
4973
__in THEME* pTheme,
@@ -5011,7 +5060,7 @@ static HRESULT LoadControls(
5060
case THEME_CONTROL_TYPE_IMAGE: // images are basically just owner drawn static controls (so we can draw .jpgs and .pngs instead of just bitmaps).
5061
if (pControl->hImage || (pTheme->hImage && 0 <= pControl->nSourceX && 0 <= pControl->nSourceY))
5062
{
5014
- wzWindowClass = WC_STATICW;
5063
+ wzWindowClass = THEME_WC_STATICOWNERDRAW;
5064
dwWindowBits |= SS_OWNERDRAW;
5065
pControl->dwInternalStyle |= INTERNAL_CONTROL_STYLE_OWNER_DRAW;
5066
}
@@ -5038,7 +5087,7 @@ static HRESULT LoadControls(
5087
case THEME_CONTROL_TYPE_PROGRESSBAR:
5088
if (pControl->hImage || (pTheme->hImage && 0 <= pControl->nSourceX && 0 <= pControl->nSourceY))
5089
{
5041
- wzWindowClass = WC_STATICW; // no such thing as an owner drawn progress bar so we'll make our own out of a static control.
5090
+ wzWindowClass = THEME_WC_STATICOWNERDRAW; // no such thing as an owner drawn progress bar so we'll make our own out of a static control.
5091
dwWindowBits |= SS_OWNERDRAW;
5092
pControl->dwInternalStyle |= INTERNAL_CONTROL_STYLE_OWNER_DRAW;
5093
}