Skip to content

Commit

Permalink
Use winbrand for branding banner
Browse files Browse the repository at this point in the history
  • Loading branch information
aubymori committed Jul 8, 2024
1 parent 22c9bcf commit 554e537
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 18 deletions.
14 changes: 14 additions & 0 deletions ClassicShutdown/ClassicShutdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions ClassicShutdown/ClassicShutdown.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion ClassicShutdown/ClassicShutdown.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
38 changes: 21 additions & 17 deletions ClassicShutdown/ExitWindowsDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#ifndef _ExitWindowsDlg_
#define _ExitWindowsDlg_

HBITMAP hbBrand;
HBITMAP g_hbBrand;

void MoveChildren(HWND hWnd, int dx, int dy)
{
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
File renamed without changes.

0 comments on commit 554e537

Please sign in to comment.