Skip to content

Commit d2342e8

Browse files
committed
save window pos/placement for program groups
1 parent 306621f commit d2342e8

File tree

2 files changed

+50
-10
lines changed

2 files changed

+50
-10
lines changed

progmgr/group.c

+47-10
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
WNDCLASSEX wcGrp;
2626
WCHAR szGrpClass[16];
2727
HWND hWndMDIClient = NULL;
28+
HWND hWndFoundGroup = NULL;
2829

2930
/* Functions */
3031

@@ -138,13 +139,6 @@ HWND CreateGroup(_In_ PGROUP pg)
138139
{
139140
mcs.x = mcs.y = mcs.cx = mcs.cy = CW_USEDEFAULT;
140141
}
141-
else
142-
{
143-
mcs.x = pg->rcGroup.left;
144-
mcs.y = pg->rcGroup.top;
145-
mcs.cx = pg->rcGroup.right - pg->rcGroup.left;
146-
mcs.cy = pg->rcGroup.bottom - pg->rcGroup.top;
147-
}
148142
mcs.style = WS_VISIBLE | WS_THICKFRAME | WS_CAPTION | WS_BORDER | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX;
149143
// TODO: should I pass the pointer to the group through here
150144
// or is it better and easier to just do it with GWLP_USERDATA?
@@ -157,6 +151,10 @@ HWND CreateGroup(_In_ PGROUP pg)
157151
// Associate the group structure pointer to the group window
158152
SetWindowLongPtr(hWndGroup, GWLP_USERDATA, (LONG_PTR)pGroup);
159153

154+
// Resize the group
155+
if (pg->wp.length == sizeof(WINDOWPLACEMENT))
156+
SetWindowPlacement(hWndGroup, &pg->wp);
157+
160158
// Load the group icon
161159
if (ExtractIconEx(pg->szIconPath, pg->iIconIndex, &hIconLarge, &hIconSmall, 1))
162160
{
@@ -444,6 +442,8 @@ BOOL ExecuteItem(_In_ PITEM pi)
444442
VOID UpdateGroup(_In_ PGROUP pg)
445443
{
446444
DWORD dwFlags = 0;
445+
HWND hWndGroup = NULL;
446+
447447
// Set the important flags
448448
pg->dwSignature = GRP_SIGNATURE;
449449
pg->wVersion = GRP_VERSION;
@@ -452,18 +452,55 @@ VOID UpdateGroup(_In_ PGROUP pg)
452452
pg->wChecksum = 1; // NOTE: implement this for real later lol
453453

454454
// TODO: set name and group flags
455-
// pg->szName = GetWindowText(blah blah blah);
456455
// pg->dwFlags = GRP_FLAG_MAXIMIZED;// GetGroupFlags(pgw);
457456

458457
// Set FILETIME
459458
GetSystemTimeAsFileTime(&pg->ftLastWrite);
460459

461-
// Get the group window rect
462-
// GetClientRect(hWndGroup, &rcGroupWindow);
460+
if (hWndGroup = GetHwndFromPGroup(pg))
461+
{
462+
// Get the group window rect and name
463+
pg->wp.length = sizeof(WINDOWPLACEMENT);
464+
GetWindowPlacement(hWndGroup, &pg->wp);
465+
GetWindowText(hWndGroup, pg->szName, ARRAYSIZE(pg->szName));
466+
}
463467

464468
return;
465469
}
466470

471+
/* * * *\
472+
GetHwndFromPGroup -
473+
In goes a PGROUP out comes a HWND
474+
RETURNS -
475+
HWND.
476+
\* * * */
477+
HWND GetHwndFromPGroup(_In_ PGROUP pg)
478+
{
479+
EnumChildWindows(g_hWndProgMgr, &GetHwndFromPGroupEnum, (LPARAM)pg);
480+
481+
return hWndFoundGroup;
482+
}
483+
484+
/* * * *\
485+
GetHwndFromPGroupEnum -
486+
Enum Function
487+
RETURNS -
488+
HWND.
489+
\* * * */
490+
BOOL GetHwndFromPGroupEnum(_In_ HWND hwnd, _In_ LPARAM lParam)
491+
{
492+
if (lParam == GetWindowLongPtr(hwnd, GWLP_USERDATA))
493+
{
494+
hWndFoundGroup = hwnd;
495+
return FALSE;
496+
}
497+
else
498+
{
499+
hWndFoundGroup = NULL;
500+
return TRUE;
501+
}
502+
}
503+
467504
/* * * *\
468505
VerifyGroup -
469506
Verifies that a group contains the

progmgr/group.h

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ typedef struct _GROUP {
5757
FILETIME ftLastWrite;
5858
// Window information
5959
RECT rcGroup;
60+
WINDOWPLACEMENT wp;
6061
// Icon
6162
WCHAR szIconPath[MAX_PATH + 1];
6263
INT iIconIndex;
@@ -85,5 +86,7 @@ VOID UpdateGroup(_In_ PGROUP pg);
8586
BOOL VerifyGroup(_In_ PGROUP pg, _In_ BOOL bRepair);
8687
// Helper functions
8788
UINT CalculateGroupMemory(_In_ PGROUP pGroup, _In_ UINT cItems, _In_ BOOL bLean);
89+
HWND GetHwndFromPGroup(_In_ PGROUP pg);
90+
BOOL GetHwndFromPGroupEnum(_In_ HWND hwnd, _In_ LPARAM lParam);
8891
// Group Window
8992
LRESULT CALLBACK GroupWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

0 commit comments

Comments
 (0)