Skip to content

Commit c62bc10

Browse files
committed
update username on the fly
1 parent 9518a5e commit c62bc10

File tree

3 files changed

+42
-20
lines changed

3 files changed

+42
-20
lines changed

progmgr/progmgr.c

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
// #define WIN32_LEAN_AND_MEAN
1515
#define SECURITY_WIN32
1616
#include <Windows.h>
17-
#include <strsafe.h>
18-
#include <Lmcons.h>
19-
#include <security.h>
2017

2118
/* Variables */
2219
// Global
@@ -37,7 +34,7 @@ HWND hWndMDIClient = NULL;
3734
wWinMain -
3835
Program Manager's entry point.
3936
\* * * */
40-
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
37+
int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow)
4138
{
4239
MSG msg = { 0 };
4340
HANDLE hAccel;
@@ -46,9 +43,6 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
4643
WNDCLASS wc = { 0 };
4744
WCHAR szBuffer[MAX_PATH];
4845
WCHAR szClass[16];
49-
WCHAR szUsername[UNLEN + 1] = L"";
50-
DWORD dwUsernameLen = UNLEN;
51-
WCHAR szWindowTitle[UNLEN + ARRAYSIZE(szAppTitle) + 4] = L"";
5246
RECT rcRoot;
5347
POINT ptOffset;
5448

@@ -58,7 +52,6 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
5852
LoadString(hAppInstance, IDS_PMCLASS, szClass, ARRAYSIZE(szClass));
5953
LoadString(hAppInstance, IDS_APPTITLE, szAppTitle, ARRAYSIZE(szAppTitle));
6054
LoadString(hAppInstance, IDS_WEBSITE, szWebsite, ARRAYSIZE(szWebsite));
61-
GetUserNameEx(NameSamCompatible, szUsername, &dwUsernameLen);
6255

6356
// Get Desktop background color
6457
//CreateSolidBrush(GetBackgroundColor
@@ -91,15 +84,6 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
9184
return FALSE;
9285
}
9386

94-
// Add username to window title if settings permit
95-
StringCchCopy(szWindowTitle, ARRAYSIZE(szAppTitle), szAppTitle);
96-
97-
if (bShowUsername)
98-
{
99-
StringCchCat(szWindowTitle, ARRAYSIZE(szWindowTitle), L" - ");
100-
StringCchCat(szWindowTitle, ARRAYSIZE(szWindowTitle), szUsername);
101-
}
102-
10387
// Get size of the root HWND
10488
GetWindowRect(GetDesktopWindow(), &rcRoot);
10589

@@ -109,7 +93,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
10993

11094
// Create main window with a default size
11195
// NOTE: i pulled 320x240 out of my ass, make this dynamic later
112-
if (!CreateWindow(wc.lpszClassName, szWindowTitle, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
96+
if (!CreateWindow(wc.lpszClassName, szAppTitle, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
11397
rcRoot.left + ptOffset.x, rcRoot.top + ptOffset.y,
11498
rcRoot.left + ptOffset.x + 320, rcRoot.top + ptOffset.y + 240,
11599
0, 0, hAppInstance, NULL))
@@ -126,13 +110,15 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
126110
hMenu = GetMenu(hWndProgMgr);
127111
hSystemMenu = GetSystemMenu(hWndProgMgr, FALSE);
128112

129-
// Update our menu checkmarks
113+
// Update relevant parts of the window
130114
UpdateChecks(bAutoArrange, IDM_OPTIONS, IDM_OPTIONS_AUTOARRANGE);
131115
UpdateChecks(bMinOnRun, IDM_OPTIONS, IDM_OPTIONS_MINONRUN);
132116
UpdateChecks(bTopMost, IDM_OPTIONS, IDM_OPTIONS_TOPMOST);
133117
UpdateChecks(bShowUsername, IDM_OPTIONS, IDM_OPTIONS_SHOWUSERNAME);
134118
UpdateChecks(bSaveSettings, IDM_OPTIONS, IDM_OPTIONS_SAVESETTINGS);
135119

120+
UpdateWindowTitle();
121+
136122
// Update settings based on their values
137123
if (bTopMost)
138124
SetWindowPos(hWndProgMgr, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);

progmgr/progmgr.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,5 @@ BOOL SetShellWindow(HWND hWndShell);
4949
// WNDPROC.C
5050
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
5151
LRESULT CALLBACK CmdProc(HWND hWnd, WPARAM wParam, LPARAM lParam);
52-
VOID UpdateChecks(BOOL bVarMenu, UINT uSubMenu, UINT uID);
52+
VOID UpdateChecks(BOOL bVarMenu, UINT uSubMenu, UINT uID);
53+
VOID UpdateWindowTitle();

progmgr/wndproc.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
#include "resource.h"
1313
#include "registry.h"
1414
// #define WIN32_LEAN_AND_MEAN
15+
#define SECURITY_WIN32
1516
#include <Windows.h>
17+
#include <strsafe.h>
18+
#include <Lmcons.h>
19+
#include <security.h>
1620

1721
/* Functions */
1822

@@ -143,6 +147,7 @@ LRESULT CALLBACK CmdProc(HWND hWnd, WPARAM wParam, LPARAM lParam)
143147

144148
case IDM_OPTIONS_SHOWUSERNAME:
145149
bShowUsername = !bShowUsername;
150+
UpdateWindowTitle();
146151
UpdateChecks(bShowUsername, IDM_OPTIONS, IDM_OPTIONS_SHOWUSERNAME);
147152
goto SaveConfig;
148153

@@ -192,6 +197,36 @@ VOID UpdateChecks(BOOL bVarMenu, UINT uSubMenu, UINT uID)
192197
return;
193198
}
194199

200+
/* * * *\
201+
UpdateWindowTitle -
202+
Updates Window title based on settings... and
203+
current foreground group window if applicable?
204+
RETURNS -
205+
Nothing!
206+
\* * * */
207+
VOID UpdateWindowTitle()
208+
{
209+
WCHAR szUsername[UNLEN + 1] = L"";
210+
DWORD dwUsernameLen = UNLEN;
211+
WCHAR szWindowTitle[UNLEN + ARRAYSIZE(szAppTitle) + 4] = L"";
212+
213+
// Get user and domain name
214+
GetUserNameEx(NameSamCompatible, szUsername, &dwUsernameLen);
215+
216+
// Add username to window title if settings permit
217+
StringCchCopy(szWindowTitle, ARRAYSIZE(szAppTitle), szAppTitle);
218+
219+
if (bShowUsername)
220+
{
221+
StringCchCat(szWindowTitle, ARRAYSIZE(szWindowTitle), L" - ");
222+
StringCchCat(szWindowTitle, ARRAYSIZE(szWindowTitle), szUsername);
223+
}
224+
225+
SetWindowText(hWndProgMgr, (LPCWSTR)&szWindowTitle);
226+
227+
return;
228+
}
229+
195230
/* * * *\
196231
ChildWndProc -
197232
Program Manager's window procedure.

0 commit comments

Comments
 (0)