Skip to content

Commit

Permalink
Merge pull request #8 from Vortesys/userhook
Browse files Browse the repository at this point in the history
merge userhook since i'm going a different direction
  • Loading branch information
freedom7341 authored May 31, 2024
2 parents 5f2fd6d + 977dbee commit d41cbd4
Show file tree
Hide file tree
Showing 34 changed files with 534 additions and 199 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
80 changes: 80 additions & 0 deletions common/usrapihk.h
Original file line number Diff line number Diff line change
@@ -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 <wtypes.h>

/* 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;
Binary file renamed srchook/version.inc → common/version.inc
Binary file not shown.
Binary file modified misc/banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed misc/mock.png
Binary file not shown.
Binary file removed misc/mock2.png
Binary file not shown.
56 changes: 23 additions & 33 deletions src/dlgproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand All @@ -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;
}
Expand Down
60 changes: 24 additions & 36 deletions src/ntstyle.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@
/* Headers */
#include "ntstyle.h"
#include "resource.h"
#include "..\common\usrapihk.h"
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <CommCtrl.h>

/* Variables */
// Handles
HINSTANCE g_hAppInstance;
HHOOK g_hhkNTShk32 = NULL;
HHOOK g_hhkNTShk64 = NULL;
// Strings
WCHAR g_szAppTitle[64];
// Other
BOOL g_bSystem64 = TRUE;
BOOL g_bSystem64 = TRUE;

/* Functions */

Expand All @@ -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
Expand All @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/ntstyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
5 changes: 3 additions & 2 deletions src/ntstyle.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
<ClCompile Include="ntstyle.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\common\usrapihk.h" />
<ClInclude Include="ntstyle.h" />
<ClInclude Include="resource.h" />
</ItemGroup>
Expand All @@ -177,10 +178,10 @@
<ResourceCompile Include="resource.rc" />
</ItemGroup>
<ItemGroup>
<None Include="version.inc" />
<Manifest Include="ntstyle.exe.manifest" />
</ItemGroup>
<ItemGroup>
<Manifest Include="ntstyle.exe.manifest" />
<None Include="..\common\version.inc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
16 changes: 11 additions & 5 deletions src/ntstyle.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<Filter Include="Resource Files\en-US">
<UniqueIdentifier>{d681401a-a069-441c-82e8-4bba44ebd993}</UniqueIdentifier>
</Filter>
<Filter Include="Common Files">
<UniqueIdentifier>{5de2b196-5c95-4426-b53a-6e9402331a6b}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="ntstyle.c">
Expand All @@ -32,6 +35,9 @@
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\common\usrapihk.h">
<Filter>Common Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="resource.rc">
Expand All @@ -45,13 +51,13 @@
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<None Include="version.inc">
<Manifest Include="ntstyle.exe.manifest">
<Filter>Resource Files</Filter>
</None>
</Manifest>
</ItemGroup>
<ItemGroup>
<Manifest Include="ntstyle.exe.manifest">
<Filter>Source Files</Filter>
</Manifest>
<None Include="..\common\version.inc">
<Filter>Common Files</Filter>
</None>
</ItemGroup>
</Project>
8 changes: 6 additions & 2 deletions src/resource.rc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* * * * * * * *\
NTSTYLE.C -
RESOURCE.RC -
Copyright © 2024 Brady McDermott, Vortesys
DESCRIPTION -
This file contains NT Style's resources.
Expand All @@ -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
Expand Down
Binary file removed src/version.inc
Binary file not shown.
Loading

0 comments on commit d41cbd4

Please sign in to comment.