Index: reactos/base/applications/calc/CMakeLists.txt =================================================================== --- reactos/base/applications/calc/CMakeLists.txt (revision 74958) +++ reactos/base/applications/calc/CMakeLists.txt (working copy) @@ -13,7 +13,7 @@ add_rc_deps(resource.rc ${calc_rc_deps}) add_executable(calc ${SOURCE} resource.rc) set_module_type(calc win32gui UNICODE) -add_importlibs(calc advapi32 user32 shell32 gdi32 msvcrt kernel32) +add_importlibs(calc advapi32 comctl32 user32 shell32 gdi32 msvcrt kernel32) if(MSVC) add_importlibs(calc ntdll) Index: reactos/base/applications/calc/winmain.c =================================================================== --- reactos/base/applications/calc/winmain.c (revision 74958) +++ reactos/base/applications/calc/winmain.c (working copy) @@ -1,9 +1,10 @@ #include "calc.h" -#include -#include -#include +#include +#include #include +#include +#include #define HTMLHELP_PATH(_pt) TEXT("%systemroot%\\Help\\calc.chm::") TEXT(_pt) @@ -224,6 +225,63 @@ calc_t calc; +HINSTANCE s_hinstTheme = NULL; +HTHEME s_hTheme = NULL; + +// OpenThemeData +typedef HTHEME (WINAPI *OPENTHEMEDATA)(HWND, LPCWSTR); +OPENTHEMEDATA s_pOpenThemeData = NULL; + +// CloseThemeData +typedef HRESULT (WINAPI *CLOSETHEMEDATA)(HTHEME); +CLOSETHEMEDATA s_pCloseThemeData = NULL; + +// DrawThemeBackground +typedef HRESULT (WINAPI *DRAWTHEMEBACKGROUND)(HTHEME, HDC, int, int, LPCRECT, LPCRECT); +DRAWTHEMEBACKGROUND s_pDrawThemeBackground = NULL; + +// DrawThemeText +typedef HRESULT (WINAPI *DRAWTHEMETEXTEX)(HTHEME, HDC, int, int, LPCWSTR, int, DWORD, DWORD, LPCRECT); +DRAWTHEMETEXTEX s_pDrawThemeText = NULL; + +static BOOL OpenTheme(HWND hwnd) +{ + s_hinstTheme = LoadLibraryA("uxtheme.dll"); + if (s_hinstTheme == NULL) + return FALSE; + + s_pOpenThemeData = (OPENTHEMEDATA)GetProcAddress(s_hinstTheme, "OpenThemeData"); + s_pCloseThemeData = (CLOSETHEMEDATA)GetProcAddress(s_hinstTheme, "CloseThemeData"); + s_pDrawThemeBackground = (DRAWTHEMEBACKGROUND)GetProcAddress(s_hinstTheme, "DrawThemeBackground"); + s_pDrawThemeText = (DRAWTHEMETEXTEX)GetProcAddress(s_hinstTheme, "DrawThemeText"); + + if (s_pOpenThemeData == NULL || s_pCloseThemeData == NULL || + s_pDrawThemeBackground == NULL || s_pDrawThemeText == NULL) + { + return FALSE; + } + + s_hTheme = (*s_pOpenThemeData)(hwnd, L"Button"); + return s_hTheme != NULL; +} + +static void CloseTheme(void) +{ + if (s_hTheme) + { + (*s_pCloseThemeData)(s_hTheme); + s_hTheme = NULL; + + s_pOpenThemeData = NULL; + s_pCloseThemeData = NULL; + s_pDrawThemeBackground = NULL; + s_pDrawThemeText = NULL; + + FreeLibrary(s_hinstTheme); + s_hinstTheme = NULL; + } +} + static void load_config(void) { DWORD tmp; @@ -1237,22 +1295,56 @@ /* default state: unpushed & enabled */ dwStyle = 0; dwText = 0; - if ((dis->itemState & ODS_DISABLED)) - dwText = DSS_DISABLED; - if ((dis->itemState & ODS_SELECTED)) - dwStyle = DFCS_PUSHED; - DrawFrameControl(dis->hDC, &dis->rcItem, DFC_BUTTON, DFCS_BUTTONPUSH | dwStyle); - GetTextExtentPoint32(dis->hDC, text, len, &size); - dx = ((dis->rcItem.right-dis->rcItem.left) - size.cx) >> 1; - dy = ((dis->rcItem.bottom-dis->rcItem.top) - size.cy) >> 1; - if ((dwStyle & DFCS_PUSHED)) { - dx++; - dy++; + if (s_hTheme) + { + RECT rcItem = dis->rcItem; + DWORD dwTextFlags2 = 2; /* hack: colored text */ + + if (dis->itemState & ODS_SELECTED) + { + dwStyle |= CMDLGS_PRESSED; + dwText |= CMDLGS_PRESSED; + } + if (dis->itemState & ODS_DISABLED) + { + dwStyle |= CMDLGS_DISABLED; + dwTextFlags2 &= ~2; /* hack: colored text */ + dwTextFlags2 |= DTT_GRAYED; + } + + (*s_pDrawThemeBackground)(s_hTheme, dis->hDC, BP_PUSHBUTTON, dwStyle, &rcItem, NULL); + + if (dis->itemState & ODS_SELECTED) + { + OffsetRect(&rcItem, 1, 1); + } + + (*s_pDrawThemeText)(s_hTheme, dis->hDC, BP_PUSHBUTTON, dwText, text, len, + DT_SINGLELINE | DT_CENTER | DT_VCENTER, dwTextFlags2, + &rcItem); } - pt.x = dis->rcItem.left + dx; - pt.y = dis->rcItem.top + dy; - DrawState(dis->hDC, NULL, NULL, (LPARAM)text, 0, pt.x, pt.y, size.cx, size.cy, DST_TEXT | dwText); + else + { + if ((dis->itemState & ODS_SELECTED)) + dwStyle |= DFCS_PUSHED; + if ((dis->itemState & ODS_DISABLED)) + dwText |= DSS_DISABLED; + + DrawFrameControl(dis->hDC, &dis->rcItem, DFC_BUTTON, DFCS_BUTTONPUSH | dwStyle); + + GetTextExtentPoint32(dis->hDC, text, len, &size); + dx = ((dis->rcItem.right-dis->rcItem.left) - size.cx) >> 1; + dy = ((dis->rcItem.bottom-dis->rcItem.top) - size.cy) >> 1; + if (dis->itemState & ODS_SELECTED) + { + dx++; + dy++; + } + pt.x = dis->rcItem.left + dx; + pt.y = dis->rcItem.top + dy; + DrawState(dis->hDC, NULL, NULL, (LPARAM)text, 0, pt.x, pt.y, size.cx, size.cy, DST_TEXT | dwText); + } } return 1L; } @@ -1268,6 +1360,7 @@ return SubclassButtonProc(hWnd, wp, lp); case WM_INITDIALOG: + OpenTheme(hWnd); calc.hWnd=hWnd; #ifdef USE_KEYBOARD_HOOK @@ -1754,8 +1847,13 @@ #ifdef USE_KEYBOARD_HOOK UnhookWindowsHookEx(calc.hKeyboardHook); #endif + CloseTheme(); PostQuitMessage(0); return TRUE; + case WM_THEMECHANGED: + CloseTheme(); + OpenTheme(hWnd); + break; case WM_CONTEXTMENU: if ((HWND)wp != hWnd) handle_context_menu(hWnd, wp, lp); @@ -1784,6 +1882,8 @@ { MSG msg; DWORD dwLayout; + INITCOMMONCONTROLSEX iccx = { sizeof(iccx), ICC_WIN95_CLASSES }; + InitCommonControlsEx(&iccx); calc.hInstance = hInstance; Index: reactos/dll/win32/uxtheme/draw.c =================================================================== --- reactos/dll/win32/uxtheme/draw.c (revision 74958) +++ reactos/dll/win32/uxtheme/draw.c (working copy) @@ -2,6 +2,7 @@ * Win32 5.1 Theme drawing * * Copyright (C) 2003 Kevin Koltzau + * Copyright (C) 2017 Katayama Hirofumi MZ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -1410,7 +1411,10 @@ oldBkMode = SetBkMode(hdc, TRANSPARENT); - if(dwTextFlags2 & DTT_GRAYED) + /* hack for calc: calc needs colored text */ + if (dwTextFlags2 & 2) + textColor = GetTextColor(hdc); + else if (dwTextFlags2 & DTT_GRAYED) textColor = GetSysColor(COLOR_GRAYTEXT); else { if(FAILED(GetThemeColor(hTheme, iPartId, iStateId, TMT_TEXTCOLOR, &textColor)))