Skip to content

Commit

Permalink
refactoring of group code from main program file, memory operations, …
Browse files Browse the repository at this point in the history
…updates to group format, we are getting REAL in here! also handle the changes introduced in the registry functions
  • Loading branch information
freedom7341 committed Aug 10, 2023
1 parent 35a28f6 commit ba27611
Show file tree
Hide file tree
Showing 5 changed files with 234 additions and 96 deletions.
216 changes: 186 additions & 30 deletions progmgr/group.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,63 +14,219 @@
#include "registry.h"
// #define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <strsafe.h>

/* Variables */
WNDCLASSEX wcGrp;
WCHAR szGrpClass[16];
PGROUPWND pgwArray[];
HWND hWndMDIClient = NULL;

/* Functions */

/* * * *\
GroupWndProc -
Group window procedure.
InitializeGroups -
Create the MDI Client window and initialize
the group window class.
RETURNS -
Zero if nothing, otherwise returns the good stuff.
TRUE if groups are successfully created.
FALSE if otherwise.
\* * * */
LRESULT CALLBACK GroupWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
BOOL InitializeGroups()
{
switch (message)
CLIENTCREATESTRUCT ccs = { 0 };
WNDCLASSEX wce = { 0 };

// Create the MDI Client Window
ccs.hWindowMenu = GetSubMenu(GetMenu(hWndProgMgr), IDM_WINDOW);
ccs.idFirstChild = IDM_WINDOW_CHILDSTART;

if (!(hWndMDIClient = CreateWindowEx(WS_EX_COMPOSITED, L"MDIClient",
NULL, WS_CLIPCHILDREN | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
hWndProgMgr, (HMENU)1, hAppInstance, (LPWSTR)&ccs)))
{
case WM_CREATE:
{
break;
}
default:
// GroupProcDefault:
return DefMDIChildProc(hWnd, message, wParam, lParam);
return FALSE;
}
return 0;

// Load the group class string
LoadString(hAppInstance, IDS_GRPCLASS, szGrpClass, ARRAYSIZE(szGrpClass));

// Register the group window Class
wce.cbSize = sizeof(WNDCLASSEX);
wce.lpfnWndProc = GroupWndProc;
wce.cbClsExtra = 0;
wce.cbWndExtra = 0;
wce.hInstance = hAppInstance;
wce.hIcon = hGroupIcon = LoadImage(hAppInstance, MAKEINTRESOURCE(IDI_PROGGRP), IMAGE_ICON,
0, 0, LR_DEFAULTSIZE | LR_SHARED);
wce.hCursor = LoadCursor(NULL, IDC_ARROW);
wce.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wce.lpszMenuName = NULL;
wce.lpszClassName = szGrpClass;

if (!RegisterClassEx(&wce))
return FALSE;

// TempCreateGroup();

// CreateGroupWindow(NULL);

return TRUE;
}


/* * * *\
InitGroups -
Initialize variables for the betterment of groups forever
Make great glorious MDI Client
TempCreateGroup -
th
RETURNS -
Zero if nothing, otherwise returns the good stuff.
real
\* * * */
VOID TempCreateGroup()
{
return;
}

/* * * *\
TempCreateGroup -
th
CreateGroupWindow -
Create an MDI window from a group
RETURNS -
handle to window
Group Window structure
or NULL GROUPWND on failure
\* * * */
HWND TempCreateGroup(HWND hMDIClient)
GROUPWND CreateGroupWindow(PGROUP pgGroup)
{
MDICREATESTRUCT mcs;
HWND hChild;
GROUPWND gw = { NULL };
MDICREATESTRUCT mcs = { NULL };
HWND hGroup;

// TODO: allocate memory from pgwArray in here

// TODO: rethink the structure of this, when i create a group window
// i don't have a pggroup handle. or maybe i do. think about this
// just a little bit more, thanks!

mcs.szClass = szGrpClass;
mcs.szTitle = L"";
mcs.hOwner = hAppInstance;
mcs.x = mcs.y = mcs.cx = mcs.cy = CW_USEDEFAULT;
mcs.style = WS_VISIBLE;
mcs.lParam = (LPARAM)pgGroup;

hGroup = (HWND)SendMessage(hWndMDIClient, WM_MDICREATE, 0, (LPARAM)(LPTSTR)&mcs);
if (!hGroup)
return gw;

return gw;
}

