Skip to content

Commit

Permalink
Add hibernate, add /lang arg
Browse files Browse the repository at this point in the history
  • Loading branch information
aubymori committed Oct 11, 2024
1 parent 554e537 commit f4b7593
Show file tree
Hide file tree
Showing 11 changed files with 214 additions and 126 deletions.
52 changes: 41 additions & 11 deletions ClassicShutdown/ClassicShutdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ HWND g_hDesktopWnd, g_hDlg;
HBITMAP g_hbDesktop;
HINSTANCE g_hAppInstance, g_hMuiInstance, g_hShell32;
BOOL g_bLogoff;
BOOL g_bHibernationAvailable;
SHUTDOWNSTYLE g_ssStyle;

BrandingLoadImage_t BrandingLoadImage = nullptr;
Expand Down Expand Up @@ -63,8 +64,11 @@ void HandleShutdown(HWND hWnd, DWORD dwCode)
case SHTDN_STANDBY:
SetSuspendState(FALSE, TRUE, FALSE);
break;
case SHTDN_LOCK:
LockWorkStation();
case SHTDN_HIBER:
SetSuspendState(TRUE, FALSE, FALSE);
break;
case SHTDN_DISCONNECT:
WTSDisconnectSession(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, FALSE);
break;
default:
{
Expand Down Expand Up @@ -154,15 +158,14 @@ int WINAPI wWinMain(
ShowWindow(hFader, SW_HIDE);
}

/* Set up HINSTANCEs */
g_hAppInstance = hInstance;
g_hMuiInstance = GetMUIModule(g_hAppInstance);
if (!g_hMuiInstance)
{
ERRORANDQUIT(
L"Failed to load language resources.\n\nMost likely, you did not copy over files properly."
);
}
/* Check if hibernation is available */
SYSTEM_POWER_CAPABILITIES spc = { 0 };
CallNtPowerInformation(
SystemPowerCapabilities,
NULL, NULL,
&spc, sizeof(spc)
);
g_bHibernationAvailable = spc.HiberFilePresent;

CDimmedWindow *pDimmedWindow = NULL;

Expand Down Expand Up @@ -194,6 +197,7 @@ int WINAPI wWinMain(
LPWSTR *argv = CommandLineToArgvW(
lpCmdLine, &argc
);
WCHAR szLocale[LOCALE_NAME_MAX_LENGTH] = { 0 };
for (int i = 0; i < argc; i++)
{
if (!_wcsicmp(argv[i], L"/logoff"))
Expand Down Expand Up @@ -240,6 +244,32 @@ int WINAPI wWinMain(
g_ssStyle = SS_CLASSIC;
}
}
else if (!_wcsicmp(argv[i], L"/lang"))
{
if (i + 1 != argc)
{
wcscpy_s(szLocale, LOCALE_NAME_MAX_LENGTH, argv[i + 1]);
}
else
{
MessageBoxW(
NULL,
L"No value defined for /lang parameter, defaulting to system locale.",
L"ClassicShutdown",
MB_ICONWARNING
);
}
}
}

/* Set up HINSTANCEs */
g_hAppInstance = hInstance;
g_hMuiInstance = GetMUIModule(g_hAppInstance, szLocale);
if (!g_hMuiInstance)
{
ERRORANDQUIT(
L"Failed to load language resources.\n\nMost likely, you did not copy over files properly."
);
}

if (IsXP(g_ssStyle))
Expand Down
4 changes: 3 additions & 1 deletion ClassicShutdown/ClassicShutdown.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ extern HWND g_hDesktopWnd, g_hDlg;
extern HBITMAP g_hbDesktop;
extern HINSTANCE g_hAppInstance, g_hMuiInstance, g_hShell32;
extern BOOL g_bLogoff;
extern BOOL g_bHibernationAvailable;
extern LPDWORD g_dwRes;

typedef HANDLE (WINAPI *BrandingLoadImage_t)(
Expand Down Expand Up @@ -44,6 +45,7 @@ return 1;
#define SHTDN_SHUTDOWN 2
#define SHTDN_RESTART 3
#define SHTDN_STANDBY 4
#define SHTDN_LOCK 5
#define SHTDN_HIBER 5
#define SHTDN_DISCONNECT 6

#endif
17 changes: 16 additions & 1 deletion ClassicShutdown/ClassicShutdown.vcxproj.user
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerCommandArguments>/style xp</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LocalDebuggerCommandArguments>/style xp</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerCommandArguments>/style xp</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerCommandArguments>/style xp</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>
29 changes: 11 additions & 18 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 g_hbBrand;
HBITMAP s_hbBrand;

void MoveChildren(HWND hWnd, int dx, int dy)
{
Expand Down Expand Up @@ -68,15 +68,7 @@ INT_PTR CALLBACK ExitWindowsDlgProc(
{
case WM_INITDIALOG:
{
HINSTANCE hBasebrd = LoadLibraryW(L"C:\\Windows\\Branding\\Basebrd\\basebrd.dll");
if (!hBasebrd)
{
MessageBoxW(NULL, L"Failed to load basebrd.dll!", L"ClassicShutdown", MB_ICONERROR);
HandleShutdown(hWnd, SHTDN_NONE);
return FALSE;
}

g_hbBrand = GetBrandingBitmap();
s_hbBrand = GetBrandingBitmap();

HICON hShutDown = LoadIconW(
g_hShell32,
Expand All @@ -92,7 +84,7 @@ INT_PTR CALLBACK ExitWindowsDlgProc(

/* Resize window to account for branding banner */
BITMAP bmBrand;
GetObjectW(g_hbBrand, sizeof(BITMAP), &bmBrand);
GetObjectW(s_hbBrand, sizeof(BITMAP), &bmBrand);

RECT rcClient;
GetClientRect(hWnd, &rcClient);
Expand Down Expand Up @@ -139,7 +131,7 @@ INT_PTR CALLBACK ExitWindowsDlgProc(
}

HWND hComboBox = GetDlgItem(hWnd, IDD_EXITWINDOWS_COMBOBOX);
WCHAR szLogoffFormat[64], szLogoff[300], szShutdown[64], szRestart[64], szStandby[64], szLock[64], szUsername[UNLEN + 1];
WCHAR szLogoffFormat[64], szLogoff[300], szShutdown[64], szRestart[64], szStandby[64], szHiber[64], szUsername[UNLEN + 1];

LoadStringW(g_hMuiInstance, IDS_LOGOFF, szLogoffFormat, 64);

Expand All @@ -151,13 +143,14 @@ INT_PTR CALLBACK ExitWindowsDlgProc(
LoadStringW(g_hMuiInstance, IDS_SHUTDOWN, szShutdown, 64);
LoadStringW(g_hMuiInstance, IDS_RESTART, szRestart, 64);
LoadStringW(g_hMuiInstance, IDS_STANDBY, szStandby, 64);
LoadStringW(g_hMuiInstance, IDS_LOCK, szLock, 64);
LoadStringW(g_hMuiInstance, IDS_HIBER, szHiber, 64);

SendMessageW(hComboBox, CB_ADDSTRING, 0, (LPARAM)szLogoff);
SendMessageW(hComboBox, CB_ADDSTRING, 0, (LPARAM)szShutdown);
SendMessageW(hComboBox, CB_ADDSTRING, 0, (LPARAM)szRestart);
SendMessageW(hComboBox, CB_ADDSTRING, 0, (LPARAM)szStandby);
SendMessageW(hComboBox, CB_ADDSTRING, 0, (LPARAM)szLock);
if (g_bHibernationAvailable)
SendMessageW(hComboBox, CB_ADDSTRING, 0, (LPARAM)szHiber);
SendMessageW(hComboBox, CB_SETCURSEL, 1, 0);

WCHAR szShutdownDesc[256];
Expand Down Expand Up @@ -191,10 +184,10 @@ INT_PTR CALLBACK ExitWindowsDlgProc(
HDC hDC = BeginPaint(hWnd, &ps);
HDC hDCMem = CreateCompatibleDC(hDC);

HBITMAP hbmOld = (HBITMAP)SelectObject(hDCMem, g_hbBrand);
HBITMAP hbmOld = (HBITMAP)SelectObject(hDCMem, s_hbBrand);

BITMAP bmBrand;
GetObjectW(g_hbBrand, sizeof(BITMAP), &bmBrand);
GetObjectW(s_hbBrand, sizeof(BITMAP), &bmBrand);

BitBlt(
hDC,
Expand Down Expand Up @@ -237,8 +230,8 @@ INT_PTR CALLBACK ExitWindowsDlgProc(
case SHTDN_STANDBY:
uStringId = IDS_STANDBY_DESC;
break;
case SHTDN_LOCK:
uStringId = IDS_LOCK_DESC;
case SHTDN_HIBER:
uStringId = IDS_HIBER_DESC;
break;
}

Expand Down
Loading

0 comments on commit f4b7593

Please sign in to comment.