diff --git a/README.md b/README.md index 63aefd5..8ea775d 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,13 @@ ![NT Style banner](/misc/banner.png) ## What is NT Style? -NT Style makes your computer look like it's straight out of 1993! Or atleast the titlebars and window borders. Stay tuned. +NT Style makes your computer look like it's straight out of 1993! Using the same method that Stardock's Windowblinds and Microsoft's UxTheme employ, every control and titlebar is turned into something straight from vintage Windows. ## What does it run on? -Support and compatibility is provided for all versions of Windows NT with kernel version 5.2 and newer. There are currently only compiles for IA-32 and AMD64. +Support and compatibility is provided for all versions of Windows NT with kernel version 5.2 and newer. There is currently only support for IA-32 and AMD64 releases. ## Where do I get it? -The [releases page](https://github.com/freedom7341/NTStyle/releases/latest) has the latest release of NT Style. +The [releases page](https://github.com/freedom7341/NTStyle/releases/latest) has the latest stable release of NT Style. Builds for every commit can be found in the artifacts of the GitHub actions run of said commit. ## How can I help? Submitting [issues](/issues) and reporting or commenting on bugs that you find is a massive help. The next level is to contribute and create a [pull request](/pulls). diff --git a/common/usrapihk.h b/common/usrapihk.h new file mode 100644 index 0000000..702325c --- /dev/null +++ b/common/usrapihk.h @@ -0,0 +1,80 @@ +/* * * * * * * *\ + USRAPIHK.H - + Copyright © 2024 Brady McDermott, Vortesys + DESCRIPTION - + User32 UserApiHook function prototypes. Info + and structures sourced primarily from the ReactOS + wiki, source code and Mozilla's bug tracker. + LICENSE INFORMATION - + MIT License, see LICENSE.txt in the root folder +\* * * * * * * */ + +/* Pragmas */ +#pragma once + +/* Includes */ +#include + +/* Definitions */ +#define WM_UAHINIT 0x0000031b +#define WM_UAHDRAWMENU 0x00000091 +#define WM_UAHDRAWITEM 0x00000092 // WM_DRAWITEM +#define WM_UAHINITMENU 0x00000093 +#define WM_UAHMEASUREITEM 0x00000094 // WM_MEASUREITEM +#define WM_UAHDRAWMENUNC 0x00000095 +#define WM_NCUAHDRAWCAPTION 0x000000AE +#define WM_NCUAHDRAWFRAME 0x000000AF +#define UAH_HOOK_MESSAGE(uahowp, msg) uahowp.MsgBitArray[msg/8] |= (1 << (msg % 8)); +#define UAH_IS_MESSAGE_HOOKED(uahowp, msg) (uahowp.MsgBitArray[msg/8] & (1 << (msg % 8))) +#define UAHOWP_MAX_SIZE WM_USER/8 + +/* Structures */ +typedef struct _USERAPIHOOKINFO +{ + LPCWSTR m_funname1; // Callback function + LPCWSTR m_dllname1; // DLL 1 + LPCWSTR m_funname2; // Callback function + LPCWSTR m_dllname2; // DLL 2 +} USERAPIHOOKINFO, * PUSERAPIHOOKINFO; + +typedef LRESULT(CALLBACK* WNDPROC_OWP)(HWND, UINT, WPARAM, LPARAM, ULONG_PTR, PDWORD); + +typedef struct _UAHOWP +{ + BYTE* MsgBitArray; + DWORD Size; +} UAHOWP, * PUAHOWP; + +typedef struct tagUSERAPIHOOK +{ + DWORD size; + WNDPROC DefWindowProcA; + WNDPROC DefWindowProcW; + UAHOWP DefWndProcArray; + FARPROC GetScrollInfo; + FARPROC SetScrollInfo; + FARPROC EnableScrollBar; + FARPROC AdjustWindowRectEx; + FARPROC SetWindowRgn; + WNDPROC_OWP PreWndProc; + WNDPROC_OWP PostWndProc; + UAHOWP WndProcArray; + WNDPROC_OWP PreDefDlgProc; + WNDPROC_OWP PostDefDlgProc; + UAHOWP DlgProcArray; + FARPROC GetSystemMetrics; + FARPROC SystemParametersInfoA; + FARPROC SystemParametersInfoW; + FARPROC ForceResetUserApiHook; + FARPROC DrawFrameControl; + FARPROC DrawCaption; + FARPROC MDIRedrawFrame; + FARPROC GetRealWindowOwner; +} USERAPIHOOK, * PUSERAPIHOOK; + +typedef enum _UAPIHK +{ + uahLoadInit, + uahStop, + uahShutdown +} UAPIHK, * PUAPIHK; diff --git a/srchook/version.inc b/common/version.inc similarity index 71% rename from srchook/version.inc rename to common/version.inc index 2540d50..f2540d7 100644 Binary files a/srchook/version.inc and b/common/version.inc differ diff --git a/misc/banner.png b/misc/banner.png index 0b3dbc0..b994f51 100644 Binary files a/misc/banner.png and b/misc/banner.png differ diff --git a/misc/mock.png b/misc/mock.png deleted file mode 100644 index ea4d5b2..0000000 Binary files a/misc/mock.png and /dev/null differ diff --git a/misc/mock2.png b/misc/mock2.png deleted file mode 100644 index f7cd4d0..0000000 Binary files a/misc/mock2.png and /dev/null differ diff --git a/src/dlgproc.c b/src/dlgproc.c index 5d60137..bd59b92 100644 --- a/src/dlgproc.c +++ b/src/dlgproc.c @@ -5,7 +5,7 @@ NT Style's primary dialog procedures. LICENSE INFORMATION - MIT License, see LICENSE.txt in the root folder - \* * * * * * * */ +\* * * * * * * */ /* Headers */ #include "ntstyle.h" @@ -17,10 +17,10 @@ /* Functions */ /* * * *\ - NTStyleDialogProc - + NtStyleDialogProc - NT Style's dialog procedure. \* * * */ -INT_PTR CALLBACK NTStyleDialogProc( +INT_PTR CALLBACK NtStyleDialogProc( _In_ HWND hDlg, _In_ UINT uMsg, _In_ WPARAM wParam, @@ -41,44 +41,34 @@ INT_PTR CALLBACK NTStyleDialogProc( case IDC_START: { - DWORD dwLastError = 0; - - if (g_bSystem64) - dwLastError = NTStyleCreateHook(g_hAppInstance, L"ntshk64.dll", - (Button_GetCheck(GetDlgItem(hDlg, IDC_THEMEOFF)) == BST_CHECKED), g_hhkNTShk64); - - // load that 32 bit ish - dwLastError = NTStyleCreateHook(g_hAppInstance, L"ntshk32.dll", - (Button_GetCheck(GetDlgItem(hDlg, IDC_THEMEOFF)) == BST_CHECKED), g_hhkNTShk32); + if (NtStyleToggleHook(TRUE)) + { + MessageBox(hDlg, L"Started NT Style.", L"NT Style", + MB_OK | MB_ICONINFORMATION | MB_DEFAULT_DESKTOP_ONLY); - if (g_hhkNTShk32 || g_hhkNTShk64) + Button_Enable(GetDlgItem(hDlg, IDC_START), FALSE); + Button_Enable(GetDlgItem(hDlg, IDC_STOP), TRUE); + } + else { - // Start NT Style - if (!g_hhkNTShk32) - MessageBox(hDlg, L"Started NT Style.", L"NT Style (AMD64)", - MB_OK | MB_ICONINFORMATION | MB_DEFAULT_DESKTOP_ONLY); - else if (!g_hhkNTShk64) - MessageBox(hDlg, L"Started NT Style.", L"NT Style (IA32)", - MB_OK | MB_ICONINFORMATION | MB_DEFAULT_DESKTOP_ONLY); - else - MessageBox(hDlg, L"Started NT Style.", L"NT Style (AMD64 + WOW)", - MB_OK | MB_ICONINFORMATION | MB_DEFAULT_DESKTOP_ONLY); + MessageBox(hDlg, L"Failed to start NT Style.", L"NT Style", + MB_OK | MB_ICONINFORMATION | MB_DEFAULT_DESKTOP_ONLY); } - Button_Enable(GetDlgItem(hDlg, IDC_START), FALSE); - Button_Enable(GetDlgItem(hDlg, IDC_STOP), TRUE); - return 0; } case IDC_STOP: - if (g_hhkNTShk32) - UnhookWindowsHookEx(g_hhkNTShk32); - if (g_hhkNTShk64) - UnhookWindowsHookEx(g_hhkNTShk64); - - Button_Enable(GetDlgItem(hDlg, IDC_START), TRUE); - Button_Enable(GetDlgItem(hDlg, IDC_STOP), FALSE); + if (NtStyleToggleHook(FALSE)) + { + Button_Enable(GetDlgItem(hDlg, IDC_START), FALSE); + Button_Enable(GetDlgItem(hDlg, IDC_STOP), TRUE); + } + else + { + MessageBox(hDlg, L"Failed to stop NT Style.", L"NT Style", + MB_OK | MB_ICONINFORMATION | MB_DEFAULT_DESKTOP_ONLY); + } return 0; } diff --git a/src/ntstyle.c b/src/ntstyle.c index 02aa791..ff03b78 100644 --- a/src/ntstyle.c +++ b/src/ntstyle.c @@ -10,10 +10,12 @@ /* Headers */ #include "ntstyle.h" #include "resource.h" +#include "..\common\usrapihk.h" #define WIN32_LEAN_AND_MEAN #include #include +/* Variables */ // Handles HINSTANCE g_hAppInstance; HHOOK g_hhkNTShk32 = NULL; @@ -21,7 +23,7 @@ HHOOK g_hhkNTShk64 = NULL; // Strings WCHAR g_szAppTitle[64]; // Other -BOOL g_bSystem64 = TRUE; +BOOL g_bSystem64 = TRUE; /* Functions */ @@ -45,7 +47,7 @@ int WINAPI wWinMain( // Create our main window dialog InitCommonControls(); - hDlg = CreateDialogParam(g_hAppInstance, MAKEINTRESOURCE(IDD_MAIN), 0, NTStyleDialogProc, 0); + hDlg = CreateDialogParam(g_hAppInstance, MAKEINTRESOURCE(IDD_MAIN), 0, NtStyleDialogProc, 0); ShowWindow(hDlg, nCmdShow); // Get some system information to determine what @@ -68,59 +70,45 @@ int WINAPI wWinMain( } /* * * *\ - NTStyleCreateHook - - NT Style's hook creation function. + NtStyleToggleHook - + NT Style's hook creation and removal function. \* * * */ -DWORD NTStyleCreateHook( - _In_ HINSTANCE hInst, - _In_ LPWSTR lpNTStyleHook, - _In_ BOOL bDisableTheming, - _Out_ HHOOK hhkNTShk -) +BOOL NtStyleToggleHook(BOOL bInstall) { - HINSTANCE hDllInstance = NULL; - HOOKPROC hkprc = NULL; - DWORD dwLastError = 0; - - hhkNTShk = NULL; + HMODULE hLib = LoadLibrary(L"ntshk64.dll"); + BOOL bRet = 0; - // Load the hook DLL - hDllInstance = LoadLibrary(lpNTStyleHook); + if (hLib) + { + FARPROC fLib; - // Get the hook procedure of NTShook - if (hDllInstance) - hkprc = (HOOKPROC)GetProcAddress(hDllInstance, "NTStyleHookProc"); - else - dwLastError = GetLastError(); + if (bInstall) + fLib = GetProcAddress(hLib, "NtStyleInstallUserHook"); + else + fLib = GetProcAddress(hLib, "NtStyleRemoveUserHook"); - // Establish our hook - if (hkprc) - hhkNTShk = SetWindowsHookEx(WH_CALLWNDPROC, hkprc, hDllInstance, 0); - else - dwLastError = GetLastError(); + bRet = (BOOL)fLib(); - // Enumerate the existing windows and get them dwm-free :fire: - if (bDisableTheming) - EnumWindows(&NTStyleEnumWindowProc, (LPARAM)hDllInstance); + FreeLibrary(hLib); - if (hDllInstance) - FreeLibrary(hDllInstance); + return bRet; + } - return dwLastError; + return FALSE; } /* * * *\ - NTStyleEnumWindowProc - + NtStyleEnumWindowProc - NT Style's window enumeration procedure. \* * * */ -BOOL CALLBACK NTStyleEnumWindowProc( +BOOL CALLBACK NtStyleEnumWindowProc( _In_ HWND hwnd, _In_ LPARAM lParam ) { if ((HMODULE)lParam != NULL) { - FARPROC fLib = GetProcAddress((HMODULE)lParam, "NTStyleDisableWindowTheme"); + FARPROC fLib = GetProcAddress((HMODULE)lParam, "NtStyleDisableWindowTheme"); fLib(hwnd); return TRUE; diff --git a/src/ntstyle.h b/src/ntstyle.h index bd28360..05c1565 100644 --- a/src/ntstyle.h +++ b/src/ntstyle.h @@ -26,7 +26,8 @@ extern BOOL g_bSystem64; /* Function Prototypes */ // NTSTYLE.C -BOOL CALLBACK NTStyleEnumWindowProc(_In_ HWND hwnd, _In_ LPARAM lParam); -DWORD NTStyleCreateHook(_In_ HINSTANCE hInst, _In_ LPWSTR lpNTStyleHook, _In_ BOOL bDisableTheming, _Out_ HHOOK hhkNTShk); +BOOL CALLBACK NtStyleEnumWindowProc(_In_ HWND hwnd, _In_ LPARAM lParam); +BOOL NtStyleToggleHook(BOOL bInstall); + // DLGPROC.C -INT_PTR CALLBACK NTStyleDialogProc(_In_ HWND hDlg, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam); +INT_PTR CALLBACK NtStyleDialogProc(_In_ HWND hDlg, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam); diff --git a/src/ntstyle.vcxproj b/src/ntstyle.vcxproj index a785950..f6c2732 100644 --- a/src/ntstyle.vcxproj +++ b/src/ntstyle.vcxproj @@ -168,6 +168,7 @@ + @@ -177,10 +178,10 @@ - + - + diff --git a/src/ntstyle.vcxproj.filters b/src/ntstyle.vcxproj.filters index bf6d927..7c14321 100644 --- a/src/ntstyle.vcxproj.filters +++ b/src/ntstyle.vcxproj.filters @@ -16,6 +16,9 @@ {d681401a-a069-441c-82e8-4bba44ebd993} + + {5de2b196-5c95-4426-b53a-6e9402331a6b} + @@ -32,6 +35,9 @@ Header Files + + Common Files + @@ -45,13 +51,13 @@ - + Resource Files - + - - Source Files - + + Common Files + \ No newline at end of file diff --git a/src/resource.rc b/src/resource.rc index ff2d190..f53a61f 100644 --- a/src/resource.rc +++ b/src/resource.rc @@ -1,5 +1,5 @@ /* * * * * * * *\ - NTSTYLE.C - + RESOURCE.RC - Copyright © 2024 Brady McDermott, Vortesys DESCRIPTION - This file contains NT Style's resources. @@ -24,7 +24,11 @@ IDI_MAIN ICON icons\ntstyle.ico /* Version Information */ #define APSTUDIO_HIDDEN_SYMBOLS -#include "version.inc" +#define VER_FILEDESCRIPTION_STR "NT Style theming utility for Windows." +#define VER_INTERNALNAME_STR "ntstyle\0" +#define VER_ORIGINALFILENAME_STR "NTSTYLE.EXE" +#define VER_PRODUCTNAME_STR "NT Style" +#include "..\common\version.inc" #undef APSTUDIO_HIDDEN_SYMBOLS VS_VERSION_INFO VERSIONINFO diff --git a/src/version.inc b/src/version.inc deleted file mode 100644 index efe56aa..0000000 Binary files a/src/version.inc and /dev/null differ diff --git a/srchook/ntsdlfn.c b/srchook/delayfnc.c similarity index 69% rename from srchook/ntsdlfn.c rename to srchook/delayfnc.c index 8d12a6c..e832e3c 100644 --- a/srchook/ntsdlfn.c +++ b/srchook/delayfnc.c @@ -1,22 +1,20 @@ /* * * * * * * *\ - NTSDLFN.C - + DELAYFNC.C - Copyright © 2024 Brady McDermott, Vortesys DESCRIPTION - Delay loaded functions, mostly for only testing and disabling DWM on systems newer than Windows - Vista. + Vista. Also contains the RegisterUserApiHook. LICENSE INFORMATION - MIT License, see LICENSE.txt in the root folder - \* * * * * * * */ +\* * * * * * * */ /* Headers */ #include "ntshook.h" +#include "..\common\usrapihk.h" #define WIN32_LEAN_AND_MEAN #include -/* Definitions */ -#define STATUS_UNSUCCESSFUL 0xC0000001 - /* Functions */ /* * * *\ @@ -116,3 +114,54 @@ HRESULT SetWindowThemeDelay( return STATUS_UNSUCCESSFUL; } + +/* * * *\ + RegisterUserApiHook - + Registers a DLL and its initialization function + to User32 for theming controls. + RETURNS - + TRUE if successful. +\* * * */ +BOOL WINAPI RegisterUserApiHook(PUSERAPIHOOKINFO ApiHookInfo) +{ + HMODULE hLib = LoadLibrary(L"user32.dll"); + BOOL bRet = 0; + + if (hLib) + { + FARPROC fLib = GetProcAddress(hLib, "RegisterUserApiHook"); + + bRet = (BOOL)fLib(ApiHookInfo); + + FreeLibrary(hLib); + + return bRet; + } + + return FALSE; +} + +/* * * *\ + UnregisterUserApiHook - + Unregisters a DLL from User32. + RETURNS - + TRUE if successful. +\* * * */ +BOOL WINAPI UnregisterUserApiHook(VOID) +{ + HMODULE hLib = LoadLibrary(L"user32.dll"); + BOOL bRet = 0; + + if (hLib) + { + FARPROC fLib = GetProcAddress(hLib, "UnregisterUserApiHook"); + + bRet = (BOOL)fLib(); + + FreeLibrary(hLib); + + return bRet; + } + + return FALSE; +} diff --git a/srchook/ntsdrfn.c b/srchook/draw.c similarity index 99% rename from srchook/ntsdrfn.c rename to srchook/draw.c index 92d22ee..534c47a 100644 --- a/srchook/ntsdrfn.c +++ b/srchook/draw.c @@ -1,15 +1,15 @@ /* * * * * * * *\ - NTSDRFN.C - + DRAW.C - Copyright © 2024 Brady McDermott, Vortesys DESCRIPTION - NT Style's drawing functions. LICENSE INFORMATION - MIT License, see LICENSE.txt in the root folder - \* * * * * * * */ +\* * * * * * * */ /* Headers */ #include "ntshook.h" -#include "ntsdrfn.h" +#include "draw.h" #include "oebitmap.h" #include diff --git a/srchook/ntsdrfn.h b/srchook/draw.h similarity index 99% rename from srchook/ntsdrfn.h rename to srchook/draw.h index a5a925a..b2047e9 100644 --- a/srchook/ntsdrfn.h +++ b/srchook/draw.h @@ -1,5 +1,5 @@ /* * * * * * * *\ - NTSDRFN.H - + DRAW.H - Copyright © 2024 Brady McDermott, Vortesys DESCRIPTION - NT Style's drawing functions. diff --git a/srchook/images/g96max.bmp b/srchook/images/g96max.bmp new file mode 100644 index 0000000..72bb0ae Binary files /dev/null and b/srchook/images/g96max.bmp differ diff --git a/srchook/images/g96menu.bmp b/srchook/images/g96menu.bmp new file mode 100644 index 0000000..f84c93b Binary files /dev/null and b/srchook/images/g96menu.bmp differ diff --git a/srchook/images/g96min.bmp b/srchook/images/g96min.bmp new file mode 100644 index 0000000..062e5c9 Binary files /dev/null and b/srchook/images/g96min.bmp differ diff --git a/srchook/images/g96mmenu.bmp b/srchook/images/g96mmenu.bmp new file mode 100644 index 0000000..2f34eb3 Binary files /dev/null and b/srchook/images/g96mmenu.bmp differ diff --git a/srchook/images/g96res.bmp b/srchook/images/g96res.bmp new file mode 100644 index 0000000..1bf079e Binary files /dev/null and b/srchook/images/g96res.bmp differ diff --git a/srchook/images/max.bmp b/srchook/images/max.bmp index e31080a..0ead5e0 100644 Binary files a/srchook/images/max.bmp and b/srchook/images/max.bmp differ diff --git a/srchook/images/maxd.bmp b/srchook/images/maxd.bmp index b8e758d..94ffef0 100644 Binary files a/srchook/images/maxd.bmp and b/srchook/images/maxd.bmp differ diff --git a/srchook/images/min.bmp b/srchook/images/min.bmp index 81d90fd..062e5c9 100644 Binary files a/srchook/images/min.bmp and b/srchook/images/min.bmp differ diff --git a/srchook/images/mind.bmp b/srchook/images/mind.bmp index 99fdea9..fe0812b 100644 Binary files a/srchook/images/mind.bmp and b/srchook/images/mind.bmp differ diff --git a/srchook/images/mock.bmp b/srchook/images/mock.bmp new file mode 100644 index 0000000..9a80216 Binary files /dev/null and b/srchook/images/mock.bmp differ diff --git a/srchook/images/res.bmp b/srchook/images/res.bmp index 972c9b6..1bf079e 100644 Binary files a/srchook/images/res.bmp and b/srchook/images/res.bmp differ diff --git a/srchook/images/resd.bmp b/srchook/images/resd.bmp index af812f6..ffc2792 100644 Binary files a/srchook/images/resd.bmp and b/srchook/images/resd.bmp differ diff --git a/srchook/ntshook.c b/srchook/ntshook.c index b519776..c21b536 100644 --- a/srchook/ntshook.c +++ b/srchook/ntshook.c @@ -3,24 +3,27 @@ Copyright © 2024 Brady McDermott, Vortesys DESCRIPTION - Defines the entry point for the DLL application. + User hook functions are modeled after the ReactOS + implementation of UxTheme. LICENSE INFORMATION - MIT License, see LICENSE.txt in the root folder - \* * * * * * * */ +\* * * * * * * */ /* Headers */ #include "ntshook.h" -#include "ntsdrfn.h" +#include "draw.h" +#include "..\common\usrapihk.h" #include "resource.h" #include #include #include /* Global Variables */ -static INT g_iSystemHasDWM = 2; -static INT g_iLockUpdateCount; - -// Handles -HINSTANCE g_hDllInstance; +USERAPIHOOK g_user32ApiHook; +BYTE gabDWPmessages[UAHOWP_MAX_SIZE]; +BYTE gabMSGPmessages[UAHOWP_MAX_SIZE]; +BYTE gabDLGPmessages[UAHOWP_MAX_SIZE]; +BOOL g_bThemeHooksActive = FALSE; /* * * *\ DllMain - @@ -44,87 +47,10 @@ BOOL APIENTRY DllMain( } /* * * *\ - NTStyleHookProc - - NT Style Hook procedure - Uses WH_CALLWNDPROC. -\* * * */ -__declspec(dllexport) LRESULT APIENTRY NTStyleHookProc( - _In_ UINT uMsg, - _In_ WPARAM wParam, - _In_ LPARAM lParam -) -{ - PCWPSTRUCT pcwps; - - // Switch case for window painting - switch (uMsg) - { - /* BEGIN HC_ACTION */ - case HC_ACTION: - pcwps = (CWPSTRUCT*)lParam; - - switch (pcwps->message) - { - // Drawing Messages - case WM_CREATE: - NTStyleDisableWindowTheme(pcwps->hwnd); - case WM_DISPLAYCHANGE: - case WM_SYNCPAINT: - case WM_ACTIVATE: - case WM_SETTEXT: - case WM_PAINT: - case WM_MOVE: - NTStyleDrawWindow(pcwps->hwnd, pcwps->wParam, pcwps->lParam); - break; - - case WM_NCACTIVATE: - case WM_NCCALCSIZE: - case WM_NCPAINT: - NTStyleDrawWindow(pcwps->hwnd, pcwps->wParam, pcwps->lParam); - return 0; - - // Collision Messages - /* - case WM_NCLBUTTONUP: - break; - - case WM_NCLBUTTONDBLCLK: - break; - - case WM_NCRBUTTONUP: - break; - - case WM_NCHITTEST: - break;*/ - - default: - break; - } - /* END HC_ACTION */ - - default: - break; - } - - return CallNextHookEx(NULL, uMsg, wParam, lParam); -} - -/* * * *\ - NTStyleSetHook - - NT Style Hook hook so - that we can actually - WOW these programs. -\* * * */ -__declspec(dllexport) HHOOK APIENTRY NTStyleSetHook(_In_ INT idHook, _In_ HOOKPROC lpfn, _In_ HINSTANCE hmod, _In_ DWORD dwThreadId) -{ - return SetWindowsHookEx(idHook, lpfn, hmod, dwThreadId); -} - -/* * * *\ - NTStyleDisableWindowTheme - + NtStyleDisableWindowTheme - de-themify that window \* * * */ -__declspec(dllexport) VOID APIENTRY NTStyleDisableWindowTheme(_In_ HWND hWnd) +__declspec(dllexport) VOID APIENTRY NtStyleDisableWindowTheme(_In_ HWND hWnd) { enum DWMNCRENDERINGPOLICY ncrp = DWMNCRP_DISABLED; @@ -158,3 +84,272 @@ __declspec(dllexport) VOID APIENTRY NTStyleDisableWindowTheme(_In_ HWND hWnd) return; } + +/* * * *\ + NtStyleInstallUserHook - + Load the User32 API hook. +\* * * */ +__declspec(dllexport) BOOL CALLBACK NtStyleInstallUserHook() +{ + USERAPIHOOKINFO uah; + + uah.m_funname1 = L"NtStyleInitUserHook"; + uah.m_dllname1 = L"ntshk64.dll"; + uah.m_funname2 = L"NtStyleInitUserHook"; + uah.m_dllname2 = L"ntshk64.dll"; + + return RegisterUserApiHook(&uah); +} + +/* * * *\ + NtStyleInitUserHook - + Initialize the User32 API hook. +\* * * */ +__declspec(dllexport) BOOL CALLBACK NtStyleInitUserHook(UAPIHK State, PUSERAPIHOOK puah) +{ + // Don't initialize if the state isn't appropriate. + if (!puah || State != uahLoadInit) + { + g_bThemeHooksActive = FALSE; + return TRUE; + } + + /* Store the original functions from user32 */ + g_user32ApiHook = *puah; + + puah->DefWindowProcA = NtStyleDefWindowProcA; + puah->DefWindowProcW = NtStyleDefWindowProcW; + puah->PreWndProc = NtStylePreWindowProc; + puah->PostWndProc = NtStylePostWindowProc; + puah->PreDefDlgProc = NtStyleDlgPreWindowProc; + puah->PostDefDlgProc = NtStyleDlgPostWindowProc; + puah->DefWndProcArray.MsgBitArray = gabDWPmessages; + puah->DefWndProcArray.Size = UAHOWP_MAX_SIZE; + puah->WndProcArray.MsgBitArray = gabMSGPmessages; + puah->WndProcArray.Size = UAHOWP_MAX_SIZE; + puah->DlgProcArray.MsgBitArray = gabDLGPmessages; + puah->DlgProcArray.Size = UAHOWP_MAX_SIZE; + + puah->SetWindowRgn = NtStyleSetWindowRgn; + puah->GetScrollInfo = NtStyleGetScrollInfo; + puah->SetScrollInfo = NtStyleSetScrollInfo; + + UAH_HOOK_MESSAGE(puah->DefWndProcArray, WM_NCPAINT); + UAH_HOOK_MESSAGE(puah->DefWndProcArray, WM_NCACTIVATE); + UAH_HOOK_MESSAGE(puah->DefWndProcArray, WM_NCMOUSEMOVE); + UAH_HOOK_MESSAGE(puah->DefWndProcArray, WM_NCMOUSELEAVE); + UAH_HOOK_MESSAGE(puah->DefWndProcArray, WM_NCHITTEST); + UAH_HOOK_MESSAGE(puah->DefWndProcArray, WM_NCLBUTTONDOWN); + UAH_HOOK_MESSAGE(puah->DefWndProcArray, WM_NCUAHDRAWCAPTION); + UAH_HOOK_MESSAGE(puah->DefWndProcArray, WM_NCUAHDRAWFRAME); + UAH_HOOK_MESSAGE(puah->DefWndProcArray, WM_SETTEXT); + UAH_HOOK_MESSAGE(puah->DefWndProcArray, WM_WINDOWPOSCHANGED); + UAH_HOOK_MESSAGE(puah->DefWndProcArray, WM_CONTEXTMENU); + UAH_HOOK_MESSAGE(puah->DefWndProcArray, WM_STYLECHANGED); + UAH_HOOK_MESSAGE(puah->DefWndProcArray, WM_SETICON); + UAH_HOOK_MESSAGE(puah->DefWndProcArray, WM_NCDESTROY); + UAH_HOOK_MESSAGE(puah->DefWndProcArray, WM_SYSCOMMAND); + UAH_HOOK_MESSAGE(puah->DefWndProcArray, WM_CTLCOLORMSGBOX); + UAH_HOOK_MESSAGE(puah->DefWndProcArray, WM_CTLCOLORBTN); + UAH_HOOK_MESSAGE(puah->DefWndProcArray, WM_CTLCOLORSTATIC); + + UAH_HOOK_MESSAGE(puah->WndProcArray, WM_CREATE); + UAH_HOOK_MESSAGE(puah->WndProcArray, WM_SETTINGCHANGE); + UAH_HOOK_MESSAGE(puah->WndProcArray, WM_DRAWITEM); + UAH_HOOK_MESSAGE(puah->WndProcArray, WM_MEASUREITEM); + UAH_HOOK_MESSAGE(puah->WndProcArray, WM_WINDOWPOSCHANGING); + UAH_HOOK_MESSAGE(puah->WndProcArray, WM_WINDOWPOSCHANGED); + UAH_HOOK_MESSAGE(puah->WndProcArray, WM_STYLECHANGING); + UAH_HOOK_MESSAGE(puah->WndProcArray, WM_STYLECHANGED); + UAH_HOOK_MESSAGE(puah->WndProcArray, WM_NCCREATE); + UAH_HOOK_MESSAGE(puah->WndProcArray, WM_NCDESTROY); + UAH_HOOK_MESSAGE(puah->WndProcArray, WM_NCPAINT); + UAH_HOOK_MESSAGE(puah->WndProcArray, WM_MENUCHAR); + UAH_HOOK_MESSAGE(puah->WndProcArray, WM_MDISETMENU); + UAH_HOOK_MESSAGE(puah->WndProcArray, WM_THEMECHANGED); + UAH_HOOK_MESSAGE(puah->WndProcArray, WM_UAHINIT); + + puah->DlgProcArray.MsgBitArray = gabDLGPmessages; + puah->DlgProcArray.Size = UAHOWP_MAX_SIZE; + + UAH_HOOK_MESSAGE(puah->DlgProcArray, WM_INITDIALOG); + UAH_HOOK_MESSAGE(puah->DlgProcArray, WM_CTLCOLORMSGBOX); + UAH_HOOK_MESSAGE(puah->DlgProcArray, WM_CTLCOLORBTN); + UAH_HOOK_MESSAGE(puah->DlgProcArray, WM_CTLCOLORDLG); + UAH_HOOK_MESSAGE(puah->DlgProcArray, WM_CTLCOLORSTATIC); + UAH_HOOK_MESSAGE(puah->DlgProcArray, WM_PRINTCLIENT); + + return TRUE; +} + +/* * * *\ + NtStyleRemoveUserHook - + Initialize the User32 API hook. +\* * * */ +__declspec(dllexport) BOOL CALLBACK NtStyleRemoveUserHook() +{ + return UnregisterUserApiHook(); +} + +/* * * *\ + NtStyleDefWindowProcA - + User32 stub. +\* * * */ +static LRESULT CALLBACK NtStyleDefWindowProcA( + _In_ HWND hWnd, + _In_ UINT Msg, + _In_ WPARAM wParam, + _In_ LPARAM lParam) +{ + return NtStyleWndProc(hWnd, Msg, wParam, lParam, g_user32ApiHook.DefWindowProcA); +} + +/* * * *\ + NtStyleDefWindowProcW - + User32 stub. +\* * * */ +static LRESULT CALLBACK NtStyleDefWindowProcW( + _In_ HWND hWnd, + _In_ UINT Msg, + _In_ WPARAM wParam, + _In_ LPARAM lParam) +{ + return NtStyleWndProc(hWnd, Msg, wParam, lParam, g_user32ApiHook.DefWindowProcW); +} + +/* * * *\ + NtStylePreWindowProc - + User32 stub. +\* * * */ +static LRESULT CALLBACK NtStylePreWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam, ULONG_PTR ret, PDWORD unknown) +{ + // TODO: SET/CHECK/MODIFY WINDOW REGION - ELIMINATE UGLY BASIC CORNERS!!! + switch (Msg) + { + case WM_CREATE: + NtStyleDisableWindowTheme(hWnd); + break; + } + + return 0; +} + +/* * * *\ + NtStylePostWindowProc - + User32 stub. +\* * * */ +static LRESULT CALLBACK NtStylePostWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam, ULONG_PTR ret, PDWORD unknown) +{ + return 0; +} + +/* * * *\ + NtStyleDlgPreWindowProc - + User32 stub. +\* * * */ +static LRESULT CALLBACK NtStyleDlgPreWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam, ULONG_PTR ret, PDWORD unknown) +{ + return 0; +} + +/* * * *\ + NtStyleDlgPostWindowProc - + User32 stub. +\* * * */ +static LRESULT CALLBACK NtStyleDlgPostWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam, ULONG_PTR ret, PDWORD unknown) +{ + return 0; +} + +/* * * *\ + NtStyleSetWindowRgn - + User32 stub. +\* * * */ +static LRESULT CALLBACK NtStyleSetWindowRgn(HWND hWnd, HRGN hRgn, BOOL bRedraw) +{ + return g_user32ApiHook.SetWindowRgn(hWnd, hRgn, bRedraw); +} + +/* * * *\ + NtStyleGetScrollInfo - + User32 stub. +\* * * */ +static LRESULT CALLBACK NtStyleGetScrollInfo(HWND hwnd, int fnBar, LPSCROLLINFO lpsi) +{ + // ReactOS UxTheme tracks the scrollbar itself - if we change the metrics of + // anything then we're going to have to change some stuff up here. + return g_user32ApiHook.GetScrollInfo(hwnd, fnBar, lpsi); +} + +/* * * *\ + NtStyleSetScrollInfo - + User32 stub. +\* * * */ +static LRESULT CALLBACK NtStyleSetScrollInfo(HWND hWnd, int fnBar, LPCSCROLLINFO lpsi, BOOL bRedraw) +{ + return g_user32ApiHook.SetScrollInfo(hWnd, fnBar, lpsi, bRedraw); +} + +/* * * *\ + NtStyleWndProc - + NT Style's Window Procedure functions. +\* * * */ +LRESULT CALLBACK NtStyleWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam, WNDPROC DefWndProc) +{ + switch (Msg) + { + case WM_NCPAINT: + // + // WM_NCUAHDRAWCAPTION : wParam are DC_* flags. + // + case WM_NCUAHDRAWCAPTION: + // + // WM_NCUAHDRAWFRAME : wParam is HDC, lParam are DC_ACTIVE and or DC_REDRAWHUNGWND. + // + case WM_NCUAHDRAWFRAME: + case WM_NCACTIVATE: + //if ((GetWindowLongW(hWnd, GWL_STYLE) & WS_CAPTION) != WS_CAPTION) + //return TRUE; + //return TRUE; + case WM_NCMOUSEMOVE: + case WM_NCMOUSELEAVE: + case WM_NCLBUTTONDOWN: + //switch (wParam) + //{ + //case HTMINBUTTON: + //case HTMAXBUTTON: + //case HTCLOSE: + //{ + //ThemeHandleButton(hWnd, wParam); + //return 0; + //} + //default: + //return DefWndProc(hWnd, Msg, wParam, lParam); + //} + //case WM_NCHITTEST: + //{ + //POINT Point; + //Point.x = GET_X_LPARAM(lParam); + //Point.y = GET_Y_LPARAM(lParam); + //return DefWndNCHitTest(hWnd, Point); + //} + case WM_SYSCOMMAND: + //{ + //if ((wParam & 0xfff0) == SC_VSCROLL || + //(wParam & 0xfff0) == SC_HSCROLL) + //{ + //POINT Pt; + //Pt.x = (short)LOWORD(lParam); + //Pt.y = (short)HIWORD(lParam); + //NC_TrackScrollBar(hWnd, wParam, Pt); + //return 0; + //} + //else + //{ + return DefWndProc(hWnd, Msg, wParam, lParam); + //} + //} + default: + return DefWndProc(hWnd, Msg, wParam, lParam); + } +} diff --git a/srchook/ntshook.def b/srchook/ntshook.def index babf377..1fba138 100644 --- a/srchook/ntshook.def +++ b/srchook/ntshook.def @@ -1,5 +1,6 @@ LIBRARY EXPORTS - NTStyleDisableWindowTheme @1 - NTStyleHookProc @2 - NTStyleSetHook @4 \ No newline at end of file + NtStyleDisableWindowTheme @1 + NtStyleInstallUserHook @2 + NtStyleInitUserHook @4 + NtStyleRemoveUserHook @8 \ No newline at end of file diff --git a/srchook/ntshook.h b/srchook/ntshook.h index 5967491..d60d722 100644 --- a/srchook/ntshook.h +++ b/srchook/ntshook.h @@ -15,18 +15,36 @@ /* Includes */ #include +#include "..\common\usrapihk.h" + +/* Definitions */ +#define STATUS_UNSUCCESSFUL 0xC0000001 /* Global Variables */ /* Function Prototypes */ -// Hook Procedure -__declspec(dllexport) LRESULT APIENTRY NTStyleHookProc(_In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam); -__declspec(dllexport) HHOOK APIENTRY NTStyleSetHook(_In_ INT idHook, _In_ HOOKPROC lpfn, _In_ HINSTANCE hmod, _In_ DWORD dwThreadId); +__declspec(dllexport) VOID APIENTRY NtStyleDisableWindowTheme(_In_ HWND hWnd); + +// Hook Functions +__declspec(dllexport) BOOL CALLBACK NtStyleInstallUserHook(); +__declspec(dllexport) BOOL CALLBACK NtStyleInitUserHook(UAPIHK State, PUSERAPIHOOK puah); +__declspec(dllexport) BOOL CALLBACK NtStyleRemoveUserHook(); -// Functions -__declspec(dllexport) VOID APIENTRY NTStyleDisableWindowTheme(_In_ HWND hWnd); +// Window Management +static LRESULT CALLBACK NtStyleDefWindowProcA(_In_ HWND hWnd, _In_ UINT Msg, _In_ WPARAM wParam, _In_ LPARAM lParam); +static LRESULT CALLBACK NtStyleDefWindowProcW(_In_ HWND hWnd, _In_ UINT Msg, _In_ WPARAM wParam, _In_ LPARAM lParam); +static LRESULT CALLBACK NtStylePreWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam, ULONG_PTR ret, PDWORD unknown); +static LRESULT CALLBACK NtStylePostWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam, ULONG_PTR ret, PDWORD unknown); +static LRESULT CALLBACK NtStyleDlgPreWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam, ULONG_PTR ret, PDWORD unknown); +static LRESULT CALLBACK NtStyleDlgPostWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam, ULONG_PTR ret, PDWORD unknown); +static LRESULT CALLBACK NtStyleSetWindowRgn(HWND hWnd, HRGN hRgn, BOOL bRedraw); +static LRESULT CALLBACK NtStyleGetScrollInfo(HWND hwnd, int fnBar, LPSCROLLINFO lpsi); +static LRESULT CALLBACK NtStyleSetScrollInfo(HWND hWnd, int fnBar, LPCSCROLLINFO lpsi, BOOL bRedraw); +LRESULT CALLBACK NtStyleWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam, WNDPROC DefWndProc); // Delay Load Functions HRESULT DwmGetWindowAttributeDelay(HWND hwnd, DWORD dwAttribute, _In_ LPCVOID pvAttribute, DWORD cbAttribute); HRESULT DwmSetWindowAttributeDelay(HWND hwnd, DWORD dwAttribute, _In_ LPCVOID pvAttribute, DWORD cbAttribute); HRESULT SetWindowThemeDelay(_In_ HWND hwnd, _In_ LPCWSTR pszSubAppName, _In_ LPCWSTR pszSubIdList); +BOOL WINAPI RegisterUserApiHook(PUSERAPIHOOKINFO ApiHookInfo); +BOOL WINAPI UnregisterUserApiHook(VOID); diff --git a/srchook/resource.rc b/srchook/resource.rc index 869006d..3b87a68 100644 --- a/srchook/resource.rc +++ b/srchook/resource.rc @@ -11,6 +11,7 @@ #define APSTUDIO_HIDDEN_SYMBOLS #include #include "resource.h" +#undef APSTUDIO_HIDDEN_SYMBOLS /* Bitmaps */ IDB_MAX BITMAP images\max.bmp @@ -22,7 +23,12 @@ IDB_RES_S BITMAP images\resd.bmp IDB_MENU BITMAP images\menu.bmp /* Version Information */ -#include "version.inc" +#define APSTUDIO_HIDDEN_SYMBOLS +#define VER_FILEDESCRIPTION_STR "NT Style Hook" +#define VER_INTERNALNAME_STR "ntshook\0" +#define VER_ORIGINALFILENAME_STR "NTSHOOK.DLL" +#define VER_PRODUCTNAME_STR "NT Style Hook" +#include "..\common\version.inc" #undef APSTUDIO_HIDDEN_SYMBOLS VS_VERSION_INFO VERSIONINFO diff --git a/srchook/srchook.vcxproj b/srchook/srchook.vcxproj index c7619c9..da6e9bf 100644 --- a/srchook/srchook.vcxproj +++ b/srchook/srchook.vcxproj @@ -196,14 +196,14 @@ - + - - + + @@ -211,7 +211,6 @@ - diff --git a/srchook/srchook.vcxproj.filters b/srchook/srchook.vcxproj.filters index 79e453e..3019ab1 100644 --- a/srchook/srchook.vcxproj.filters +++ b/srchook/srchook.vcxproj.filters @@ -27,7 +27,7 @@ Header Files - + Header Files @@ -35,10 +35,10 @@ Source Files - + Source Files - + Source Files @@ -48,9 +48,6 @@ - - Resource Files - Export Definitions