/* * * *\
GetGroupFlags -
Retrieve the flags of a group window.
RETURNS -
DWORD containing the flags of the group.
Otherwise 0xFFFFFFFF if failure.
\* * * */
DWORD GetGroupFlags(PGROUPWND pgw)
{
HWND hWndGrp;

// Cancel if the group window doesn't exist
if (pgw == NULL)
return 0xFFFFFFFF;

// Get the window handle
hWndGrp = pgw->hWndGroup;

hChild = (HWND)SendMessage(hMDIClient, WM_MDICREATE, 0, (LPARAM)(LPTSTR)&mcs);
// if (!hChild)
// {
// MessageBox(hMDIClient, L"MDI Child creation failed.", L"Oh Oh...",
// MB_ICONEXCLAMATION | MB_OK);
// }
return hChild;
if (hWndGrp != NULL)
{
// NOTE: come back to this lol
// TODO: establish better what this actually does
// min/max flags are pulled from hwnd
// common/readonly flags are set upon group creation
// this means that some flags are static whereas
// others change over time, this means that we can
// either assume certain flags never change over time
// or grab them every time.
return 0xFFFFFFFF;
}

return 0xFFFFFFFF;
}

/* * * *\
SaveGroup -
Saves group from a group window
into a GROUP structure.
INFO -
This function operates under the
assumption that the GROUP structure
doesn't get modified over the course
of the MDI window's life and we can't
just grab the structure directly and
expect it to be updated.
RETURNS -
Formatted GROUP structure.
Otherwise NULL if failure.
\* * * */
GROUP SaveGroup(PGROUPWND pgw)
{
GROUP grp = {
.dwSignature = GRP_SIGNATURE,
.wVersion = GRP_VERSION,
.wChecksum = 0,
.szGroupName = L"",
.dwFlags = 0,
.ftLastWrite = 0,
.cItems = 0,
.iItems = NULL
};
HWND hWndGrp;
WCHAR szName[MAX_TITLE_LENGTH];

// Find the group and copy it
grp = *pgw->pGroup;

// Get the window handle as well
hWndGrp = pgw->hWndGroup;

// Set the group header information
grp.dwSignature = GRP_SIGNATURE;
grp.wVersion = GRP_VERSION;
grp.wChecksum = 0; // NOTE: implement this later lol

// Copy group information
GetWindowText(hWndGrp, szName, MAX_TITLE_LENGTH);
StringCchCopy(grp.szGroupName, MAX_TITLE_LENGTH, szName);

grp.dwFlags = GetGroupFlags(pgw);

GetSystemTimeAsFileTime(&grp.ftLastWrite);

// Save items...
grp.cItems = 0;
// TODO: iterate through listview to save items

return grp;
}

/* * * *\
GroupWndProc -
Group window procedure.
RETURNS -
Zero if nothing, otherwise returns the good stuff.
\* * * */
LRESULT CALLBACK GroupWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
{
break;
}
default:
// GroupProcDefault:
return DefMDIChildProc(hWnd, message, wParam, lParam);
}
return 0;
}
26 changes: 19 additions & 7 deletions progmgr/group.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define MAX_TITLE_LENGTH MAX_PATH
// Group Format Definitions
#define GRP_SIGNATURE 0x47324D50L // PM2G
#define GRP_VERSION 1 // Increment for breaking changes
// Group Flag Values (DWORD)
#define GRP_FLAG_COMMON 0x00000001
#define GRP_FLAG_READONLY 0x00000002
Expand All @@ -30,12 +31,12 @@
typedef struct _ITEM {
// Item executable and name
WCHAR szItemName[MAX_TITLE_LENGTH];
WCHAR szExecPath[MAX_PATH]; // Path of the item executable
WCHAR szExecPath[MAX_PATH]; // Path of the executable
WCHAR szWorkPath[MAX_PATH]; // Working directory

// Icon
WCHAR szIconPath[MAX_PATH]; // Path of the icon
UINT uiIconIndex; // Index of the icon
WCHAR szIconPath[MAX_PATH];
UINT uiIconIndex;
} ITEM, * PITEM;

// Group format, .GRP
Expand All @@ -59,12 +60,23 @@ typedef struct _GROUP {
typedef struct _GROUPWND {
// Window information
HWND hWndGroup;
RECT rcGroup; // Window rectangle

// Group information
HANDLE hGroup; // Handle to GROUP object
} GROUPINFO, * PGROUPINFO;
PGROUP pGroup; // Pointer to GROUP structure
} GROUPWND, * PGROUPWND;

/* Global Variables */
extern HWND hWndMDIClient;

/* Local Variables */

/* Function Prototypes */
BOOL InitializeGroups();
VOID TempCreateGroup();
// Group Window
LRESULT CALLBACK GroupWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
HWND TempCreateGroup(HWND hMDIClient);
GROUPWND CreateGroupWindow(PGROUP pgGroup);
// Group information
DWORD GetGroupFlags(PGROUPWND pgw);
// Import/export functions
GROUP SaveGroup(PGROUPWND pgw);
Loading

0 comments on commit ba27611

Please sign in to comment.