Author: hbelusca
Date: Sun Nov 9 11:48:18 2014
New Revision: 65339
URL:
http://svn.reactos.org/svn/reactos?rev=65339&view=rev
Log:
[TASKMGR]
Displays the current user name in the TaskMgr shutdown menu.
Patch by Ismael Ferreras Morezuelas (swyter) with minor modifications by me.
CORE-8536 #resolve #comment Committed in r65339, thanks!
Modified:
trunk/reactos/base/applications/taskmgr/precomp.h
trunk/reactos/base/applications/taskmgr/taskmgr.c
Modified: trunk/reactos/base/applications/taskmgr/precomp.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/taskmgr/…
==============================================================================
--- trunk/reactos/base/applications/taskmgr/precomp.h [iso-8859-1] (original)
+++ trunk/reactos/base/applications/taskmgr/precomp.h [iso-8859-1] Sun Nov 9 11:48:18
2014
@@ -5,6 +5,7 @@
#error Task-Manager uses NDK functions, so it can only be compiled with Unicode support
enabled!
#endif
+#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
Modified: trunk/reactos/base/applications/taskmgr/taskmgr.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/taskmgr/…
==============================================================================
--- trunk/reactos/base/applications/taskmgr/taskmgr.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/taskmgr/taskmgr.c [iso-8859-1] Sun Nov 9 11:48:18
2014
@@ -564,13 +564,17 @@
HMENU hMenu;
HMENU hEditMenu;
HMENU hViewMenu;
+ HMENU hShutMenu;
HMENU hUpdateSpeedMenu;
HMENU hCPUHistoryMenu;
int nActivePage;
int nParts[3];
RECT rc;
WCHAR szTemp[256];
+ WCHAR szLogOffItem[MAX_PATH];
+ LPTSTR lpUserName;
TCITEM item;
+ DWORD len = 0;
SendMessageW(hMainWnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIconW(hInst,
MAKEINTRESOURCEW(IDI_TASKMANAGER)));
@@ -653,8 +657,9 @@
hMenu = GetMenu(hWnd);
hEditMenu = GetSubMenu(hMenu, 1);
hViewMenu = GetSubMenu(hMenu, 2);
+ hShutMenu = GetSubMenu(hMenu, 4);
hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
- hCPUHistoryMenu = GetSubMenu(hViewMenu, 7);
+ hCPUHistoryMenu = GetSubMenu(hViewMenu, 7);
/* Check or uncheck the always on top menu item */
if (TaskManagerSettings.AlwaysOnTop) {
@@ -703,6 +708,35 @@
TabCtrl_SetCurFocus/*Sel*/(hTabWnd, 1);
TabCtrl_SetCurFocus/*Sel*/(hTabWnd, 2);
TabCtrl_SetCurFocus/*Sel*/(hTabWnd, nActivePage);
+
+ /* Set the username in the "Log Off %s" item of the Shutdown menu */
+
+ /* 1- Get the menu item text and store it temporarily */
+ GetMenuStringW(hShutMenu, ID_SHUTDOWN_LOGOFF, szTemp, 256, MF_BYCOMMAND);
+
+ /* 2- Retrieve the username length first, then allocate a buffer for it and call it
again */
+ if (!GetUserNameW(NULL, &len) && GetLastError() ==
ERROR_INSUFFICIENT_BUFFER)
+ {
+ lpUserName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len * sizeof(WCHAR));
+ if (lpUserName && GetUserNameW(lpUserName, &len))
+ {
+ _snwprintf(szLogOffItem, sizeof(szLogOffItem)/sizeof(szLogOffItem[0]),
szTemp, lpUserName);
+ szLogOffItem[sizeof(szLogOffItem)/sizeof(szLogOffItem[0]) - 1] =
UNICODE_NULL;
+ }
+ else
+ {
+ _snwprintf(szLogOffItem, sizeof(szLogOffItem)/sizeof(szLogOffItem[0]),
szTemp, L"n/a");
+ }
+
+ if (lpUserName) HeapFree(GetProcessHeap(), 0, lpUserName);
+ }
+ else
+ {
+ _snwprintf(szLogOffItem, sizeof(szLogOffItem)/sizeof(szLogOffItem[0]), szTemp,
L"n/a");
+ }
+
+ /* 3- Set the menu item text to its formatted counterpart */
+ ModifyMenuW(hShutMenu, ID_SHUTDOWN_LOGOFF, MF_BYCOMMAND | MF_STRING,
ID_SHUTDOWN_LOGOFF, szLogOffItem);
/* Setup update speed */
SetUpdateSpeed(hWnd);