Skip to content

Commit e400645

Browse files
committed
we're getting there
1 parent 77512dd commit e400645

File tree

3 files changed

+113
-35
lines changed

3 files changed

+113
-35
lines changed

progmgr/dialog.c

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// #define WIN32_LEAN_AND_MEAN
1717
#include <Windows.h>
1818
#include <Shlobj.h>
19+
#include <strsafe.h>
1920

2021
/* Functions */
2122

@@ -27,12 +28,22 @@
2728
\* * * */
2829
BOOL CALLBACK NewGroupDlgProc(HWND hWndDlg, UINT message, WPARAM wParam, LPARAM lParam)
2930
{
31+
GROUP grp = {
32+
.dwSignature = GRP_SIGNATURE,
33+
.wVersion = GRP_VERSION,
34+
.wChecksum = 0,
35+
.szName = L"",
36+
.dwFlags = 0,
37+
.ftLastWrite = 0,
38+
.cItems = 0,
39+
.iItems = NULL
40+
};
3041
BOOL bOKEnabled = FALSE;
31-
WCHAR szBuffer[] = { L"\0" };
42+
WCHAR szBuffer[MAX_TITLE_LENGTH] = { L"\0" };
3243
HICON hIconDef = NULL;
3344
HICON hIconDlg = NULL;
3445
WCHAR szIconPath[MAX_PATH] = { L"\0" };
35-
int iIconIndex = 0;
46+
INT iIconIndex = 0;
3647

3748
switch (message)
3849
{
@@ -41,6 +52,8 @@ BOOL CALLBACK NewGroupDlgProc(HWND hWndDlg, UINT message, WPARAM wParam, LPARAM
4152
// TODO:
4253
// Enable creation of common groups (enable the controls)
4354
// if permissions are available.
55+
// TODO:
56+
// fix minor GDI font/region leak
4457

4558
// Populate the icon with the default path and index.
4659
GetModuleFileName(NULL, (LPWSTR)&szIconPath, MAX_PATH);
@@ -62,6 +75,19 @@ BOOL CALLBACK NewGroupDlgProc(HWND hWndDlg, UINT message, WPARAM wParam, LPARAM
6275
break;
6376

6477
case WM_COMMAND:
78+
79+
if (HIWORD(wParam) == EN_CHANGE)
80+
{
81+
if (LOWORD(wParam) == IDD_NAME)
82+
{
83+
// Name text control changed. See what's up...
84+
bOKEnabled = GetDlgItemText(hWndDlg, IDD_NAME, (LPWSTR)&szBuffer, ARRAYSIZE(szBuffer));
85+
86+
// Enable or disable the OK button based on the information
87+
EnableWindow(GetDlgItem(hWndDlg, IDD_OK), bOKEnabled);
88+
}
89+
}
90+
6591
switch (GET_WM_COMMAND_ID(wParam, lParam))
6692
{
6793

@@ -79,9 +105,39 @@ BOOL CALLBACK NewGroupDlgProc(HWND hWndDlg, UINT message, WPARAM wParam, LPARAM
79105
// Check that all the applicable fields are filled out
80106
bOKEnabled = GetDlgItemText(hWndDlg, IDD_NAME, (LPWSTR)&szBuffer, ARRAYSIZE(szBuffer));
81107

108+
// If not, set the focus to the offending field
109+
if (!bOKEnabled)
110+
SendDlgItemMessage(hWndDlg, IDD_NAME, EM_TAKEFOCUS, 0, 0);
111+
82112
// Enable or disable the OK button based on the information
83113
EnableWindow(GetDlgItem(hWndDlg, IDD_OK), bOKEnabled);
84114

115+
if (bOKEnabled)
116+
{
117+
// Set the name of the group
118+
StringCchCopy(grp.szName, ARRAYSIZE(szBuffer), szBuffer);
119+
120+
// Set the flags of the group
121+
if (SendDlgItemMessage(hWndDlg, IDD_COMMGROUP, BM_GETCHECK, 0, 0) != BST_UNCHECKED)
122+
grp.dwFlags = grp.dwFlags || GRP_FLAG_COMMON;
123+
124+
// TODO: set FILETIME
125+
126+
// Set the rectangle of the group to be CW_USEDEFAULT
127+
grp.rcGroup.left = grp.rcGroup.top = grp.rcGroup.right = grp.rcGroup.bottom = CW_USEDEFAULT;
128+
129+
// Set icon properties
130+
StringCchCopy(grp.szIconPath, ARRAYSIZE(szIconPath), szIconPath);
131+
grp.iIconIndex = iIconIndex;
132+
133+
// Group's ready!
134+
if (CreateGroupWindow(&grp) != NULL)
135+
break;
136+
137+
// Failure!
138+
break;
139+
}
140+
85141
break;
86142

87143
case IDD_CANCEL:

progmgr/group.c

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,11 @@ BOOL InitializeGroups()
7171
if (!RegisterClassEx(&wce))
7272
return FALSE;
7373

74-
// TempCreateGroup();
75-
76-
CreateGroupWindow(NULL);
74+
// CreateGroupWindow(NULL);
7775

7876
return TRUE;
7977
}
8078

81-
82-
/* * * *\
83-
TempCreateGroup -
84-
th
85-
RETURNS -
86-
real
87-
\* * * */
88-
VOID TempCreateGroup()
89-
{
90-
return;
91-
}
92-
9379
/* * * *\
9480
CreateGroupWindow -
9581
Create an MDI window from a group structure
@@ -101,35 +87,69 @@ PGROUPWND CreateGroupWindow(PGROUP pgGroup)
10187
{
10288
GROUPWND gw = { NULL };
10389
MDICREATESTRUCT mcs = { NULL };
104-
HWND hGroup;
90+
HICON hIconBig = NULL;
91+
HICON hIconSmall = NULL;
92+
93+
// Copy group structure to our group window
94+
gw.grp = *pgGroup;
10595

10696
// TODO: allocate memory from pgwArray in here
10797

108-
// TODO: rethink the structure of this, when i create a group window
109-
// i don't have a pggroup handle. or maybe i do. think about this
110-
// just a little bit more, thanks!
98+
// TODO: Automatically add itself to the array of
99+
// PGW pointers?
100+
101+
// Get group minimized/maximized flags
111102

112103
mcs.szClass = szGrpClass;
113-
mcs.szTitle = L"";
104+
mcs.szTitle = gw.grp.szName;
114105
mcs.hOwner = hAppInstance;
115-
mcs.x = mcs.y = mcs.cx = mcs.cy = CW_USEDEFAULT;
106+
if ((gw.grp.rcGroup.left == CW_USEDEFAULT) & (gw.grp.rcGroup.right == CW_USEDEFAULT))
107+
{
108+
mcs.x = mcs.y = mcs.cx = mcs.cy = CW_USEDEFAULT;
109+
}
110+
else
111+
{
112+
mcs.x = gw.grp.rcGroup.left;
113+
mcs.y = gw.grp.rcGroup.top;
114+
mcs.cx = gw.grp.rcGroup.right - gw.grp.rcGroup.left;
115+
mcs.cy = gw.grp.rcGroup.bottom - gw.grp.rcGroup.top;
116+
}
116117
mcs.style = WS_VISIBLE;
117118
mcs.lParam = (LPARAM)pgGroup;
118119

119-
if (!(hGroup = (HWND)SendMessage(hWndMDIClient, WM_MDICREATE, 0, (LPARAM)(LPTSTR)&mcs)))
120+
if (!(gw.hWndGroup = (HWND)SendMessage(hWndMDIClient, WM_MDICREATE, 0, (LPARAM)(LPTSTR)&mcs)))
120121
return NULL;
121122

122-
return NULL;
123+
// Load the group icon
124+
ExtractIconEx(gw.grp.szIconPath, gw.grp.iIconIndex, &hIconBig, &hIconSmall, 0);
125+
SendMessage(gw.hWndGroup, WM_SETICON, ICON_SMALL, (LPARAM)hIconSmall);
126+
SendMessage(gw.hWndGroup, WM_SETICON, ICON_BIG, (LPARAM)hIconBig);
127+
128+
// TODO: make sure the groups delete their icons upon destruction!
129+
130+
return &gw;
131+
}
132+
133+
/* * * *\
134+
SetGroupFlags -
135+
Retrieve the flags of a group window.
136+
RETURNS -
137+
TRUE if the flag mask is applied
138+
FALSE if the flags aren't set
139+
\* * * */
140+
BOOL SetGroupFlags(PGROUPWND pgw, DWORD dwFlags)
141+
{
142+
return FALSE;
123143
}
124144

125145
/* * * *\
126146
GetGroupFlags -
127147
Retrieve the flags of a group window.
128148
RETURNS -
129-
DWORD containing the flags of the group.
130-
Otherwise 0xFFFFFFFF if failure.
149+
TRUE if the flag mask is applied
150+
FALSE if the flags aren't set
131151
\* * * */
132-
DWORD GetGroupFlags(PGROUPWND pgw)
152+
BOOL GetGroupFlags(PGROUPWND pgw, DWORD dwFlags)
133153
{
134154
HWND hWndGrp;
135155

@@ -184,7 +204,7 @@ GROUP SaveGroup(PGROUPWND pgw)
184204
WCHAR szGroupName[MAX_TITLE_LENGTH];
185205

186206
// Find the group and copy it
187-
grp = *pgw->pGroup;
207+
grp = pgw->grp;
188208

189209
// Get the window handle as well
190210
hWndGrp = pgw->hWndGroup;
@@ -196,7 +216,7 @@ GROUP SaveGroup(PGROUPWND pgw)
196216
GetWindowText(hWndGrp, szGroupName, MAX_TITLE_LENGTH);
197217
StringCchCopy(grp.szName, MAX_TITLE_LENGTH, szGroupName);
198218

199-
grp.dwFlags = GetGroupFlags(pgw);
219+
grp.dwFlags = GRP_FLAG_MAXIMIZED;// GetGroupFlags(pgw);
200220

201221
GetSystemTimeAsFileTime(&grp.ftLastWrite);
202222

progmgr/group.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ typedef struct _ITEM {
3939
UINT uiHotkeyVirtualKey;
4040
// Icon
4141
WCHAR szIconPath[MAX_PATH];
42-
UINT uiIconIndex;
42+
INT iIconIndex;
4343
} ITEM, * PITEM;
4444

4545
// Group format, .GRP
@@ -52,9 +52,11 @@ typedef struct _GROUP {
5252
WCHAR szName[MAX_TITLE_LENGTH];
5353
DWORD dwFlags; // Use with GRP_FLAG_* values.
5454
FILETIME ftLastWrite;
55+
// Window information
56+
RECT rcGroup;
5557
// Icon
5658
WCHAR szIconPath[MAX_PATH];
57-
UINT uiIconIndex;
59+
INT iIconIndex;
5860
// Items
5961
WORD cItems; // Number of items
6062
PITEM iItems; // Array of items
@@ -66,7 +68,7 @@ typedef struct _GROUPWND {
6668
HWND hWndGroup;
6769
HWND hWndListView;
6870
// Group
69-
PGROUP pGroup; // Pointer to GROUP structure
71+
GROUP grp; // Pointer to GROUP structure
7072
} GROUPWND, * PGROUPWND;
7173

7274
/* Global Variables */
@@ -76,11 +78,11 @@ extern HWND hWndMDIClient;
7678

7779
/* Function Prototypes */
7880
BOOL InitializeGroups();
79-
VOID TempCreateGroup();
8081
// Group Window
8182
LRESULT CALLBACK GroupWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
8283
PGROUPWND CreateGroupWindow(PGROUP pgGroup);
8384
// Group information
84-
DWORD GetGroupFlags(PGROUPWND pgw);
85+
BOOL SetGroupFlags(PGROUPWND pgw, DWORD dwFlags);
86+
BOOL GetGroupFlags(PGROUPWND pgw, DWORD dwFlags);
8587
// Import/export functions
8688
GROUP SaveGroup(PGROUPWND pgw);

0 commit comments

Comments
 (0)