From c62bc1049021ed2a1030424d98307a65f0ec7c41 Mon Sep 17 00:00:00 2001 From: freedom Date: Tue, 1 Aug 2023 13:03:22 -0600 Subject: [PATCH] update username on the fly --- progmgr/progmgr.c | 24 +++++------------------- progmgr/progmgr.h | 3 ++- progmgr/wndproc.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 20 deletions(-) diff --git a/progmgr/progmgr.c b/progmgr/progmgr.c index 4652add..78fa1f8 100644 --- a/progmgr/progmgr.c +++ b/progmgr/progmgr.c @@ -14,9 +14,6 @@ // #define WIN32_LEAN_AND_MEAN #define SECURITY_WIN32 #include -#include -#include -#include /* Variables */ // Global @@ -37,7 +34,7 @@ HWND hWndMDIClient = NULL; wWinMain - Program Manager's entry point. \* * * */ -int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) +int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) { MSG msg = { 0 }; HANDLE hAccel; @@ -46,9 +43,6 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi WNDCLASS wc = { 0 }; WCHAR szBuffer[MAX_PATH]; WCHAR szClass[16]; - WCHAR szUsername[UNLEN + 1] = L""; - DWORD dwUsernameLen = UNLEN; - WCHAR szWindowTitle[UNLEN + ARRAYSIZE(szAppTitle) + 4] = L""; RECT rcRoot; POINT ptOffset; @@ -58,7 +52,6 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi LoadString(hAppInstance, IDS_PMCLASS, szClass, ARRAYSIZE(szClass)); LoadString(hAppInstance, IDS_APPTITLE, szAppTitle, ARRAYSIZE(szAppTitle)); LoadString(hAppInstance, IDS_WEBSITE, szWebsite, ARRAYSIZE(szWebsite)); - GetUserNameEx(NameSamCompatible, szUsername, &dwUsernameLen); // Get Desktop background color //CreateSolidBrush(GetBackgroundColor @@ -91,15 +84,6 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi return FALSE; } - // Add username to window title if settings permit - StringCchCopy(szWindowTitle, ARRAYSIZE(szAppTitle), szAppTitle); - - if (bShowUsername) - { - StringCchCat(szWindowTitle, ARRAYSIZE(szWindowTitle), L" - "); - StringCchCat(szWindowTitle, ARRAYSIZE(szWindowTitle), szUsername); - } - // Get size of the root HWND GetWindowRect(GetDesktopWindow(), &rcRoot); @@ -109,7 +93,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi // Create main window with a default size // NOTE: i pulled 320x240 out of my ass, make this dynamic later - if (!CreateWindow(wc.lpszClassName, szWindowTitle, WS_OVERLAPPEDWINDOW | WS_VISIBLE, + if (!CreateWindow(wc.lpszClassName, szAppTitle, WS_OVERLAPPEDWINDOW | WS_VISIBLE, rcRoot.left + ptOffset.x, rcRoot.top + ptOffset.y, rcRoot.left + ptOffset.x + 320, rcRoot.top + ptOffset.y + 240, 0, 0, hAppInstance, NULL)) @@ -126,13 +110,15 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi hMenu = GetMenu(hWndProgMgr); hSystemMenu = GetSystemMenu(hWndProgMgr, FALSE); - // Update our menu checkmarks + // Update relevant parts of the window UpdateChecks(bAutoArrange, IDM_OPTIONS, IDM_OPTIONS_AUTOARRANGE); UpdateChecks(bMinOnRun, IDM_OPTIONS, IDM_OPTIONS_MINONRUN); UpdateChecks(bTopMost, IDM_OPTIONS, IDM_OPTIONS_TOPMOST); UpdateChecks(bShowUsername, IDM_OPTIONS, IDM_OPTIONS_SHOWUSERNAME); UpdateChecks(bSaveSettings, IDM_OPTIONS, IDM_OPTIONS_SAVESETTINGS); + UpdateWindowTitle(); + // Update settings based on their values if (bTopMost) SetWindowPos(hWndProgMgr, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); diff --git a/progmgr/progmgr.h b/progmgr/progmgr.h index 2bcdc1a..e71f9de 100644 --- a/progmgr/progmgr.h +++ b/progmgr/progmgr.h @@ -49,4 +49,5 @@ BOOL SetShellWindow(HWND hWndShell); // WNDPROC.C LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); LRESULT CALLBACK CmdProc(HWND hWnd, WPARAM wParam, LPARAM lParam); -VOID UpdateChecks(BOOL bVarMenu, UINT uSubMenu, UINT uID); \ No newline at end of file +VOID UpdateChecks(BOOL bVarMenu, UINT uSubMenu, UINT uID); +VOID UpdateWindowTitle(); \ No newline at end of file diff --git a/progmgr/wndproc.c b/progmgr/wndproc.c index 83b725b..855e0f6 100644 --- a/progmgr/wndproc.c +++ b/progmgr/wndproc.c @@ -12,7 +12,11 @@ #include "resource.h" #include "registry.h" // #define WIN32_LEAN_AND_MEAN +#define SECURITY_WIN32 #include +#include +#include +#include /* Functions */ @@ -143,6 +147,7 @@ LRESULT CALLBACK CmdProc(HWND hWnd, WPARAM wParam, LPARAM lParam) case IDM_OPTIONS_SHOWUSERNAME: bShowUsername = !bShowUsername; + UpdateWindowTitle(); UpdateChecks(bShowUsername, IDM_OPTIONS, IDM_OPTIONS_SHOWUSERNAME); goto SaveConfig; @@ -192,6 +197,36 @@ VOID UpdateChecks(BOOL bVarMenu, UINT uSubMenu, UINT uID) return; } +/* * * *\ + UpdateWindowTitle - + Updates Window title based on settings... and + current foreground group window if applicable? + RETURNS - + Nothing! +\* * * */ +VOID UpdateWindowTitle() +{ + WCHAR szUsername[UNLEN + 1] = L""; + DWORD dwUsernameLen = UNLEN; + WCHAR szWindowTitle[UNLEN + ARRAYSIZE(szAppTitle) + 4] = L""; + + // Get user and domain name + GetUserNameEx(NameSamCompatible, szUsername, &dwUsernameLen); + + // Add username to window title if settings permit + StringCchCopy(szWindowTitle, ARRAYSIZE(szAppTitle), szAppTitle); + + if (bShowUsername) + { + StringCchCat(szWindowTitle, ARRAYSIZE(szWindowTitle), L" - "); + StringCchCat(szWindowTitle, ARRAYSIZE(szWindowTitle), szUsername); + } + + SetWindowText(hWndProgMgr, (LPCWSTR)&szWindowTitle); + + return; +} + /* * * *\ ChildWndProc - Program Manager's window procedure.