From dba0b8c659bfcd66eef1be89c994ad0e6f4646f7 Mon Sep 17 00:00:00 2001 From: Mohmed abdel-fattah Date: Wed, 26 Jun 2024 12:50:04 +0300 Subject: [PATCH] fix MinGW build issues --- .mingw/Makefile.am | 2 +- .mingw/Makefile.in | 2 +- .mingw/dwmapi.def | 1 + .mingw/uxtheme.def | 79 ++++++++++++++++++++++++++++ .vs/rufus.vcxproj | 32 ++++++------ src/Makefile.in | 2 +- src/registry.h | 7 +++ src/rufus.c | 58 +++++++++----------- src/stdlg.c | 128 ++++++++++++++++++++++++++++++++++++++------- src/ui.h | 2 +- src/ui_data.h | 4 ++ 11 files changed, 244 insertions(+), 73 deletions(-) create mode 100644 .mingw/uxtheme.def diff --git a/.mingw/Makefile.am b/.mingw/Makefile.am index cb131d61..2326c9ca 100644 --- a/.mingw/Makefile.am +++ b/.mingw/Makefile.am @@ -19,7 +19,7 @@ TARGET := $(word 1,$(subst -, ,$(TUPLE))) DEF_SUFFIX := $(if $(TARGET:x86_64=),.def,.def64) .PHONY: all -all: dwmapi-delaylib.lib version-delaylib.lib wintrust-delaylib.lib +all: dwmapi-delaylib.lib version-delaylib.lib wintrust-delaylib.lib uxtheme-delaylib.lib %.def64: %.def $(AM_V_SED) "s/@.*//" $< >$@ diff --git a/.mingw/Makefile.in b/.mingw/Makefile.in index 0dda8fb1..877c4d83 100644 --- a/.mingw/Makefile.in +++ b/.mingw/Makefile.in @@ -367,7 +367,7 @@ uninstall-am: .PHONY: all -all: dwmapi-delaylib.lib version-delaylib.lib wintrust-delaylib.lib +all: dwmapi-delaylib.lib version-delaylib.lib wintrust-delaylib.lib uxtheme-delaylib.lib %.def64: %.def $(AM_V_SED) "s/@.*//" $< >$@ diff --git a/.mingw/dwmapi.def b/.mingw/dwmapi.def index 240e17c7..393c04e0 100644 --- a/.mingw/dwmapi.def +++ b/.mingw/dwmapi.def @@ -1,2 +1,3 @@ EXPORTS DwmGetWindowAttribute@16 + DwmSetWindowAttribute@16 diff --git a/.mingw/uxtheme.def b/.mingw/uxtheme.def new file mode 100644 index 00000000..3f772ac0 --- /dev/null +++ b/.mingw/uxtheme.def @@ -0,0 +1,79 @@ +; +; Definition file of UxTheme.dll +; Automatic generated by gendef +; written by Kai Tietz 2008 +; +LIBRARY "UxTheme.dll" +EXPORTS +BeginPanningFeedback@4 +EndPanningFeedback@8 +UpdatePanningFeedback@16 +BeginBufferedAnimation@32 +BeginBufferedPaint@20 +BufferedPaintClear@8 +BufferedPaintInit@0 +BufferedPaintRenderAnimation@8 +BufferedPaintSetAlpha@12 +DrawThemeBackgroundEx@24 +BufferedPaintStopAllAnimations@4 +BufferedPaintUnInit@0 +CloseThemeData@4 +DrawThemeBackground@24 +DrawThemeEdge@32 +DrawThemeIcon@28 +DrawThemeParentBackground@12 +DrawThemeParentBackgroundEx@16 +DrawThemeText@36 +OpenThemeDataEx@12 +DrawThemeTextEx@36 +EnableThemeDialogTexture@8 +EnableTheming@4 +EndBufferedAnimation@8 +EndBufferedPaint@8 +GetBufferedPaintBits@12 +GetBufferedPaintDC@4 +GetBufferedPaintTargetDC@4 +GetBufferedPaintTargetRect@8 +GetCurrentThemeName@24 +GetThemeAppProperties@0 +GetThemeBackgroundContentRect@24 +GetThemeBackgroundExtent@24 +GetThemeBackgroundRegion@24 +GetThemeBitmap@24 +GetThemeBool@20 +GetThemeColor@20 +GetThemeDocumentationProperty@16 +GetThemeEnumValue@20 +GetThemeFilename@24 +GetThemeFont@24 +GetThemeInt@20 +GetThemeIntList@20 +GetThemeMargins@28 +GetThemeMetric@24 +GetThemePartSize@28 +GetThemePosition@20 +GetThemePropertyOrigin@20 +GetThemeRect@20 +GetThemeStream@28 +GetThemeString@24 +GetThemeSysBool@8 +GetThemeSysColor@8 +GetThemeSysColorBrush@8 +GetThemeSysFont@12 +GetThemeSysInt@12 +GetThemeSysSize@8 +GetThemeSysString@16 +GetThemeTextExtent@36 +GetThemeTextMetrics@20 +GetThemeTransitionDuration@24 +GetWindowTheme@4 +HitTestThemeBackground@40 +IsAppThemed@0 +IsCompositionActive@0 +IsThemeActive@0 +IsThemeBackgroundPartiallyTransparent@12 +IsThemeDialogTextureEnabled@4 +IsThemePartDefined@12 +OpenThemeData@8 +SetThemeAppProperties@4 +SetWindowTheme@12 \ No newline at end of file diff --git a/.vs/rufus.vcxproj b/.vs/rufus.vcxproj index 7266623b..414c633f 100644 --- a/.vs/rufus.vcxproj +++ b/.vs/rufus.vcxproj @@ -133,12 +133,12 @@ /utf-8 $(ExternalCompilerOptions) %(AdditionalOptions) - advapi32.lib;comctl32.lib;crypt32.lib;gdi32.lib;ole32.lib;dwmapi.lib;setupapi.lib;shell32.lib;shlwapi.lib;version.lib;wintrust.lib;%(AdditionalDependencies) + advapi32.lib;comctl32.lib;crypt32.lib;gdi32.lib;ole32.lib;dwmapi.lib;setupapi.lib;uxtheme.lib;shell32.lib;shlwapi.lib;version.lib;wintrust.lib;%(AdditionalDependencies) RequireAdministrator true Windows MachineX86 - advapi32.dll;comctl32.dll;crypt32.dll;gdi32.dll;ole32.dll;dwmapi.dll;setupapi.dll;shell32.dll;shlwapi.dll;version.dll;wintrust.dll;%(DelayLoadDLLs) + advapi32.dll;comctl32.dll;crypt32.dll;gdi32.dll;ole32.dll;dwmapi.dll;setupapi.dll;uxtheme.dll;shell32.dll;shlwapi.dll;version.dll;wintrust.dll;%(DelayLoadDLLs) _UNICODE;UNICODE;%(PreprocessorDefinitions) @@ -162,12 +162,12 @@ /utf-8 $(ExternalCompilerOptions) %(AdditionalOptions) - advapi32.lib;comctl32.lib;crypt32.lib;gdi32.lib;ole32.lib;dwmapi.lib;setupapi.lib;shell32.lib;shlwapi.lib;version.lib;wintrust.lib;ole32.lib;advapi32.lib;gdi32.lib;shell32.lib;comdlg32.lib;%(AdditionalDependencies) + advapi32.lib;comctl32.lib;crypt32.lib;gdi32.lib;ole32.lib;dwmapi.lib;setupapi.lib;uxtheme.lib;shell32.lib;shlwapi.lib;version.lib;wintrust.lib;ole32.lib;advapi32.lib;gdi32.lib;shell32.lib;comdlg32.lib;%(AdditionalDependencies) RequireAdministrator true Windows C:\Program Files (x86)\Windows Kits\10\Lib\10.0.15063.0\um\arm - advapi32.dll;comctl32.dll;crypt32.dll;gdi32.dll;ole32.dll;dwmapi.dll;setupapi.dll;shell32.dll;shlwapi.dll;version.dll;wintrust.dll;ole32.dll;advapi32.dll;gdi32.dll;shell32.dll;comdlg32.dll;%(DelayLoadDLLs) + advapi32.dll;comctl32.dll;crypt32.dll;gdi32.dll;ole32.dll;dwmapi.dll;setupapi.dll;uxtheme.dll;shell32.dll;shlwapi.dll;version.dll;wintrust.dll;ole32.dll;advapi32.dll;gdi32.dll;shell32.dll;comdlg32.dll;%(DelayLoadDLLs) _UNICODE;UNICODE;%(PreprocessorDefinitions) @@ -193,12 +193,12 @@ /utf-8 $(ExternalCompilerOptions) %(AdditionalOptions) - advapi32.lib;comctl32.lib;crypt32.lib;gdi32.lib;ole32.lib;dwmapi.lib;setupapi.lib;shell32.lib;shlwapi.lib;version.lib;wintrust.lib;ole32.lib;advapi32.lib;gdi32.lib;shell32.lib;comdlg32.lib;%(AdditionalDependencies) + advapi32.lib;comctl32.lib;crypt32.lib;gdi32.lib;ole32.lib;dwmapi.lib;setupapi.lib;uxtheme.lib;shell32.lib;shlwapi.lib;version.lib;wintrust.lib;ole32.lib;advapi32.lib;gdi32.lib;shell32.lib;comdlg32.lib;%(AdditionalDependencies) RequireAdministrator true Windows C:\Program Files (x86)\Windows Kits\10\Lib\10.0.16299.0\um\arm64 - advapi32.dll;comctl32.dll;crypt32.dll;gdi32.dll;ole32.dll;dwmapi.dll;setupapi.dll;shell32.dll;shlwapi.dll;version.dll;wintrust.dll;ole32.dll;advapi32.dll;gdi32.dll;shell32.dll;comdlg32.dll;%(DelayLoadDLLs) + advapi32.dll;comctl32.dll;crypt32.dll;gdi32.dll;ole32.dll;dwmapi.dll;setupapi.dll;uxtheme.dll;shell32.dll;shlwapi.dll;version.dll;wintrust.dll;ole32.dll;advapi32.dll;gdi32.dll;shell32.dll;comdlg32.dll;%(DelayLoadDLLs) _UNICODE;UNICODE;%(PreprocessorDefinitions) @@ -229,12 +229,12 @@ /utf-8 $(ExternalCompilerOptions) %(AdditionalOptions) - advapi32.lib;comctl32.lib;crypt32.lib;gdi32.lib;ole32.lib;dwmapi.lib;setupapi.lib;shell32.lib;shlwapi.lib;version.lib;wintrust.lib;%(AdditionalDependencies) + advapi32.lib;comctl32.lib;crypt32.lib;gdi32.lib;ole32.lib;dwmapi.lib;setupapi.lib;uxtheme.lib;shell32.lib;shlwapi.lib;version.lib;wintrust.lib;%(AdditionalDependencies) RequireAdministrator true Windows MachineX64 - advapi32.dll;comctl32.dll;crypt32.dll;gdi32.dll;ole32.dll;dwmapi.dll;setupapi.dll;shell32.dll;shlwapi.dll;version.dll;wintrust.dll;%(DelayLoadDLLs) + advapi32.dll;comctl32.dll;crypt32.dll;gdi32.dll;ole32.dll;dwmapi.dll;setupapi.dll;uxtheme.dll;shell32.dll;shlwapi.dll;version.dll;wintrust.dll;%(DelayLoadDLLs) _UNICODE;UNICODE;%(PreprocessorDefinitions) @@ -260,13 +260,13 @@ true - advapi32.lib;comctl32.lib;crypt32.lib;gdi32.lib;ole32.lib;dwmapi.lib;setupapi.lib;shell32.lib;shlwapi.lib;version.lib;wintrust.lib;%(AdditionalDependencies) + advapi32.lib;comctl32.lib;crypt32.lib;gdi32.lib;ole32.lib;dwmapi.lib;setupapi.lib;uxtheme.lib;shell32.lib;shlwapi.lib;version.lib;wintrust.lib;%(AdditionalDependencies) RequireAdministrator false Windows MachineX86 /BREPRO %(AdditionalOptions) - advapi32.dll;comctl32.dll;crypt32.dll;gdi32.dll;ole32.dll;dwmapi.dll;setupapi.dll;shell32.dll;shlwapi.dll;version.dll;wintrust.dll;%(DelayLoadDLLs) + advapi32.dll;comctl32.dll;crypt32.dll;gdi32.dll;ole32.dll;dwmapi.dll;setupapi.dll;uxtheme.dll;shell32.dll;shlwapi.dll;version.dll;wintrust.dll;%(DelayLoadDLLs) _UNICODE;UNICODE;%(PreprocessorDefinitions) @@ -292,13 +292,13 @@ true - advapi32.lib;comctl32.lib;crypt32.lib;gdi32.lib;ole32.lib;dwmapi.lib;setupapi.lib;shell32.lib;shlwapi.lib;version.lib;wintrust.lib;ole32.lib;advapi32.lib;gdi32.lib;shell32.lib;comdlg32.lib;%(AdditionalDependencies) + advapi32.lib;comctl32.lib;crypt32.lib;gdi32.lib;ole32.lib;dwmapi.lib;setupapi.lib;uxtheme.lib;shell32.lib;shlwapi.lib;version.lib;wintrust.lib;ole32.lib;advapi32.lib;gdi32.lib;shell32.lib;comdlg32.lib;%(AdditionalDependencies) RequireAdministrator false Windows C:\Program Files (x86)\Windows Kits\10\Lib\10.0.15063.0\um\arm /BREPRO %(AdditionalOptions) - advapi32.dll;comctl32.dll;crypt32.dll;gdi32.dll;ole32.dll;dwmapi.dll;setupapi.dll;shell32.dll;shlwapi.dll;version.dll;wintrust.dll;ole32.dll;advapi32.dll;gdi32.dll;shell32.dll;comdlg32.dll;%(DelayLoadDLLs) + advapi32.dll;comctl32.dll;crypt32.dll;gdi32.dll;ole32.dll;dwmapi.dll;setupapi.dll;uxtheme.dll;shell32.dll;shlwapi.dll;version.dll;wintrust.dll;ole32.dll;advapi32.dll;gdi32.dll;shell32.dll;comdlg32.dll;%(DelayLoadDLLs) _UNICODE;UNICODE;%(PreprocessorDefinitions) @@ -326,13 +326,13 @@ true - advapi32.lib;comctl32.lib;crypt32.lib;gdi32.lib;ole32.lib;dwmapi.lib;setupapi.lib;shell32.lib;shlwapi.lib;version.lib;wintrust.lib;ole32.lib;advapi32.lib;gdi32.lib;shell32.lib;comdlg32.lib;%(AdditionalDependencies) + advapi32.lib;comctl32.lib;crypt32.lib;gdi32.lib;ole32.lib;dwmapi.lib;setupapi.lib;uxtheme.lib;shell32.lib;shlwapi.lib;version.lib;wintrust.lib;ole32.lib;advapi32.lib;gdi32.lib;shell32.lib;comdlg32.lib;%(AdditionalDependencies) RequireAdministrator false Windows C:\Program Files (x86)\Windows Kits\10\Lib\10.0.16299.0\um\arm64 /BREPRO %(AdditionalOptions) - advapi32.dll;comctl32.dll;crypt32.dll;gdi32.dll;ole32.dll;dwmapi.dll;setupapi.dll;shell32.dll;shlwapi.dll;version.dll;wintrust.dll;ole32.dll;advapi32.dll;gdi32.dll;shell32.dll;comdlg32.dll;%(DelayLoadDLLs) + advapi32.dll;comctl32.dll;crypt32.dll;gdi32.dll;ole32.dll;dwmapi.dll;setupapi.dll;uxtheme.dll;shell32.dll;shlwapi.dll;version.dll;wintrust.dll;ole32.dll;advapi32.dll;gdi32.dll;shell32.dll;comdlg32.dll;%(DelayLoadDLLs) _UNICODE;UNICODE;%(PreprocessorDefinitions) @@ -363,13 +363,13 @@ true - advapi32.lib;comctl32.lib;crypt32.lib;gdi32.lib;ole32.lib;dwmapi.lib;setupapi.lib;shell32.lib;shlwapi.lib;version.lib;wintrust.lib;%(AdditionalDependencies) + advapi32.lib;comctl32.lib;crypt32.lib;gdi32.lib;ole32.lib;dwmapi.lib;setupapi.lib;uxtheme.lib;uxtheme.lib;shell32.lib;shlwapi.lib;version.lib;wintrust.lib;%(AdditionalDependencies) RequireAdministrator false Windows MachineX64 /BREPRO %(AdditionalOptions) - advapi32.dll;comctl32.dll;crypt32.dll;gdi32.dll;ole32.dll;dwmapi.dll;setupapi.dll;shell32.dll;shlwapi.dll;version.dll;wintrust.dll;%(DelayLoadDLLs) + advapi32.dll;comctl32.dll;crypt32.dll;gdi32.dll;ole32.dll;dwmapi.dll;setupapi.dll;uxtheme.dll;shell32.dll;shlwapi.dll;version.dll;wintrust.dll;%(DelayLoadDLLs) _UNICODE;UNICODE;%(PreprocessorDefinitions) diff --git a/src/Makefile.in b/src/Makefile.in index 70d31a54..6c20da30 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -280,7 +280,7 @@ NONVULNERABLE_LIBS = -lsetupapi -lole32 -lgdi32 -lshlwapi -lcrypt32 -lcomctl32 - # Ideally there would also be virtdisk and wininet as delaylib's below, but the MinGW folks haven't quite sorted out delay-loading # for x86_32 so as soon as you try to call APIs from these, the application will crash! # See https://github.com/pbatard/rufus/issues/1877#issuecomment-1109683039 as well as https://github.com/pbatard/rufus/issues/2272 -VULNERABLE_LIBS = -ldwmapi-delaylib -lversion-delaylib -lwintrust-delaylib +VULNERABLE_LIBS = -ldwmapi-delaylib -lversion-delaylib -lwintrust-delaylib -luxtheme-delaylib AM_V_WINDRES_0 = @echo " RC $@";$(WINDRES) AM_V_WINDRES_1 = $(WINDRES) AM_V_WINDRES_ = $(AM_V_WINDRES_$(AM_DEFAULT_VERBOSITY)) diff --git a/src/registry.h b/src/registry.h index 7e8312bc..b6d401ea 100644 --- a/src/registry.h +++ b/src/registry.h @@ -26,10 +26,17 @@ #ifdef __cplusplus extern "C" { #endif + +// disable all warnings until fix theme +#ifdef __GNUC__ +#pragma GCC diagnostic ignored "-Wstrict-prototypes" +#pragma GCC diagnostic ignored "-Wunused-variable" +#endif #define REGKEY_HKCU HKEY_CURRENT_USER #define REGKEY_HKLM HKEY_LOCAL_MACHINE + /* Delete a registry key from \Software and all its values If the key has subkeys, this call will fail. */ static __inline BOOL DeleteRegistryKey(HKEY key_root, const char* key_name) diff --git a/src/rufus.c b/src/rufus.c index d106ec71..4d1c6f34 100755 --- a/src/rufus.c +++ b/src/rufus.c @@ -59,8 +59,9 @@ #include "../res/grub2/grub2_version.h" #include #include -#pragma comment(lib,"UxTheme.lib") -#pragma comment(lib,"DwmApi.lib") +#include + + enum bootcheck_return { BOOTCHECK_PROCEED = 0, BOOTCHECK_CANCEL = -1, @@ -106,7 +107,7 @@ extern const char* old_c32_name[NB_OLD_C32]; extern const char* cert_name[3]; extern const char* FileSystemLabel[FS_MAX]; extern const char *bootmgr_efi_name, *efi_dirname, *efi_bootname[ARCH_MAX]; - +static UINT_PTR uIdSubclass = 1; /* * Globals */ @@ -154,8 +155,7 @@ RUFUS_DRIVE rufus_drive[MAX_DRIVES] = { 0 }; // This function sets the alpha channel to 255 without // affecting any of the color channels. -void MakeBitmapOpaque( - HDC hdc, int x, int y, int cx, int cy) +void MakeBitmapOpaque( HDC hdc, int x, int y, int cx, int cy) { BITMAPINFO bi = {0}; bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); @@ -164,12 +164,8 @@ void MakeBitmapOpaque( bi.bmiHeader.biPlanes = 1; bi.bmiHeader.biBitCount = 32; bi.bmiHeader.biCompression = BI_RGB; - RGBQUAD bitmapBits = { 0x00, 0x00, 0x00, 0xFF }; - - StretchDIBits(hdc, x, y, cx, cy, - 0, 0, 1, 1, &bitmapBits, &bi, - DIB_RGB_COLORS, SRCPAINT); + StretchDIBits(hdc, x, y, cx, cy, 0, 0, 1, 1, &bitmapBits, &bi,DIB_RGB_COLORS, SRCPAINT); } // TODO: Remember to update copyright year in stdlg's AboutCallback() WM_INITDIALOG, @@ -963,10 +959,9 @@ out: * DarkMode CheckBox Subclass Proc */ -static LRESULT CALLBACK ButtonSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, - LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) +static LRESULT CALLBACK ButtonSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam,LPARAM lParam, UINT_PTR idSubclass, DWORD_PTR dwRefData) { - if (!IsAppsUseDarkMode) + if (!IsAppsUseDarkMode()) { return DefSubclassProc(hWnd, uMsg, wParam, lParam); } @@ -993,15 +988,15 @@ static LRESULT CALLBACK ButtonSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, rc1.left += siz.cx + 2; FillRect(hDc, &rc1, CreateSolidBrush(ColorControlDark)); rc1.top += GetSystemMetrics(SM_CXPADDEDBORDER); - LPCWSTR* staticText[99] = {0}; - GetWindowText(hWnd, staticText, ARRAYSIZE(staticText)); + WCHAR szCaption[60]; + GetWindowText(hWnd, szCaption, ARRAYSIZE(szCaption)); DTTOPTS opts; opts.dwSize = sizeof(DTTOPTS); opts.dwFlags = DTT_TEXTCOLOR; opts.crText = RGB(255, 255, 255); HFONT font = (HFONT)SendMessage(hWnd, WM_GETFONT, 0, 0); SelectObject(hDc, font); - DrawThemeTextEx(btnTheme, hDc, 3, 0, &staticText, -1, DT_SINGLELINE | DT_LEFT, &rc1, &opts); + DrawThemeTextEx(btnTheme, hDc, 3, 0, szCaption, -1, DT_SINGLELINE | DT_LEFT, &rc1, &opts); ReleaseDC(hWnd, hDc); return true; } @@ -1013,10 +1008,10 @@ static LRESULT CALLBACK ButtonSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, */ static BOOL CALLBACK ThemeCallback(HWND hWnd, LPARAM lParam) { - const char* str[255] = {0}; - GetClassName(hWnd, &str, 255); + WCHAR str[20] = {0}; + GetClassName(hWnd, str, 20); bool isDarkmode = IsAppsUseDarkMode(); - if (strcmp(str, L"Button") == 0) + if (_wcsicmp(str, L"Button") == 0) { LONG_PTR style = GetWindowLongPtr(hWnd, GWL_STYLE); if ((style & BS_AUTOCHECKBOX) == BS_AUTOCHECKBOX) @@ -1033,20 +1028,20 @@ static BOOL CALLBACK ThemeCallback(HWND hWnd, LPARAM lParam) else SetWindowTheme(hWnd, isDarkmode ? L"DarkMode_Explorer" : L"Explorer", NULL); } - else if (strcmp(str, L"ComboBox") == 0) + else if (_wcsicmp(str, L"ComboBox") == 0) { SetWindowTheme(hWnd, isDarkmode ? L"DarkMode_CFD" : L"Explorer", NULL); } - else if (strcmp(str, L"ToolBar") == 0) + else if (_wcsicmp(str, L"ToolbarWindow32") == 0) { wchar_t toolbarText[50]; wchar_t multiToolbarText[50] ; utf8_to_wchar_no_alloc(lmprintf(MSG_315), multiToolbarText, ARRAYSIZE(multiToolbarText)); GetWindowText(hWnd, &toolbarText, 16); - if (strcmp(toolbarText, multiToolbarText) != 0) + if (_wcsicmp(toolbarText, multiToolbarText) != 0) SetWindowTheme(hWnd, isDarkmode ? L"DarkMode" : L"Explorer", NULL); } - else if (strcmp(str, L"EDIT") == 0) + else if (_wcsicmp(str, L"EDIT") == 0) { LONG_PTR style = GetWindowLongPtr(hWnd, GWL_STYLE); if (((style & WS_VSCROLL) == WS_VSCROLL) || ((style & WS_HSCROLL) == WS_HSCROLL)) @@ -1065,11 +1060,9 @@ static BOOL CALLBACK ThemeCallback(HWND hWnd, LPARAM lParam) * DarkMod Dialog Subclass Proc */ -static LRESULT CALLBACK DlgSubclassProc(HWND hDlg, UINT message, WPARAM wParam, - LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) +static LRESULT CALLBACK DlgSubclassProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam, UINT_PTR idSubclass, DWORD_PTR dwRefData) { - RECT rcDlg; - GetClientRect(hDlg, &rcDlg); + HDC dc; switch (message) { @@ -1088,16 +1081,17 @@ static LRESULT CALLBACK DlgSubclassProc(HWND hDlg, UINT message, WPARAM wParam, int borderWidth = (rcWinWidth - rcrcClientWidth) / 2; int captionHight = rcWinHieght - rcrcClientHieght - borderWidth; OffsetRect(&rcWin, -rcWin.left, -rcWin.top); - OffsetRect(&rcClient, borderWidth, captionHight); - HRGN updateRgn = wParam != 1 ?(HRGN)wParam : CreateRectRgnIndirect(&rcWin); + OffsetRect(&rcClient, -rcWin.left, -rcWin.top); + HRGN copy =CreateRectRgn(0, 0, 0, 0); + HRGN updateRgn = wParam != 1 ? copy : CreateRectRgnIndirect(&rcWin); HRGN clipRgn = CreateRectRgn(0, 0, 0, 0); HRGN ncRgn = CreateRectRgn(0, 0, 0, 0); - + CombineRgn(copy, copy, (HRGN)wParam, RGN_COPY); if (wParam == 1) clipRgn = CreateRectRgnIndirect(&rcClient); else GetClipRgn(windowDC, clipRgn); - CombineRgn(ncRgn, updateRgn, clipRgn, RGN_DIFF); + CombineRgn(ncRgn, updateRgn, clipRgn, RGN_OR); SelectClipRgn(windowDC, ncRgn); FillRect(windowDC, &rcWin, CreateSolidBrush(RGB(63, 63, 63))); HRGN hRgn= CreateRectRgnIndirect(&rcWin); @@ -1177,8 +1171,6 @@ static LRESULT CALLBACK DlgSubclassProc(HWND hDlg, UINT message, WPARAM wParam, return (INT_PTR)CreateSolidBrush(ColorControlDark); case WM_CTLCOLORSTATIC: dc = GetDC((HWND)lParam); - RECT rcDlg; - GetClientRect((HWND)lParam, &rcDlg); safe_release_dc((HWND)lParam, dc); if ((HWND)lParam == GetDlgItem(hDlg, IDC_LABEL)) { diff --git a/src/stdlg.c b/src/stdlg.c index 532f81c5..5d9afca8 100644 --- a/src/stdlg.c +++ b/src/stdlg.c @@ -44,6 +44,7 @@ #include "settings.h" #include "license.h" #include +#include /* Globals */ extern BOOL is_x86_64, appstore_version; @@ -61,6 +62,7 @@ static const char* notification_dont_display_setting; static WNDPROC update_original_proc = NULL; static HWINEVENTHOOK ap_weh = NULL; static char title_str[2][128], button_str[128]; +static UINT_PTR uIdSubclass = 1; HWND hFidoDlg = NULL; static int update_settings_reposition_ids[] = { @@ -76,6 +78,8 @@ static int update_settings_reposition_ids[] = { IDCANCEL, }; + + /* * https://blogs.msdn.microsoft.com/oldnewthing/20040802-00/?p=38283/ */ @@ -88,10 +92,9 @@ void SetDialogFocus(HWND hDlg, HWND hCtrl) * DarkMode CheckBox Subclass Proc */ -static LRESULT CALLBACK ButtonSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, - LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) +static LRESULT CALLBACK ButtonSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR idSubclass, DWORD_PTR dwRefData) { - if (!IsAppsUseDarkMode) + if (!IsAppsUseDarkMode()) { return DefSubclassProc(hWnd, uMsg, wParam, lParam); } @@ -118,15 +121,15 @@ static LRESULT CALLBACK ButtonSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, rc1.left += siz.cx + 2; FillRect(hDc, &rc1, CreateSolidBrush(ColorControlDark)); rc1.top += GetSystemMetrics(SM_CXPADDEDBORDER); - LPCWSTR* staticText[99] = {0}; - GetWindowText(hWnd, staticText, ARRAYSIZE(staticText)); + WCHAR szCaption[60]; + GetWindowText(hWnd, szCaption, ARRAYSIZE(szCaption)); DTTOPTS opts; opts.dwSize = sizeof(DTTOPTS); opts.dwFlags = DTT_TEXTCOLOR; opts.crText = RGB(255, 255, 255); HFONT font = (HFONT)SendMessage(hWnd, WM_GETFONT, 0, 0); SelectObject(hDc, font); - DrawThemeTextEx(btnTheme, hDc, 3, 0, &staticText, -1, DT_SINGLELINE | DT_LEFT, &rc1, &opts); + DrawThemeTextEx(btnTheme, hDc, 3, 0, szCaption, -1, DT_SINGLELINE | DT_LEFT, &rc1, &opts); ReleaseDC(hWnd, hDc); return TRUE; } @@ -140,11 +143,11 @@ static LRESULT CALLBACK ButtonSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, static BOOL CALLBACK ThemeCallback(HWND hWnd, LPARAM lParam) { - char* str[255]; - GetClassName(hWnd, &str, 255); + WCHAR str[30] = { 0 }; + GetClassName(hWnd, str, ARRAYSIZE(str)); BOOL isDarkMode = IsAppsUseDarkMode(); - if (strcmp(str, L"Button") == 0) + if (_wcsicmp(str, L"Button") == 0) { LONG_PTR style = GetWindowLongPtr(hWnd, GWL_STYLE); if ((style & BS_AUTOCHECKBOX) == BS_AUTOCHECKBOX) @@ -161,18 +164,18 @@ static BOOL CALLBACK ThemeCallback(HWND hWnd, LPARAM lParam) else SetWindowTheme(hWnd, isDarkMode ? L"DarkMode_Explorer" : L"Explorer", NULL); } - else if (strcmp(str, L"ComboBox") == 0) + else if (_wcsicmp(str, L"ComboBox") == 0) { SetWindowTheme(hWnd, isDarkMode ? L"DarkMode_CFD" : L"Explorer", NULL); } - else if (strcmp(str, L"ToolBar") == 0) + else if (_wcsicmp(str, L"ToolBar") == 0) { - char* title[16]; - GetWindowText(hWnd, &title, 16); - if (strcmp(title, L"Multiple buttons") != 0) + WCHAR title[30] = {0}; + GetWindowText(hWnd, title, ARRAYSIZE(title)); + if (_wcsicmp(title, L"Multiple buttons") != 0) SetWindowTheme(hWnd, isDarkMode ? L"DarkMode" : L"Explorer", NULL); } - else if (strcmp(str, L"EDIT") == 0) + else if (_wcsicmp(str, L"EDIT") == 0) { LONG_PTR style = GetWindowLongPtr(hWnd, GWL_STYLE); if(((style & WS_VSCROLL) == WS_VSCROLL) || ((style & WS_HSCROLL) == WS_HSCROLL)) @@ -182,7 +185,7 @@ static BOOL CALLBACK ThemeCallback(HWND hWnd, LPARAM lParam) } - else if (strcmp(str, L"RichEdit20W") == 0) + else if (_wcsicmp(str, L"RichEdit20W") == 0) { SendMessage(hWnd, EM_SETBKGNDCOLOR, 0, isDarkMode ? (LPARAM)ColorControlDark : (LPARAM)GetSysColor(COLOR_BTNFACE)); CHARFORMAT cf; @@ -204,8 +207,7 @@ static BOOL CALLBACK ThemeCallback(HWND hWnd, LPARAM lParam) * DarkMod Dialog Subclass Proc */ -static LRESULT CALLBACK DlgSubclassProc(HWND hDlg, UINT message, WPARAM wParam, - LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) +static LRESULT CALLBACK DlgSubclassProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam, UINT_PTR idSubclass, DWORD_PTR dwRefData) { if (!IsAppsUseDarkMode()) { @@ -213,9 +215,94 @@ static LRESULT CALLBACK DlgSubclassProc(HWND hDlg, UINT message, WPARAM wParam, } switch (message) { + case WM_NCPAINT: + { + LRESULT result = DefSubclassProc(hDlg, message, wParam, lParam); + HDC windowDC = GetWindowDC(hDlg); + RECT rcWin, rcClient; + GetWindowRect(hDlg, &rcWin); + GetClientRect(hDlg, &rcClient); + MapWindowPoints(hDlg, NULL, (LPPOINT)&rcWin, 2); + int rcWinWidth = rcWin.right - rcWin.left; + int rcWinHieght = rcWin.bottom - rcWin.top; + int rcrcClientWidth = rcClient.right - rcClient.left; + int rcrcClientHieght = rcClient.bottom - rcClient.top; + int borderWidth = (rcWinWidth - rcrcClientWidth) / 2; + int captionHight = rcWinHieght - rcrcClientHieght - borderWidth; + OffsetRect(&rcWin, -rcWin.left, -rcWin.top); + OffsetRect(&rcClient, -rcWin.left, -rcWin.top); + HRGN copy = CreateRectRgn(0, 0, 0, 0); + HRGN updateRgn = wParam != 1 ? copy : CreateRectRgnIndirect(&rcWin); + HRGN clipRgn = CreateRectRgn(0, 0, 0, 0); + HRGN ncRgn = CreateRectRgn(0, 0, 0, 0); + CombineRgn(copy, copy, (HRGN)wParam, RGN_COPY); + if (wParam == 1) + clipRgn = CreateRectRgnIndirect(&rcClient); + else + GetClipRgn(windowDC, clipRgn); + CombineRgn(ncRgn, updateRgn, clipRgn, RGN_OR); + SelectClipRgn(windowDC, ncRgn); + FillRect(windowDC, &rcWin, CreateSolidBrush(RGB(63, 63, 63))); + HRGN hRgn = CreateRectRgnIndirect(&rcWin); + SelectClipRgn(windowDC, hRgn); + MakeBitmapOpaque(windowDC, 0, 0, rcWinWidth, rcWinHieght); + safe_release_dc(hDlg, windowDC); + return result; + } + case WM_NCCALCSIZE: + { + //TODO: get real caption Size + + if (wParam) + { + NCCALCSIZE_PARAMS* ncParma = (NCCALCSIZE_PARAMS*)(lParam); + ncParma->rgrc[0].left += 1;//pr++; + ncParma->rgrc[0].top += 31; + ncParma->rgrc[0].right -= 1; + ncParma->rgrc[0].bottom -= 1; + return 0; + } + else + { + RECT* rect = (RECT*)lParam; + rect->top += 31; + rect->left += 1; + rect->right -= 1; + rect->bottom -= 1; + return 0; + } + } + case WM_SHOWWINDOW: - EnumChildWindows(hDlg, ThemeCallback, lParam); - return DefWindowProc(hDlg, message, wParam, lParam); + { + if (wParam) + { + EnumChildWindows(hDlg, ThemeCallback, lParam); + BOOL allowncpaint = TRUE; + COLORREF caption = RGB(0x0, 0x0, 0x0); + DwmSetWindowAttribute(hDlg, DWMWA_CAPTION_COLOR, &caption, sizeof caption); + DwmSetWindowAttribute(hDlg, DWMWA_BORDER_COLOR, &caption, sizeof caption); + DwmSetWindowAttribute(hDlg, DWMWA_ALLOW_NCPAINT, &allowncpaint, sizeof(int)); + RECT rcDlg; + GetWindowRect(hDlg, &rcDlg); + SetWindowPos(hDlg, 0, 0, 0, rcDlg.right - rcDlg.left, rcDlg.bottom - rcDlg.top, SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE); + + if (hLog) + { + RECT rcLog; + GetWindowRect(hLog, &rcLog); + GetClientRect(hDlg, &rcDlg); + rcLog.left = rcDlg.left + 1; + rcLog.right = rcDlg.right - 1; + SetWindowPos(hLog, NULL, 0, 0, rcLog.right - rcLog.left, rcLog.bottom - rcLog.top, SWP_NOMOVE | SWP_NOZORDER); + } + RedrawWindow(hDlg, NULL, NULL, RDW_ALLCHILDREN | RDW_UPDATENOW | RDW_INVALIDATE | RDW_FRAME | RDW_ERASENOW); + } + + return DefSubclassProc(hDlg, message, wParam, lParam); + + } + case WM_CTLCOLORLISTBOX: SetBkColor((HDC)wParam, RGB(25, 25, 25)); SetTextColor((HDC)wParam, RGB(255, 255, 255)); @@ -228,6 +315,7 @@ static LRESULT CALLBACK DlgSubclassProc(HWND hDlg, UINT message, WPARAM wParam, return (INT_PTR)CreateSolidBrush(RGB(25, 25, 25)); } + case WM_CTLCOLORBTN: case WM_CTLCOLORDLG: return (INT_PTR)CreateSolidBrush(ColorControlDark); diff --git a/src/ui.h b/src/ui.h index c0bb1a2c..0e2189be 100644 --- a/src/ui.h +++ b/src/ui.h @@ -116,4 +116,4 @@ extern void ShowLanguageMenu(RECT rcExclude); extern void SetPassesTooltip(void); extern void SetBootTypeDropdownWidth(void); extern void OnPaint(HDC hdc); -static UINT_PTR uIdSubclass = 1; +extern void MakeBitmapOpaque(HDC hdc, int x, int y, int cx, int cy); diff --git a/src/ui_data.h b/src/ui_data.h index be33e8c1..03dde1d7 100644 --- a/src/ui_data.h +++ b/src/ui_data.h @@ -20,6 +20,10 @@ #include #include "resource.h" + // disable all warnings about unused variable +#ifdef __GNUC__ +#pragma GCC diagnostic ignored "-Wunused-variable" +#endif #pragma once // GUIDs needed to set a control's accessibility props