we're getting there

This commit is contained in:
freedom
2023-08-16 03:12:03 -06:00
parent 77512dd72d
commit e400645956
3 changed files with 113 additions and 35 deletions

View File

@@ -16,6 +16,7 @@
// #define WIN32_LEAN_AND_MEAN // #define WIN32_LEAN_AND_MEAN
#include <Windows.h> #include <Windows.h>
#include <Shlobj.h> #include <Shlobj.h>
#include <strsafe.h>
/* Functions */ /* Functions */
@@ -27,12 +28,22 @@
\* * * */ \* * * */
BOOL CALLBACK NewGroupDlgProc(HWND hWndDlg, UINT message, WPARAM wParam, LPARAM lParam) BOOL CALLBACK NewGroupDlgProc(HWND hWndDlg, UINT message, WPARAM wParam, LPARAM lParam)
{ {
GROUP grp = {
.dwSignature = GRP_SIGNATURE,
.wVersion = GRP_VERSION,
.wChecksum = 0,
.szName = L"",
.dwFlags = 0,
.ftLastWrite = 0,
.cItems = 0,
.iItems = NULL
};
BOOL bOKEnabled = FALSE; BOOL bOKEnabled = FALSE;
WCHAR szBuffer[] = { L"\0" }; WCHAR szBuffer[MAX_TITLE_LENGTH] = { L"\0" };
HICON hIconDef = NULL; HICON hIconDef = NULL;
HICON hIconDlg = NULL; HICON hIconDlg = NULL;
WCHAR szIconPath[MAX_PATH] = { L"\0" }; WCHAR szIconPath[MAX_PATH] = { L"\0" };
int iIconIndex = 0; INT iIconIndex = 0;
switch (message) switch (message)
{ {
@@ -41,6 +52,8 @@ BOOL CALLBACK NewGroupDlgProc(HWND hWndDlg, UINT message, WPARAM wParam, LPARAM
// TODO: // TODO:
// Enable creation of common groups (enable the controls) // Enable creation of common groups (enable the controls)
// if permissions are available. // if permissions are available.
// TODO:
// fix minor GDI font/region leak
// Populate the icon with the default path and index. // Populate the icon with the default path and index.
GetModuleFileName(NULL, (LPWSTR)&szIconPath, MAX_PATH); GetModuleFileName(NULL, (LPWSTR)&szIconPath, MAX_PATH);
@@ -62,6 +75,19 @@ BOOL CALLBACK NewGroupDlgProc(HWND hWndDlg, UINT message, WPARAM wParam, LPARAM
break; break;
case WM_COMMAND: case WM_COMMAND:
if (HIWORD(wParam) == EN_CHANGE)
{
if (LOWORD(wParam) == IDD_NAME)
{
// Name text control changed. See what's up...
bOKEnabled = GetDlgItemText(hWndDlg, IDD_NAME, (LPWSTR)&szBuffer, ARRAYSIZE(szBuffer));
// Enable or disable the OK button based on the information
EnableWindow(GetDlgItem(hWndDlg, IDD_OK), bOKEnabled);
}
}
switch (GET_WM_COMMAND_ID(wParam, lParam)) switch (GET_WM_COMMAND_ID(wParam, lParam))
{ {
@@ -79,9 +105,39 @@ BOOL CALLBACK NewGroupDlgProc(HWND hWndDlg, UINT message, WPARAM wParam, LPARAM
// Check that all the applicable fields are filled out // Check that all the applicable fields are filled out
bOKEnabled = GetDlgItemText(hWndDlg, IDD_NAME, (LPWSTR)&szBuffer, ARRAYSIZE(szBuffer)); bOKEnabled = GetDlgItemText(hWndDlg, IDD_NAME, (LPWSTR)&szBuffer, ARRAYSIZE(szBuffer));
// If not, set the focus to the offending field
if (!bOKEnabled)
SendDlgItemMessage(hWndDlg, IDD_NAME, EM_TAKEFOCUS, 0, 0);
// Enable or disable the OK button based on the information // Enable or disable the OK button based on the information
EnableWindow(GetDlgItem(hWndDlg, IDD_OK), bOKEnabled); EnableWindow(GetDlgItem(hWndDlg, IDD_OK), bOKEnabled);
if (bOKEnabled)
{
// Set the name of the group
StringCchCopy(grp.szName, ARRAYSIZE(szBuffer), szBuffer);
// Set the flags of the group
if (SendDlgItemMessage(hWndDlg, IDD_COMMGROUP, BM_GETCHECK, 0, 0) != BST_UNCHECKED)
grp.dwFlags = grp.dwFlags || GRP_FLAG_COMMON;
// TODO: set FILETIME
// Set the rectangle of the group to be CW_USEDEFAULT
grp.rcGroup.left = grp.rcGroup.top = grp.rcGroup.right = grp.rcGroup.bottom = CW_USEDEFAULT;
// Set icon properties
StringCchCopy(grp.szIconPath, ARRAYSIZE(szIconPath), szIconPath);
grp.iIconIndex = iIconIndex;
// Group's ready!
if (CreateGroupWindow(&grp) != NULL)
break;
// Failure!
break;
}
break; break;
case IDD_CANCEL: case IDD_CANCEL:

View File

@@ -71,25 +71,11 @@ BOOL InitializeGroups()
if (!RegisterClassEx(&wce)) if (!RegisterClassEx(&wce))
return FALSE; return FALSE;
// TempCreateGroup(); // CreateGroupWindow(NULL);
CreateGroupWindow(NULL);
return TRUE; return TRUE;
} }
/* * * *\
TempCreateGroup -
th
RETURNS -
real
\* * * */
VOID TempCreateGroup()
{
return;
}
/* * * *\ /* * * *\
CreateGroupWindow - CreateGroupWindow -
Create an MDI window from a group structure Create an MDI window from a group structure
@@ -101,35 +87,69 @@ PGROUPWND CreateGroupWindow(PGROUP pgGroup)
{ {
GROUPWND gw = { NULL }; GROUPWND gw = { NULL };
MDICREATESTRUCT mcs = { NULL }; MDICREATESTRUCT mcs = { NULL };
HWND hGroup; HICON hIconBig = NULL;
HICON hIconSmall = NULL;
// Copy group structure to our group window
gw.grp = *pgGroup;
// TODO: allocate memory from pgwArray in here // TODO: allocate memory from pgwArray in here
// TODO: rethink the structure of this, when i create a group window // TODO: Automatically add itself to the array of
// i don't have a pggroup handle. or maybe i do. think about this // PGW pointers?
// just a little bit more, thanks!
// Get group minimized/maximized flags
mcs.szClass = szGrpClass; mcs.szClass = szGrpClass;
mcs.szTitle = L""; mcs.szTitle = gw.grp.szName;
mcs.hOwner = hAppInstance; mcs.hOwner = hAppInstance;
if ((gw.grp.rcGroup.left == CW_USEDEFAULT) & (gw.grp.rcGroup.right == CW_USEDEFAULT))
{
mcs.x = mcs.y = mcs.cx = mcs.cy = CW_USEDEFAULT; mcs.x = mcs.y = mcs.cx = mcs.cy = CW_USEDEFAULT;
}
else
{
mcs.x = gw.grp.rcGroup.left;
mcs.y = gw.grp.rcGroup.top;
mcs.cx = gw.grp.rcGroup.right - gw.grp.rcGroup.left;
mcs.cy = gw.grp.rcGroup.bottom - gw.grp.rcGroup.top;
}
mcs.style = WS_VISIBLE; mcs.style = WS_VISIBLE;
mcs.lParam = (LPARAM)pgGroup; mcs.lParam = (LPARAM)pgGroup;
if (!(hGroup = (HWND)SendMessage(hWndMDIClient, WM_MDICREATE, 0, (LPARAM)(LPTSTR)&mcs))) if (!(gw.hWndGroup = (HWND)SendMessage(hWndMDIClient, WM_MDICREATE, 0, (LPARAM)(LPTSTR)&mcs)))
return NULL; return NULL;
return NULL; // Load the group icon
ExtractIconEx(gw.grp.szIconPath, gw.grp.iIconIndex, &hIconBig, &hIconSmall, 0);
SendMessage(gw.hWndGroup, WM_SETICON, ICON_SMALL, (LPARAM)hIconSmall);
SendMessage(gw.hWndGroup, WM_SETICON, ICON_BIG, (LPARAM)hIconBig);
// TODO: make sure the groups delete their icons upon destruction!
return &gw;
}
/* * * *\
SetGroupFlags -
Retrieve the flags of a group window.
RETURNS -
TRUE if the flag mask is applied
FALSE if the flags aren't set
\* * * */
BOOL SetGroupFlags(PGROUPWND pgw, DWORD dwFlags)
{
return FALSE;
} }
/* * * *\ /* * * *\
GetGroupFlags - GetGroupFlags -
Retrieve the flags of a group window. Retrieve the flags of a group window.
RETURNS - RETURNS -
DWORD containing the flags of the group. TRUE if the flag mask is applied
Otherwise 0xFFFFFFFF if failure. FALSE if the flags aren't set
\* * * */ \* * * */
DWORD GetGroupFlags(PGROUPWND pgw) BOOL GetGroupFlags(PGROUPWND pgw, DWORD dwFlags)
{ {
HWND hWndGrp; HWND hWndGrp;
@@ -184,7 +204,7 @@ GROUP SaveGroup(PGROUPWND pgw)
WCHAR szGroupName[MAX_TITLE_LENGTH]; WCHAR szGroupName[MAX_TITLE_LENGTH];
// Find the group and copy it // Find the group and copy it
grp = *pgw->pGroup; grp = pgw->grp;
// Get the window handle as well // Get the window handle as well
hWndGrp = pgw->hWndGroup; hWndGrp = pgw->hWndGroup;
@@ -196,7 +216,7 @@ GROUP SaveGroup(PGROUPWND pgw)
GetWindowText(hWndGrp, szGroupName, MAX_TITLE_LENGTH); GetWindowText(hWndGrp, szGroupName, MAX_TITLE_LENGTH);
StringCchCopy(grp.szName, MAX_TITLE_LENGTH, szGroupName); StringCchCopy(grp.szName, MAX_TITLE_LENGTH, szGroupName);
grp.dwFlags = GetGroupFlags(pgw); grp.dwFlags = GRP_FLAG_MAXIMIZED;// GetGroupFlags(pgw);
GetSystemTimeAsFileTime(&grp.ftLastWrite); GetSystemTimeAsFileTime(&grp.ftLastWrite);

View File

@@ -39,7 +39,7 @@ typedef struct _ITEM {
UINT uiHotkeyVirtualKey; UINT uiHotkeyVirtualKey;
// Icon // Icon
WCHAR szIconPath[MAX_PATH]; WCHAR szIconPath[MAX_PATH];
UINT uiIconIndex; INT iIconIndex;
} ITEM, * PITEM; } ITEM, * PITEM;
// Group format, .GRP // Group format, .GRP
@@ -52,9 +52,11 @@ typedef struct _GROUP {
WCHAR szName[MAX_TITLE_LENGTH]; WCHAR szName[MAX_TITLE_LENGTH];
DWORD dwFlags; // Use with GRP_FLAG_* values. DWORD dwFlags; // Use with GRP_FLAG_* values.
FILETIME ftLastWrite; FILETIME ftLastWrite;
// Window information
RECT rcGroup;
// Icon // Icon
WCHAR szIconPath[MAX_PATH]; WCHAR szIconPath[MAX_PATH];
UINT uiIconIndex; INT iIconIndex;
// Items // Items
WORD cItems; // Number of items WORD cItems; // Number of items
PITEM iItems; // Array of items PITEM iItems; // Array of items
@@ -66,7 +68,7 @@ typedef struct _GROUPWND {
HWND hWndGroup; HWND hWndGroup;
HWND hWndListView; HWND hWndListView;
// Group // Group
PGROUP pGroup; // Pointer to GROUP structure GROUP grp; // Pointer to GROUP structure
} GROUPWND, * PGROUPWND; } GROUPWND, * PGROUPWND;
/* Global Variables */ /* Global Variables */
@@ -76,11 +78,11 @@ extern HWND hWndMDIClient;
/* Function Prototypes */ /* Function Prototypes */
BOOL InitializeGroups(); BOOL InitializeGroups();
VOID TempCreateGroup();
// Group Window // Group Window
LRESULT CALLBACK GroupWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); LRESULT CALLBACK GroupWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
PGROUPWND CreateGroupWindow(PGROUP pgGroup); PGROUPWND CreateGroupWindow(PGROUP pgGroup);
// Group information // Group information
DWORD GetGroupFlags(PGROUPWND pgw); BOOL SetGroupFlags(PGROUPWND pgw, DWORD dwFlags);
BOOL GetGroupFlags(PGROUPWND pgw, DWORD dwFlags);
// Import/export functions // Import/export functions
GROUP SaveGroup(PGROUPWND pgw); GROUP SaveGroup(PGROUPWND pgw);