From 554e53789fe781f30b5c5d2d3b855b75077478b7 Mon Sep 17 00:00:00 2001 From: aubymori Date: Mon, 8 Jul 2024 16:16:45 -0500 Subject: [PATCH] Use winbrand for branding banner --- ClassicShutdown/ClassicShutdown.cpp | 14 +++++++ ClassicShutdown/ClassicShutdown.h | 11 +++++ ClassicShutdown/ClassicShutdown.rc | 2 +- ClassicShutdown/ExitWindowsDlg.cpp | 38 ++++++++++-------- ClassicShutdown/{ => res}/ClassicShutdown.ico | Bin 5 files changed, 47 insertions(+), 18 deletions(-) rename ClassicShutdown/{ => res}/ClassicShutdown.ico (100%) diff --git a/ClassicShutdown/ClassicShutdown.cpp b/ClassicShutdown/ClassicShutdown.cpp index a0cd9fb..5078f96 100644 --- a/ClassicShutdown/ClassicShutdown.cpp +++ b/ClassicShutdown/ClassicShutdown.cpp @@ -18,6 +18,8 @@ HINSTANCE g_hAppInstance, g_hMuiInstance, g_hShell32; BOOL g_bLogoff; SHUTDOWNSTYLE g_ssStyle; +BrandingLoadImage_t BrandingLoadImage = nullptr; + /* Virtual screen metrics */ int x, y, cx, cy; @@ -131,6 +133,18 @@ int WINAPI wWinMain( _In_ int nCmdShow ) { + HMODULE hWinBrand = LoadLibraryW(L"winbrand.dll"); + if (hWinBrand) + { + BrandingLoadImage = (BrandingLoadImage_t)GetProcAddress(hWinBrand, "BrandingLoadImage"); + } + if (!BrandingLoadImage) + { + ERRORANDQUIT( + L"Failed to load BrandingLoadImage from winbrand.dll" + ); + } + /* Nuke Open-Shell fader if it exists, and simulate start menu delay */ HWND hFader = FindWindowW(L"OpenShell.CMenuFader", NULL); diff --git a/ClassicShutdown/ClassicShutdown.h b/ClassicShutdown/ClassicShutdown.h index febe671..6edeac8 100644 --- a/ClassicShutdown/ClassicShutdown.h +++ b/ClassicShutdown/ClassicShutdown.h @@ -10,6 +10,17 @@ extern HINSTANCE g_hAppInstance, g_hMuiInstance, g_hShell32; extern BOOL g_bLogoff; extern LPDWORD g_dwRes; +typedef HANDLE (WINAPI *BrandingLoadImage_t)( + LPCWSTR lpszModule, + UINT uImageId, + UINT type, + int cx, + int cy, + UINT fuLoad +); + +extern BrandingLoadImage_t BrandingLoadImage; + typedef enum tagSHUTDOWNSTYLE { SS_CLASSIC, diff --git a/ClassicShutdown/ClassicShutdown.rc b/ClassicShutdown/ClassicShutdown.rc index 73e86d1..63be329 100644 --- a/ClassicShutdown/ClassicShutdown.rc +++ b/ClassicShutdown/ClassicShutdown.rc @@ -3,7 +3,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_DEFAULT -IDI_CLASSICSHUTDOWN ICON "ClassicShutdown.ico" +IDI_CLASSICSHUTDOWN ICON "res\\ClassicShutdown.ico" IDB_BACKGROUND BITMAP DISCARDABLE "res\\to_background.bmp" IDB_FLAG BITMAP DISCARDABLE "res\\to_flag.bmp" diff --git a/ClassicShutdown/ExitWindowsDlg.cpp b/ClassicShutdown/ExitWindowsDlg.cpp index 636767f..4a20d82 100644 --- a/ClassicShutdown/ExitWindowsDlg.cpp +++ b/ClassicShutdown/ExitWindowsDlg.cpp @@ -6,7 +6,7 @@ #ifndef _ExitWindowsDlg_ #define _ExitWindowsDlg_ -HBITMAP hbBrand; +HBITMAP g_hbBrand; void MoveChildren(HWND hWnd, int dx, int dy) { @@ -41,6 +41,22 @@ void MoveChildren(HWND hWnd, int dx, int dy) SWP_NOZORDER | SWP_NOMOVE); } +/** + * Load the branding banner from basebrd.dll. + * This uses the undocumented BrandingLoadImage function for + * maximum compatibility with Server 2022 and later. + */ +HBITMAP GetBrandingBitmap(void) +{ + /* The ID changed in 1607; first attempt new ID 123, and then use old 121 ID if that fails. */ + HBITMAP hbBrand = (HBITMAP)BrandingLoadImage(L"Basebrd", 123, IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); + if (!hbBrand) + { + hbBrand = (HBITMAP)BrandingLoadImage(L"Basebrd", 121, IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); + } + return hbBrand; +} + INT_PTR CALLBACK ExitWindowsDlgProc( HWND hWnd, UINT uMsg, @@ -60,19 +76,7 @@ INT_PTR CALLBACK ExitWindowsDlgProc( return FALSE; } - /* The layout of basebrd.dll changed in 1607 */ - hbBrand = LoadBitmapW( - hBasebrd, - MAKEINTRESOURCEW(123) - ); - - if (!hbBrand) - { - hbBrand = LoadBitmapW( - hBasebrd, - MAKEINTRESOURCEW(121) - ); - } + g_hbBrand = GetBrandingBitmap(); HICON hShutDown = LoadIconW( g_hShell32, @@ -88,7 +92,7 @@ INT_PTR CALLBACK ExitWindowsDlgProc( /* Resize window to account for branding banner */ BITMAP bmBrand; - GetObjectW(hbBrand, sizeof(BITMAP), &bmBrand); + GetObjectW(g_hbBrand, sizeof(BITMAP), &bmBrand); RECT rcClient; GetClientRect(hWnd, &rcClient); @@ -187,10 +191,10 @@ INT_PTR CALLBACK ExitWindowsDlgProc( HDC hDC = BeginPaint(hWnd, &ps); HDC hDCMem = CreateCompatibleDC(hDC); - HBITMAP hbmOld = (HBITMAP)SelectObject(hDCMem, hbBrand); + HBITMAP hbmOld = (HBITMAP)SelectObject(hDCMem, g_hbBrand); BITMAP bmBrand; - GetObjectW(hbBrand, sizeof(BITMAP), &bmBrand); + GetObjectW(g_hbBrand, sizeof(BITMAP), &bmBrand); BitBlt( hDC, diff --git a/ClassicShutdown/ClassicShutdown.ico b/ClassicShutdown/res/ClassicShutdown.ico similarity index 100% rename from ClassicShutdown/ClassicShutdown.ico rename to ClassicShutdown/res/ClassicShutdown.ico