From 814c4df261eb78ce5e1ffdaebc3cc7f6687f220e Mon Sep 17 00:00:00 2001 From: Mohmed abdel-fattah Date: Mon, 24 Jun 2024 18:16:28 +0300 Subject: [PATCH] The first stage of applying dark mode --- src/registry.h | 11 ++ src/rufus.c | 383 ++++++++++++++++++++++++++++++++++++++++++++++--- src/stdlg.c | 174 +++++++++++++++++++++- src/ui.c | 59 +++++--- src/ui.h | 15 +- 5 files changed, 602 insertions(+), 40 deletions(-) diff --git a/src/registry.h b/src/registry.h index db85ee3e..7e8312bc 100644 --- a/src/registry.h +++ b/src/registry.h @@ -202,6 +202,17 @@ static __inline BOOL WriteRegistryKey32(HKEY root, const char* key, int32_t val) DWORD tmp = (DWORD)val; return SetRegistryKey32(root, key, tmp); } +static __inline BOOL IsAppsUseDarkMode() { + char buffer [4] ; + DWORD cbData = (DWORD)(sizeof(buffer)); + LSTATUS res = RegGetValue(REGKEY_HKCU, L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", L"AppsUseLightTheme", RRF_RT_REG_DWORD, NULL, buffer, &cbData); + if (res == ERROR_SUCCESS) + { + int i = (int)(buffer[3] << 24 | buffer[2] << 16 | buffer[1] << 8 | buffer[0]); + return i == 0; + } + return FALSE; +} /* Helpers for boolean registry operations */ #define ReadRegistryKeyBool(root, key) (ReadRegistryKey32(root, key) != 0) diff --git a/src/rufus.c b/src/rufus.c index 74c73cbc..d106ec71 100755 --- a/src/rufus.c +++ b/src/rufus.c @@ -38,7 +38,7 @@ #include #include #include - +#include"ui_data.h" #include "rufus.h" #include "format.h" #include "missing.h" @@ -57,7 +57,10 @@ #include "cdio/logging.h" #include "../res/grub/grub_version.h" #include "../res/grub2/grub2_version.h" - +#include +#include +#pragma comment(lib,"UxTheme.lib") +#pragma comment(lib,"DwmApi.lib") enum bootcheck_return { BOOTCHECK_PROCEED = 0, BOOTCHECK_CANCEL = -1, @@ -147,6 +150,28 @@ const int nb_steps[FS_MAX] = { 5, 5, 12, 1, 10, 1, 1, 1, 1 }; const char* flash_type[BADLOCKS_PATTERN_TYPES] = { "SLC", "MLC", "TLC" }; RUFUS_DRIVE rufus_drive[MAX_DRIVES] = { 0 }; +// hdc is a memory DC with a 32bpp bitmap selected into it. +// 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) +{ + BITMAPINFO bi = {0}; + bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + bi.bmiHeader.biWidth = 1; + bi.bmiHeader.biHeight = 1; + 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); +} + // TODO: Remember to update copyright year in stdlg's AboutCallback() WM_INITDIALOG, // localization_data.sh and the .rc when the year changes! @@ -934,10 +959,283 @@ out: SetProposedLabel(device_index); return TRUE; } +/* + * DarkMode CheckBox Subclass Proc + */ +static LRESULT CALLBACK ButtonSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, + LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) +{ + if (!IsAppsUseDarkMode) + { + return DefSubclassProc(hWnd, uMsg, wParam, lParam); + } + + switch (uMsg) + { + + case WM_PAINT: + { + DefSubclassProc(hWnd, uMsg, wParam, lParam); + if (!IsWindowEnabled(hWnd)) + { + + return true; + } + HDC hDc = GetDC(hWnd); + RECT rc1; + GetClientRect(hWnd, &rc1); + SetBkMode(hDc, TRANSPARENT); + SetTextColor(hDc, RGB(255, 255, 255)); + HTHEME btnTheme = OpenThemeData(hWnd, L"Button"); + SIZE siz; + GetThemePartSize(btnTheme, hDc, 3, 1, NULL, TS_DRAW, &siz); + rc1.left += siz.cx + 2; + FillRect(hDc, &rc1, CreateSolidBrush(ColorControlDark)); + rc1.top += GetSystemMetrics(SM_CXPADDEDBORDER); + LPCWSTR* staticText[99] = {0}; + GetWindowText(hWnd, staticText, ARRAYSIZE(staticText)); + 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); + ReleaseDC(hWnd, hDc); + return true; + } + } + return DefSubclassProc(hWnd, uMsg, wParam, lParam); +} +/* + * Set DarkMode to all Child Windows + */ +static BOOL CALLBACK ThemeCallback(HWND hWnd, LPARAM lParam) +{ + const char* str[255] = {0}; + GetClassName(hWnd, &str, 255); + bool isDarkmode = IsAppsUseDarkMode(); + if (strcmp(str, L"Button") == 0) + { + LONG_PTR style = GetWindowLongPtr(hWnd, GWL_STYLE); + if ((style & BS_AUTOCHECKBOX) == BS_AUTOCHECKBOX) + { + if (!isDarkmode) + { + RemoveWindowSubclass(hWnd, ButtonSubclassProc, uIdSubclass); + return true; + } + else + SetWindowSubclass(hWnd, ButtonSubclassProc, uIdSubclass, 0); + } + + else + SetWindowTheme(hWnd, isDarkmode ? L"DarkMode_Explorer" : L"Explorer", NULL); + } + else if (strcmp(str, L"ComboBox") == 0) + { + SetWindowTheme(hWnd, isDarkmode ? L"DarkMode_CFD" : L"Explorer", NULL); + } + else if (strcmp(str, L"ToolBar") == 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) + SetWindowTheme(hWnd, isDarkmode ? L"DarkMode" : L"Explorer", NULL); + } + else if (strcmp(str, L"EDIT") == 0) + { + LONG_PTR style = GetWindowLongPtr(hWnd, GWL_STYLE); + if (((style & WS_VSCROLL) == WS_VSCROLL) || ((style & WS_HSCROLL) == WS_HSCROLL)) + SetWindowTheme(hWnd, isDarkmode ? L"DarkMode_Explorer" : L"Explorer", NULL); + else + SetWindowTheme(hWnd, isDarkmode ? L"DarkMode_CFD" : L"Explorer", NULL); + + + + } + + return TRUE; +} + +/* + * DarkMod Dialog Subclass Proc + */ + +static LRESULT CALLBACK DlgSubclassProc(HWND hDlg, UINT message, WPARAM wParam, + LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) +{ + RECT rcDlg; + GetClientRect(hDlg, &rcDlg); + HDC dc; + 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, borderWidth, captionHight); + HRGN updateRgn = wParam != 1 ?(HRGN)wParam : CreateRectRgnIndirect(&rcWin); + HRGN clipRgn = CreateRectRgn(0, 0, 0, 0); + HRGN ncRgn = CreateRectRgn(0, 0, 0, 0); + + if (wParam == 1) + clipRgn = CreateRectRgnIndirect(&rcClient); + else + GetClipRgn(windowDC, clipRgn); + CombineRgn(ncRgn, updateRgn, clipRgn, RGN_DIFF); + 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: + { + 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)); + return (INT_PTR)CreateSolidBrush(RGB(25, 25, 25)); + case WM_CTLCOLOREDIT: + { + HDC hdc = (HDC)wParam; + SetBkColor((HDC)wParam, RGB(25, 25, 25)); + HBRUSH sysbrash = GetSysColorBrush(COLOR_WINDOWFRAME); + SetTextColor(hdc, RGB(255, 255, 255)); + return (INT_PTR)CreateSolidBrush(RGB(25, 25, 25)); + } + case WM_CTLCOLORBTN: + case WM_CTLCOLORDLG: + 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)) + { + + SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOWFRAME)); + + + return (INT_PTR)CreateSolidBrush(RGB(25, 25, 25)); + } + if ((HWND)lParam != GetDlgItem(hDlg, IDS_CSM_HELP_TXT)) + { + + SetBkMode((HDC)wParam, TRANSPARENT); + SetTextColor((HDC)wParam, TOOLBAR_ICON_COLOR); + //MakeBitmapOpaque((HDC)wParam, 0, 0, rcDlg.right - rcDlg.left, rcDlg.bottom - rcDlg.top); + + return (INT_PTR)CreateSolidBrush(ColorControlDark); + } + SetBkMode((HDC)wParam, TRANSPARENT); + SetTextColor((HDC)wParam, TOOLBAR_ICON_COLOR); + + return (INT_PTR)CreateSolidBrush(ColorControlDark); + case WM_SETTINGCHANGE: + { + if (IsAppsUseDarkMode()) + { + BOOL allowncpaint = TRUE; + COLORREF caption = RGB(0x0,0x0,0x0); + DWM_WINDOW_CORNER_PREFERENCE f = DWMWCP_DONOTROUND; + DwmSetWindowAttribute(hDlg, DWMWA_CAPTION_COLOR, &caption, sizeof caption); + DwmSetWindowAttribute(hDlg, DWMWA_BORDER_COLOR, &caption, sizeof caption); + DwmSetWindowAttribute(hDlg, DWMWA_WINDOW_CORNER_PREFERENCE, &f, sizeof(f)); + DwmSetWindowAttribute(hDlg, DWMWA_ALLOW_NCPAINT, &allowncpaint, sizeof(int)); + if (hLog) + { + RECT rcLog, rcDlg; + 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); + } + } + return DefSubclassProc(hDlg, message, wParam, lParam); + } + + default: + return DefSubclassProc(hDlg, message, wParam, lParam); + break; + } +} // Callback for the log window + BOOL CALLBACK LogCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { + BOOL resized_already = FALSE; + REQRESIZE* rsz; HDC hDC; HFONT hf; LONG lfHeight; @@ -948,10 +1246,14 @@ BOOL CALLBACK LogCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) switch (message) { case WM_INITDIALOG: apply_localization(IDD_LOG, hDlg); + hLog = GetDlgItem(hDlg, IDC_LOG_EDIT); - // Increase the size of our log textbox to MAX_LOG_SIZE (unsigned word) PostMessage(hLog, EM_LIMITTEXT, MAX_LOG_SIZE , 0); + if (IsAppsUseDarkMode()) + { + SetWindowSubclass(hDlg, DlgSubclassProc, uIdSubclass, 0); + } // Set the font to Unicode so that we can display anything hDC = GetDC(NULL); lfHeight = -MulDiv(9, GetDeviceCaps(hDC, LOGPIXELSY), 72); @@ -973,6 +1275,7 @@ BOOL CALLBACK LogCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) style &= ~(ES_RIGHT); SetWindowLongPtr(hLog, GWL_STYLE, style); break; + case WM_COMMAND: switch (LOWORD(wParam)) { case IDCANCEL: @@ -1018,7 +1321,34 @@ BOOL CALLBACK LogCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) ResizeButtonHeight(hDlg, IDC_LOG_SAVE); ResizeButtonHeight(hDlg, IDC_LOG_CLEAR); return TRUE; + case WM_SETTINGCHANGE: + if (!IsAppsUseDarkMode()) + { + BOOL allowncpaint = FALSE; + COLORREF caption = DWMWA_COLOR_DEFAULT; + DWM_WINDOW_CORNER_PREFERENCE f = DWMWCP_DONOTROUND; + DwmSetWindowAttribute(hDlg, DWMWA_CAPTION_COLOR, &caption, sizeof caption); + DwmSetWindowAttribute(hDlg, DWMWA_ALLOW_NCPAINT, &allowncpaint, sizeof(int)); + DwmSetWindowAttribute(hDlg, DWMWA_BORDER_COLOR, &caption, sizeof caption); + DwmSetWindowAttribute(hDlg, DWMWA_WINDOW_CORNER_PREFERENCE, &f, sizeof(f)); + if (hLog) + { + RECT rcLog, rcDlg; + 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); + } + RemoveWindowSubclass(hDlg, DlgSubclassProc, uIdSubclass); + } + + else + SetWindowSubclass(hDlg, DlgSubclassProc, uIdSubclass, 0); + EnumChildWindows(hDlg, ThemeCallback, lParam); + return TRUE; } + return FALSE; } @@ -1232,6 +1562,7 @@ out: return ret; } + // The scanning process can be blocking for message processing => use a thread DWORD WINAPI ImageScanThread(LPVOID param) { @@ -2149,6 +2480,8 @@ static void PrintStatusTimeout(const char* str, BOOL val) /* * Main dialog callback */ + + static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { static DWORD DeviceNum = 0; @@ -2178,7 +2511,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA loc_cmd* lcmd = NULL; switch (message) { - + case WM_COMMAND: #ifdef RUFUS_TEST if (LOWORD(wParam) == IDC_TEST) { @@ -2704,6 +3037,8 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA fScale = GetDeviceCaps(hDC, LOGPIXELSX) / 96.0f; safe_release_dc(hDlg, hDC); apply_localization(IDD_DIALOG, hDlg); + if (IsAppsUseDarkMode()) + SetWindowSubclass(hDlg, DlgSubclassProc, uIdSubclass, 0); // The AppStore version always enables Fido if (appstore_version) SetFidoCheck(); @@ -2713,6 +3048,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA log_displayed = FALSE; hLogDialog = MyCreateDialog(hMainInstance, IDD_LOG, hDlg, (DLGPROC)LogCallback); InitDialog(hDlg); + GetDevices(0); EnableControls(TRUE, FALSE); UpdateImage(FALSE); @@ -2735,7 +3071,8 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA // Set 'START' as the selected button if it's enabled, otherwise use 'SELECT', instead SendMessage(hDlg, WM_NEXTDLGCTL, (WPARAM)(IsWindowEnabled(hStart) ? hStart : hSelectImage), TRUE); - + + #if defined(ALPHA) // Add a VERY ANNOYING popup for Alpha releases, so that people don't start redistributing them MessageBoxA(NULL, "This is an Alpha version of " APPLICATION_NAME " - It is meant to be used for " @@ -2746,11 +3083,13 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA "testing ONLY and should NOT be distributed as a release.", "TEST VERSION", MSG_INFO); #endif // Let's not take any risk: Ask Windows to redraw the whole dialog before we exit init + RedrawWindow(hMainDialog, NULL, NULL, RDW_ALLCHILDREN | RDW_UPDATENOW); InvalidateRect(hMainDialog, NULL, TRUE); - + + return (INT_PTR)FALSE; - + case WM_DRAWITEM: // The things one must do to get an ellipsis and text alignment on the status bar... if (wParam == IDC_STATUS) { @@ -2773,22 +3112,34 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA return (INT_PTR)TRUE; } } + break; - + case WM_SETTINGCHANGE: + if (!IsAppsUseDarkMode()) + { + BOOL allowncpaint = FALSE; + COLORREF caption = DWMWA_COLOR_DEFAULT; + DWM_WINDOW_CORNER_PREFERENCE f = DWMWCP_ROUND; + DwmSetWindowAttribute(hDlg, DWMWA_CAPTION_COLOR, &caption, sizeof caption); + DwmSetWindowAttribute(hDlg, DWMWA_BORDER_COLOR, &caption, sizeof caption); + DwmSetWindowAttribute(hDlg, DWMWA_WINDOW_CORNER_PREFERENCE, &f, sizeof(f)); + DwmSetWindowAttribute(hDlg, DWMWA_ALLOW_NCPAINT, &allowncpaint, sizeof(int)); + RemoveWindowSubclass(hDlg, DlgSubclassProc, uIdSubclass); + } + else + { + SetWindowSubclass(hDlg, DlgSubclassProc, uIdSubclass, 0); + } + + EnumChildWindows(hDlg, ThemeCallback, lParam); + RedrawWindow(hMainDialog, NULL, NULL, RDW_ALLCHILDREN | RDW_UPDATENOW | RDW_ERASENOW); + return DefWindowProc(hDlg, message, wParam, lParam); case WM_PAINT: hDC = BeginPaint(hDlg, &ps); OnPaint(hDC); EndPaint(hDlg, &ps); break; - case WM_CTLCOLORSTATIC: - if ((HWND)lParam != GetDlgItem(hDlg, IDS_CSM_HELP_TXT)) - return FALSE; - SetBkMode((HDC)wParam, TRANSPARENT); - CreateStaticFont((HDC)wParam, &hyperlink_font, FALSE); - SelectObject((HDC)wParam, hyperlink_font); - SetTextColor((HDC)wParam, TOOLBAR_ICON_COLOR); - return (INT_PTR)CreateSolidBrush(GetSysColor(COLOR_BTNFACE)); case WM_NOTIFY: switch (((LPNMHDR)lParam)->code) { diff --git a/src/stdlg.c b/src/stdlg.c index e75987c4..532f81c5 100644 --- a/src/stdlg.c +++ b/src/stdlg.c @@ -43,6 +43,7 @@ #include "registry.h" #include "settings.h" #include "license.h" +#include /* Globals */ extern BOOL is_x86_64, appstore_version; @@ -83,6 +84,162 @@ void SetDialogFocus(HWND hDlg, HWND hCtrl) SendMessage(hDlg, WM_NEXTDLGCTL, (WPARAM)hCtrl, TRUE); } +/* + * DarkMode CheckBox Subclass Proc + */ + +static LRESULT CALLBACK ButtonSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, + LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) +{ + if (!IsAppsUseDarkMode) + { + return DefSubclassProc(hWnd, uMsg, wParam, lParam); + } + + switch (uMsg) + { + + case WM_PAINT: + { + DefSubclassProc(hWnd, uMsg, wParam, lParam); + if (!IsWindowEnabled(hWnd)) + { + + return TRUE; + } + HDC hDc = GetDC(hWnd); + RECT rc1; + GetClientRect(hWnd, &rc1); + SetBkMode(hDc, TRANSPARENT); + SetTextColor(hDc, RGB(255, 255, 255)); + HTHEME btnTheme = OpenThemeData(hWnd, L"Button"); + SIZE siz; + GetThemePartSize(btnTheme, hDc, 3, 1, NULL, TS_DRAW, &siz); + rc1.left += siz.cx + 2; + FillRect(hDc, &rc1, CreateSolidBrush(ColorControlDark)); + rc1.top += GetSystemMetrics(SM_CXPADDEDBORDER); + LPCWSTR* staticText[99] = {0}; + GetWindowText(hWnd, staticText, ARRAYSIZE(staticText)); + 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); + ReleaseDC(hWnd, hDc); + return TRUE; + } + } + return DefSubclassProc(hWnd, uMsg, wParam, lParam); +} + +/* + * Set DarkMode to all Child Windows + */ + +static BOOL CALLBACK ThemeCallback(HWND hWnd, LPARAM lParam) +{ + char* str[255]; + GetClassName(hWnd, &str, 255); + BOOL isDarkMode = IsAppsUseDarkMode(); + + if (strcmp(str, L"Button") == 0) + { + LONG_PTR style = GetWindowLongPtr(hWnd, GWL_STYLE); + if ((style & BS_AUTOCHECKBOX) == BS_AUTOCHECKBOX) + { + if (!isDarkMode) + { + RemoveWindowSubclass(hWnd, ButtonSubclassProc, uIdSubclass); + return TRUE; + } + else + SetWindowSubclass(hWnd, ButtonSubclassProc, uIdSubclass, 0); + } + + else + SetWindowTheme(hWnd, isDarkMode ? L"DarkMode_Explorer" : L"Explorer", NULL); + } + else if (strcmp(str, L"ComboBox") == 0) + { + SetWindowTheme(hWnd, isDarkMode ? L"DarkMode_CFD" : L"Explorer", NULL); + } + else if (strcmp(str, L"ToolBar") == 0) + { + char* title[16]; + GetWindowText(hWnd, &title, 16); + if (strcmp(title, L"Multiple buttons") != 0) + SetWindowTheme(hWnd, isDarkMode ? L"DarkMode" : L"Explorer", NULL); + } + else if (strcmp(str, L"EDIT") == 0) + { + LONG_PTR style = GetWindowLongPtr(hWnd, GWL_STYLE); + if(((style & WS_VSCROLL) == WS_VSCROLL) || ((style & WS_HSCROLL) == WS_HSCROLL)) + SetWindowTheme(hWnd, isDarkMode ? L"DarkMode_Explorer" : L"Explorer", NULL); + else + SetWindowTheme(hWnd, isDarkMode ? L"DarkMode_CFD" : L"Explorer", NULL); + + + } + else if (strcmp(str, L"RichEdit20W") == 0) + { + SendMessage(hWnd, EM_SETBKGNDCOLOR, 0, isDarkMode ? (LPARAM)ColorControlDark : (LPARAM)GetSysColor(COLOR_BTNFACE)); + CHARFORMAT cf; + cf.cbSize = sizeof(cf); + cf.dwMask = CFM_COLOR; + cf.crTextColor = isDarkMode ? RGB(255, 255, 255): RGB(0, 0, 0); + cf.dwEffects = 0; + SendMessage(hWnd, EM_SETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cf); + //SetWindowTheme(hEdit[i], L"DarkMode_Explorer", NULL); + SetWindowTheme(hWnd, NULL, isDarkMode ? L"DarkMode_Explorer::ScrollBar" : L"Explorer::ScrollBar"); + + + } + + return TRUE; +} + +/* + * DarkMod Dialog Subclass Proc + */ + +static LRESULT CALLBACK DlgSubclassProc(HWND hDlg, UINT message, WPARAM wParam, + LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) +{ + if (!IsAppsUseDarkMode()) + { + return DefSubclassProc(hDlg, message, wParam, lParam); + } + switch (message) + { + case WM_SHOWWINDOW: + EnumChildWindows(hDlg, ThemeCallback, lParam); + return DefWindowProc(hDlg, message, wParam, lParam); + case WM_CTLCOLORLISTBOX: + SetBkColor((HDC)wParam, RGB(25, 25, 25)); + SetTextColor((HDC)wParam, RGB(255, 255, 255)); + return (INT_PTR)CreateSolidBrush(RGB(25, 25, 25)); + case WM_CTLCOLOREDIT: + { + HDC hdc = (HDC)wParam; + SetBkColor((HDC)wParam, RGB(25, 25, 25)); + SetTextColor(hdc, RGB(255, 255, 255)); + return (INT_PTR)CreateSolidBrush(RGB(25, 25, 25)); + + } + case WM_CTLCOLORBTN: + case WM_CTLCOLORDLG: + return (INT_PTR)CreateSolidBrush(ColorControlDark); + case WM_CTLCOLORSTATIC: + SetBkMode((HDC)wParam, TRANSPARENT); + SetTextColor((HDC)wParam, TOOLBAR_ICON_COLOR); + return (INT_PTR)CreateSolidBrush(ColorControlDark); + default: + return DefSubclassProc(hDlg, message, wParam, lParam); + break; + } +} /* * Return the UTF8 path of a file selected through a load or save dialog * All string parameters are UTF-8 @@ -216,7 +373,6 @@ out: void CreateStatusBar(void) { RECT rect; - int edge[2]; HFONT hFont; // Create the status bar @@ -226,10 +382,10 @@ void CreateStatusBar(void) // Create 2 status areas GetClientRect(hMainDialog, &rect); - edge[0] = rect.right - (int)(SB_TIMER_SECTION_SIZE * fScale); - edge[1] = rect.right; - SendMessage(hStatus, SB_SETPARTS, (WPARAM)ARRAYSIZE(edge), (LPARAM)&edge); + int edge[] = { rect.right - (int)(SB_TIMER_SECTION_SIZE * fScale) , rect.right,-1}; + SendMessage(hStatus, SB_SETPARTS, (WPARAM)ARRAYSIZE(edge), (LPARAM)&edge); + //SendMessage(hStatus, WM_SIZE, 0, 0); // Set the font hFont = CreateFontA(-MulDiv(9, GetDeviceCaps(GetDC(hMainDialog), LOGPIXELSY), 72), 0, 0, 0, FW_MEDIUM, FALSE, FALSE, FALSE, DEFAULT_CHARSET, @@ -337,6 +493,7 @@ INT_PTR CALLBACK LicenseCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM style &= ~(ES_RIGHT); SetWindowLongPtr(hLicense, GWL_STYLE, style); SetDlgItemTextA(hDlg, IDC_LICENSE_TEXT, gplv3); + SetWindowSubclass(hDlg, DlgSubclassProc, uIdSubclass, 0); break; case WM_COMMAND: switch (LOWORD(wParam)) { @@ -403,6 +560,7 @@ INT_PTR CALLBACK AboutCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM lP // Need to send an explicit SetSel to avoid being positioned at the end of richedit control when tabstop is used SendMessage(hEdit[1], EM_SETSEL, 0, 0); SendMessage(hEdit[0], EM_REQUESTRESIZE, 0, 0); + SetWindowSubclass(hDlg, DlgSubclassProc, uIdSubclass, 0); break; case WM_NOTIFY: switch (((LPNMHDR)lParam)->code) { @@ -555,6 +713,7 @@ INT_PTR CALLBACK NotificationCallback(HWND hDlg, UINT message, WPARAM wParam, LP ResizeMoveCtrl(hDlg, GetDlgItem(hDlg, IDYES), 0, dh -cbh, 0, 0, 1.0f); ResizeMoveCtrl(hDlg, GetDlgItem(hDlg, IDNO), 0, dh -cbh, 0, 0, 1.0f); } + SetWindowSubclass(hDlg, DlgSubclassProc, uIdSubclass, 0); return (INT_PTR)TRUE; case WM_CTLCOLORSTATIC: // Change the background colour for static text and icon @@ -988,6 +1147,9 @@ INT_PTR CALLBACK TooltipCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM return (INT_PTR)FALSE; switch (message) { + case WM_NCPAINT: + SendMessageW(ttlist[i].hTip, TTM_SETWINDOWTHEME, 0, IsAppsUseDarkMode() ? ((LPARAM)&L"DarkMode_Explorer") : ((LPARAM)&L"Explorer")); + return CallWindowProc(ttlist[i].original_proc, hDlg, message, wParam, lParam); case WM_NOTIFY: switch (((LPNMHDR)lParam)->code) { case TTN_GETDISPINFOW: @@ -1318,6 +1480,7 @@ INT_PTR CALLBACK UpdateCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM l SendMessage(hPolicy, EM_SETEVENTMASK, 0, ENM_LINK|ENM_REQUESTRESIZE); SendMessageA(hPolicy, EM_SETBKGNDCOLOR, 0, (LPARAM)GetSysColor(COLOR_BTNFACE)); SendMessage(hPolicy, EM_REQUESTRESIZE, 0, 0); + SetWindowSubclass(hDlg, DlgSubclassProc, uIdSubclass, 0); break; case WM_NOTIFY: if ((((LPNMHDR)lParam)->code == EN_REQUESTRESIZE) && (!resized_already)) { @@ -1568,6 +1731,9 @@ INT_PTR CALLBACK NewVersionCallback(HWND hDlg, UINT message, WPARAM wParam, LPAR case WM_CTLCOLORSTATIC: if ((HWND)lParam != GetDlgItem(hDlg, IDC_WEBSITE)) return FALSE; + HDC hdcCtrl = GET_WM_CTLCOLOR_HDC(wParam, lParam, message); + HWND hWndCtrl = GET_WM_CTLCOLOR_HWND(wParam, lParam, message); + WORD cc = GET_WM_CTLCOLOR_TYPE(wParam, lParam, message); // Change the font for the hyperlink SetBkMode((HDC)wParam, TRANSPARENT); CreateStaticFont((HDC)wParam, &hyperlink_font, TRUE); diff --git a/src/ui.c b/src/ui.c index 166e2b0a..4b8e144b 100644 --- a/src/ui.c +++ b/src/ui.c @@ -38,10 +38,10 @@ #include "resource.h" #include "msapi_utf8.h" #include "localization.h" - +#include "WinUser.h" #include "ui.h" #include "ui_data.h" - +#include "registry.h" UINT_PTR UM_LANGUAGE_MENU_MAX = UM_LANGUAGE_MENU; HIMAGELIST hUpImageList, hDownImageList; extern BOOL use_vds, appstore_version; @@ -350,11 +350,18 @@ void PositionMainControls(HWND hDlg) GetWindowRect(hCtrl, &rc); MapWindowPoints(NULL, hDlg, (POINT*)&rc, 2); advanced_device_section_height = rc.top; + LONG_PTR style = GetWindowLongPtrW(hCtrl, GWL_STYLE); + /*if ((style & SS_OWNERDRAW) != SS_OWNERDRAW) + { + style |= SS_OWNERDRAW; + style |= ~BS_AUTOCHECKBOX; + SetWindowLongPtrW(hCtrl, GWL_STYLE, style); + }*/ hCtrl = GetDlgItem(hDlg, IDC_UEFI_MEDIA_VALIDATION); GetWindowRect(hCtrl, &rc); MapWindowPoints(NULL, hDlg, (POINT*)&rc, 2); advanced_device_section_height = rc.bottom - advanced_device_section_height; - + hCtrl = GetDlgItem(hDlg, IDC_QUICK_FORMAT); GetWindowRect(hCtrl, &rc); MapWindowPoints(NULL, hDlg, (POINT*)&rc, 2); @@ -893,14 +900,20 @@ static INT_PTR CALLBACK ProgressCallback(HWND hCtrl, UINT message, WPARAM wParam wchar_t winfo[128]; static BOOL marquee_mode = FALSE; static uint32_t pos = 0, min = 0, max = 0xFFFF; - static COLORREF color = PROGRESS_BAR_NORMAL_COLOR; + BOOL isDark = IsAppsUseDarkMode(); + COLORREF normalColor = isDark ? PROGRESS_BAR_DARK_NORMAL_COLOR : PROGRESS_BAR_NORMAL_COLOR; + COLORREF backgroundColor = isDark ? PROGRESS_BAR_DARK_BACKGROUND_COLOR : PROGRESS_BAR_BACKGROUND_COLOR; + COLORREF normalTextColor = isDark ? PROGRESS_BAR_DARK_NORMAL_TEXT_COLOR : PROGRESS_BAR_NORMAL_TEXT_COLOR; + COLORREF invertedlTextColor = isDark ? PROGRESS_BAR_DARK_INVERTED_TEXT_COLOR : PROGRESS_BAR_INVERTED_TEXT_COLOR; + COLORREF boxColor = isDark ? PROGRESS_BAR_DARK_BOX_COLOR : PROGRESS_BAR_BOX_COLOR; + COLORREF color = normalColor; switch (message) { case PBM_SETSTATE: switch (wParam) { case PBST_NORMAL: - color = PROGRESS_BAR_NORMAL_COLOR; + color = normalColor; break; case PBST_PAUSED: color = PROGRESS_BAR_PAUSED_COLOR; @@ -930,7 +943,7 @@ static INT_PTR CALLBACK ProgressCallback(HWND hCtrl, UINT message, WPARAM wParam if ((wParam == TRUE) && (!marquee_mode)) { marquee_mode = TRUE; pos = min; - color = PROGRESS_BAR_NORMAL_COLOR; + color = normalColor; SetTimer(hCtrl, TID_MARQUEE_TIMER, MARQUEE_TIMER_REFRESH, NULL); InvalidateRect(hProgress, NULL, TRUE); } else if ((wParam == FALSE) && (marquee_mode)) { @@ -971,7 +984,7 @@ static INT_PTR CALLBACK ProgressCallback(HWND hCtrl, UINT message, WPARAM wParam // Optional first segment if (pos + ((max - min) / 5) > max) { rc.right = MulDiv(pos + ((max - min) / 5) - max, rc.right, max - min); - SetTextColor(hDC, PROGRESS_BAR_INVERTED_TEXT_COLOR); + SetTextColor(hDC, invertedlTextColor); SetBkColor(hDC, color); ExtTextOut(hDC, (full_right - size.cx) / 2, (rc.bottom - size.cy) / 2, ETO_CLIPPED | ETO_OPAQUE | ETO_NUMERICSLOCAL, &rc, winfo, (int)wcslen(winfo), NULL); @@ -981,8 +994,8 @@ static INT_PTR CALLBACK ProgressCallback(HWND hCtrl, UINT message, WPARAM wParam // Optional second segment if (pos > min) { rc.right = MulDiv(pos - min, rc.right, max - min); - SetTextColor(hDC, PROGRESS_BAR_NORMAL_TEXT_COLOR); - SetBkColor(hDC, PROGRESS_BAR_BACKGROUND_COLOR); + SetTextColor(hDC, normalTextColor); + SetBkColor(hDC, backgroundColor); ExtTextOut(hDC, (full_right - size.cx) / 2, (rc.bottom - size.cy) / 2, ETO_CLIPPED | ETO_OPAQUE | ETO_NUMERICSLOCAL, &rc, winfo, (int)wcslen(winfo), NULL); rc.left = rc.right; @@ -990,14 +1003,14 @@ static INT_PTR CALLBACK ProgressCallback(HWND hCtrl, UINT message, WPARAM wParam } // Second to last segment rc.right = MulDiv(pos - min + ((max - min) / 5), rc.right, max - min); - SetTextColor(hDC, PROGRESS_BAR_INVERTED_TEXT_COLOR); + SetTextColor(hDC, invertedlTextColor); SetBkColor(hDC, color); ExtTextOut(hDC, (full_right - size.cx) / 2, (rc.bottom - size.cy) / 2, ETO_CLIPPED | ETO_OPAQUE | ETO_NUMERICSLOCAL, &rc, winfo, (int)wcslen(winfo), NULL); } else { // First segment rc.right = (pos > min) ? MulDiv(pos - min, rc.right, max - min) : rc.left; - SetTextColor(hDC, PROGRESS_BAR_INVERTED_TEXT_COLOR); + SetTextColor(hDC, invertedlTextColor); SetBkColor(hDC, color); ExtTextOut(hDC, (full_right - size.cx) / 2, (rc.bottom - size.cy) / 2, ETO_CLIPPED | ETO_OPAQUE | ETO_NUMERICSLOCAL, &rc, winfo, (int)wcslen(winfo), NULL); @@ -1005,12 +1018,12 @@ static INT_PTR CALLBACK ProgressCallback(HWND hCtrl, UINT message, WPARAM wParam // Last segment rc.left = rc.right; rc.right = full_right; - SetTextColor(hDC, PROGRESS_BAR_NORMAL_TEXT_COLOR); - SetBkColor(hDC, PROGRESS_BAR_BACKGROUND_COLOR); + SetTextColor(hDC, normalTextColor); + SetBkColor(hDC, backgroundColor); ExtTextOut(hDC, (full_right - size.cx) / 2, (rc.bottom - size.cy) / 2, ETO_CLIPPED | ETO_OPAQUE | ETO_NUMERICSLOCAL, &rc, winfo, (int)wcslen(winfo), NULL); // Bounding rectangle - SetDCPenColor(hDC, PROGRESS_BAR_BOX_COLOR); + SetDCPenColor(hDC, boxColor); Rectangle(hDC, rc2.left, rc2.top, rc2.right, rc2.bottom); EndPaint(hCtrl, &ps); return (INT_PTR)TRUE; @@ -1060,9 +1073,17 @@ void CreateAdditionalControls(HWND hDlg) hIconDown = (HICON)LoadImage(hDll, MAKEINTRESOURCE(16750), IMAGE_ICON, s16, s16, LR_DEFAULTCOLOR | LR_SHARED); hUpImageList = ImageList_Create(i16, i16, ILC_COLOR32 | ILC_HIGHQUALITYSCALE, 1, 0); hDownImageList = ImageList_Create(i16, i16, ILC_COLOR32 | ILC_HIGHQUALITYSCALE, 1, 0); - ImageList_AddIcon(hUpImageList, hIconUp); - ImageList_AddIcon(hDownImageList, hIconDown); - + if (!IsAppsUseDarkMode()) + { + ImageList_AddIcon(hUpImageList, hIconUp); + ImageList_AddIcon(hDownImageList, hIconDown); + } + else + { + ImageList_AddMasked(hUpImageList, LoadBitmap(0, MAKEINTRESOURCE(32753)), CLR_DEFAULT); + ImageList_AddMasked(hDownImageList, LoadBitmap(0, MAKEINTRESOURCE(32752)), CLR_DEFAULT); + } + // Create the advanced options toolbars memset(wtbtext, 0, sizeof(wtbtext)); utf8_to_wchar_no_alloc(lmprintf((advanced_mode_device) ? MSG_122 : MSG_121, lmprintf(MSG_119)), wtbtext[0], ARRAYSIZE(wtbtext[0])); @@ -1585,10 +1606,12 @@ void SetBootTypeDropdownWidth(void) void OnPaint(HDC hdc) { int i; - HPEN hp = CreatePen(0, (fScale < 1.5f) ? 2 : 3, RGB(0, 0, 0)); + + HPEN hp = CreatePen(0, (fScale < 1.5f) ? 2 : 3, IsAppsUseDarkMode() ? RGB(255,255,255) : RGB(0, 0, 0)); SelectObject(hdc, hp); for (i = 0; i < ARRAYSIZE(section_vpos); i++) { MoveToEx(hdc, mw + 10, section_vpos[i], NULL); LineTo(hdc, mw + fw, section_vpos[i]); } + } diff --git a/src/ui.h b/src/ui.h index 746aefc7..c0bb1a2c 100644 --- a/src/ui.h +++ b/src/ui.h @@ -21,7 +21,8 @@ #include #include "resource.h" #include "localization.h" - +//#include +//#include #pragma once // Progress bar colors @@ -33,8 +34,17 @@ #define PROGRESS_BAR_PAUSED_COLOR RGB(0xDA, 0xCB, 0x26) #define PROGRESS_BAR_ERROR_COLOR RGB(0xDA, 0x26, 0x26) +#define PROGRESS_BAR_DARK_NORMAL_TEXT_COLOR RGB(0xFF, 0xFF, 0xFF) +#define PROGRESS_BAR_DARK_INVERTED_TEXT_COLOR RGB(0x00, 0x00, 0x00) +#define PROGRESS_BAR_DARK_BACKGROUND_COLOR RGB(0x3F, 0x3F, 0x3F) +#define PROGRESS_BAR_DARK_BOX_COLOR RGB(192, 192,192) +#define PROGRESS_BAR_DARK_NORMAL_COLOR RGB(40,100,180) +#define PROGRESS_BAR_DARK_PAUSED_COLOR RGB(0xDA, 0xCB, 0x26) +#define PROGRESS_BAR_DARK_ERROR_COLOR RGB(0xDA, 0x26, 0x26) +#define ColorControlDark RGB(32, 32, 32) + // Toolbar icons main color -#define TOOLBAR_ICON_COLOR RGB(0x29, 0x80, 0xB9) +#define TOOLBAR_ICON_COLOR RGB(255, 255, 255) //(0x29, 0x80, 0xB9) // Toolbar default style #define TOOLBAR_STYLE ( WS_CHILD | WS_TABSTOP | WS_VISIBLE | \ @@ -106,3 +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;