From 62bd2d4195ef50a5cbecb6bd92b46af29fa9aef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Tue, 27 Oct 2015 21:22:17 +0000 Subject: [PATCH] [MSCONFIG_NEW] Enable Win7-like theming when applicable. svn path=/trunk/; revision=69723 --- .../applications/msconfig_new/CMakeLists.txt | 1 + .../msconfig_new/comctl32ex/uxthemesupp.c | 84 +++++++++++++++++++ .../msconfig_new/comctl32ex/uxthemesupp.h | 48 +++++++++++ .../base/applications/msconfig_new/msconfig.c | 55 ------------ .../applications/msconfig_new/srvpage.cpp | 5 +- .../applications/msconfig_new/toolspage.cpp | 3 +- 6 files changed, 138 insertions(+), 58 deletions(-) create mode 100644 reactos/base/applications/msconfig_new/comctl32ex/uxthemesupp.c create mode 100644 reactos/base/applications/msconfig_new/comctl32ex/uxthemesupp.h diff --git a/reactos/base/applications/msconfig_new/CMakeLists.txt b/reactos/base/applications/msconfig_new/CMakeLists.txt index 6a11f88ee8a..a7998207f46 100644 --- a/reactos/base/applications/msconfig_new/CMakeLists.txt +++ b/reactos/base/applications/msconfig_new/CMakeLists.txt @@ -11,6 +11,7 @@ include_directories( list(APPEND C_SOURCE comctl32ex/listviewfuncs.c + comctl32ex/uxthemesupp.c fileextractdialog.c fileutils.c freeldrpage.c diff --git a/reactos/base/applications/msconfig_new/comctl32ex/uxthemesupp.c b/reactos/base/applications/msconfig_new/comctl32ex/uxthemesupp.c new file mode 100644 index 00000000000..b820732b602 --- /dev/null +++ b/reactos/base/applications/msconfig_new/comctl32ex/uxthemesupp.c @@ -0,0 +1,84 @@ +/* + * PROJECT: ReactOS Applications + * LICENSE: LGPL - See COPYING in the top level directory + * FILE: base/applications/msconfig_new/comctl32ex/uxthemesupp.c + * PURPOSE: UX Theming helpers. + * COPYRIGHT: Copyright 2015 Hermes BELUSCA - MAITO + */ + +#include "precomp.h" +#include "uxthemesupp.h" + +static HMODULE hUxTheme = NULL; + +static BOOL +InitUxTheme(VOID) +{ + static BOOL Initialized = FALSE; + + if (Initialized) return TRUE; + + hUxTheme = LoadLibraryW(L"uxtheme.dll"); + if (hUxTheme == NULL) return FALSE; + + Initialized = TRUE; + return TRUE; +} + +static VOID +CleanupUxTheme(VOID) +{ + FreeLibrary(hUxTheme); + hUxTheme = NULL; + // Initialized = FALSE; +} + + + +//////////////////////////////////////////////////////////////////////////////// +// Taken from WinSpy++ 1.7 +// http://www.catch22.net/software/winspy +// Copyright (c) 2002 by J Brown +// + +typedef HRESULT (WINAPI* ETDTProc)(HWND, DWORD); + +HRESULT +WINAPI +EnableThemeDialogTexture(_In_ HWND hwnd, + _In_ DWORD dwFlags) +{ + ETDTProc fnEnableThemeDialogTexture; + + if (!InitUxTheme()) + return HRESULT_FROM_WIN32(GetLastError()); + + fnEnableThemeDialogTexture = + (ETDTProc)GetProcAddress(hUxTheme, "EnableThemeDialogTexture"); + if (!fnEnableThemeDialogTexture) + return HRESULT_FROM_WIN32(GetLastError()); + + return fnEnableThemeDialogTexture(hwnd, dwFlags); +} + + +typedef HRESULT (WINAPI* SWTProc)(HWND, LPCWSTR, LPCWSTR); + +HRESULT +WINAPI +SetWindowTheme(_In_ HWND hwnd, + _In_ LPCWSTR pszSubAppName, + _In_ LPCWSTR pszSubIdList) +{ + SWTProc fnSetWindowTheme; + + if (!InitUxTheme()) + return HRESULT_FROM_WIN32(GetLastError()); + + fnSetWindowTheme = + (SWTProc)GetProcAddress(hUxTheme, "SetWindowTheme"); + if (!fnSetWindowTheme) + return HRESULT_FROM_WIN32(GetLastError()); + + return fnSetWindowTheme(hwnd, pszSubAppName, pszSubIdList); +} diff --git a/reactos/base/applications/msconfig_new/comctl32ex/uxthemesupp.h b/reactos/base/applications/msconfig_new/comctl32ex/uxthemesupp.h new file mode 100644 index 00000000000..e372e859bce --- /dev/null +++ b/reactos/base/applications/msconfig_new/comctl32ex/uxthemesupp.h @@ -0,0 +1,48 @@ +/* + * PROJECT: ReactOS Applications + * LICENSE: LGPL - See COPYING in the top level directory + * FILE: base/applications/msconfig_new/comctl32ex/uxthemesupp.c + * PURPOSE: UX Theming helpers. + * COPYRIGHT: Copyright 2015 Hermes BELUSCA - MAITO + */ + +#ifndef _UXTHEMESUPP_H_ +#define _UXTHEMESUPP_H_ + +#pragma once + +#if defined(_UXTHEME_H) || defined(_UXTHEME_H_) // First one is our headers from Wine/MinGW, second one is MS PSDK +#warning "PSDK header uxtheme.h is already included, you might think about using it instead!" +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +// +// Copied from uxtheme.h +// If you have this new header, then delete these and +// #include instead! +// + +#define ETDT_DISABLE 0x00000001 +#define ETDT_ENABLE 0x00000002 +#define ETDT_USETABTEXTURE 0x00000004 +#define ETDT_ENABLETAB (ETDT_ENABLE | ETDT_USETABTEXTURE) + +HRESULT +WINAPI +EnableThemeDialogTexture(_In_ HWND hwnd, + _In_ DWORD dwFlags); + +HRESULT +WINAPI +SetWindowTheme(_In_ HWND hwnd, + _In_ LPCWSTR pszSubAppName, + _In_ LPCWSTR pszSubIdList); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _UXTHEMESUPP_H_ diff --git a/reactos/base/applications/msconfig_new/msconfig.c b/reactos/base/applications/msconfig_new/msconfig.c index 83acfbf7e88..3b159add3dd 100644 --- a/reactos/base/applications/msconfig_new/msconfig.c +++ b/reactos/base/applications/msconfig_new/msconfig.c @@ -46,61 +46,6 @@ HICON hIcon = NULL; WNDPROC wpOrigEditProc = NULL; -//////////////////////////////////////////////////////////////////////////////// -// Taken from WinSpy++ 1.7 -// http://www.catch22.net/software/winspy -// Copyright (c) 2002 by J Brown -// - -// -// Copied from uxtheme.h -// If you have this new header, then delete these and -// #include instead! -// -#define ETDT_DISABLE 0x00000001 -#define ETDT_ENABLE 0x00000002 -#define ETDT_USETABTEXTURE 0x00000004 -#define ETDT_ENABLETAB (ETDT_ENABLE | ETDT_USETABTEXTURE) - -// -typedef HRESULT (WINAPI * ETDTProc) (HWND, DWORD); - -// -// Try to call EnableThemeDialogTexture, if uxtheme.dll is present -// -BOOL EnableDialogTheme(HWND hwnd) -{ - HMODULE hUXTheme; - ETDTProc fnEnableThemeDialogTexture; - - hUXTheme = LoadLibrary(_T("uxtheme.dll")); - - if(hUXTheme) - { - fnEnableThemeDialogTexture = - (ETDTProc)GetProcAddress(hUXTheme, "EnableThemeDialogTexture"); - - if(fnEnableThemeDialogTexture) - { - fnEnableThemeDialogTexture(hwnd, ETDT_ENABLETAB); - - FreeLibrary(hUXTheme); - return TRUE; - } - else - { - // Failed to locate API! - FreeLibrary(hUXTheme); - return FALSE; - } - } - else - { - // Not running under XP? Just fail gracefully - return FALSE; - } -} - /* About Box dialog */ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { diff --git a/reactos/base/applications/msconfig_new/srvpage.cpp b/reactos/base/applications/msconfig_new/srvpage.cpp index 9fa77b2b655..a88c8b2288b 100644 --- a/reactos/base/applications/msconfig_new/srvpage.cpp +++ b/reactos/base/applications/msconfig_new/srvpage.cpp @@ -10,10 +10,11 @@ #include "precomp.h" #include "utils.h" -#include "listviewfuncs.h" #include "regutils.h" #include "stringutils.h" // #include "CmdLineParser.h" +#include "listviewfuncs.h" +#include "uxthemesupp.h" #include @@ -666,7 +667,7 @@ ServicesPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) // DWORD dwStyle = ListView_GetExtendedListViewStyle(hServicesListCtrl); ListView_SetExtendedListViewStyle(hServicesListCtrl, dwStyle | LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES); - /** SetWindowTheme(hServicesListCtrl, _T("Explorer"), NULL); // TODO: activate this only if Windows >= XP **/ + SetWindowTheme(hServicesListCtrl, L"Explorer", NULL); // // Initialize the application page's controls. diff --git a/reactos/base/applications/msconfig_new/toolspage.cpp b/reactos/base/applications/msconfig_new/toolspage.cpp index 4cd571525a0..746be919acd 100644 --- a/reactos/base/applications/msconfig_new/toolspage.cpp +++ b/reactos/base/applications/msconfig_new/toolspage.cpp @@ -11,6 +11,7 @@ #include "xmldomparser.hpp" #include "utils.h" #include "listviewfuncs.h" +#include "uxthemesupp.h" static HWND hToolsPage = NULL; static HWND hToolsListCtrl = NULL; @@ -330,7 +331,7 @@ ToolsPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) // DWORD dwStyle = ListView_GetExtendedListViewStyle(hToolsListCtrl); ListView_SetExtendedListViewStyle(hToolsListCtrl, dwStyle | LVS_EX_FULLROWSELECT); - /** SetWindowTheme(hToolsListCtrl, _T("Explorer"), NULL); // TODO: activate this only if Windows >= XP **/ + SetWindowTheme(hToolsListCtrl, L"Explorer", NULL); // // Initialize the application page's controls.