refactoring of group code from main program file, memory operations, updates to group format, we are getting REAL in here! also handle the changes introduced in the registry functions

This commit is contained in:
freedom
2023-08-10 02:14:35 -06:00
parent 35a28f698f
commit ba276117d7
5 changed files with 245 additions and 107 deletions

View File

@@ -14,12 +14,202 @@
#include "registry.h" #include "registry.h"
// #define WIN32_LEAN_AND_MEAN // #define WIN32_LEAN_AND_MEAN
#include <Windows.h> #include <Windows.h>
#include <strsafe.h>
/* Variables */ /* Variables */
WNDCLASSEX wcGrp; WNDCLASSEX wcGrp;
WCHAR szGrpClass[16];
PGROUPWND pgwArray[];
HWND hWndMDIClient = NULL;
/* Functions */ /* Functions */
/* * * *\
InitializeGroups -
Create the MDI Client window and initialize
the group window class.
RETURNS -
TRUE if groups are successfully created.
FALSE if otherwise.
\* * * */
BOOL InitializeGroups()
{
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)))
{
return FALSE;
}
// 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;
}
/* * * *\
TempCreateGroup -
th
RETURNS -
real
\* * * */
VOID TempCreateGroup()
{
return;
}
/* * * *\
CreateGroupWindow -
Create an MDI window from a group
RETURNS -
Group Window structure
or NULL GROUPWND on failure
\* * * */
GROUPWND CreateGroupWindow(PGROUP pgGroup)
{
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;
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 - GroupWndProc -
Group window procedure. Group window procedure.
@@ -35,42 +225,8 @@ LRESULT CALLBACK GroupWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
break; break;
} }
default: default:
// GroupProcDefault: // GroupProcDefault:
return DefMDIChildProc(hWnd, message, wParam, lParam); return DefMDIChildProc(hWnd, message, wParam, lParam);
} }
return 0; return 0;
} }
/* * * *\
InitGroups -
Initialize variables for the betterment of groups forever
Make great glorious MDI Client
RETURNS -
Zero if nothing, otherwise returns the good stuff.
\* * * */
/* * * *\
TempCreateGroup -
th
RETURNS -
handle to window
\* * * */
HWND TempCreateGroup(HWND hMDIClient)
{
MDICREATESTRUCT mcs;
HWND hChild;
mcs.szClass = szGrpClass;
mcs.szTitle = L"";
mcs.hOwner = hAppInstance;
mcs.x = mcs.y = mcs.cx = mcs.cy = CW_USEDEFAULT;
mcs.style = WS_VISIBLE;
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;
}

View File

@@ -19,6 +19,7 @@
#define MAX_TITLE_LENGTH MAX_PATH #define MAX_TITLE_LENGTH MAX_PATH
// Group Format Definitions // Group Format Definitions
#define GRP_SIGNATURE 0x47324D50L // PM2G #define GRP_SIGNATURE 0x47324D50L // PM2G
#define GRP_VERSION 1 // Increment for breaking changes
// Group Flag Values (DWORD) // Group Flag Values (DWORD)
#define GRP_FLAG_COMMON 0x00000001 #define GRP_FLAG_COMMON 0x00000001
#define GRP_FLAG_READONLY 0x00000002 #define GRP_FLAG_READONLY 0x00000002
@@ -30,12 +31,12 @@
typedef struct _ITEM { typedef struct _ITEM {
// Item executable and name // Item executable and name
WCHAR szItemName[MAX_TITLE_LENGTH]; 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 WCHAR szWorkPath[MAX_PATH]; // Working directory
// Icon // Icon
WCHAR szIconPath[MAX_PATH]; // Path of the icon WCHAR szIconPath[MAX_PATH];
UINT uiIconIndex; // Index of the icon UINT uiIconIndex;
} ITEM, * PITEM; } ITEM, * PITEM;
// Group format, .GRP // Group format, .GRP
@@ -59,12 +60,23 @@ typedef struct _GROUP {
typedef struct _GROUPWND { typedef struct _GROUPWND {
// Window information // Window information
HWND hWndGroup; HWND hWndGroup;
RECT rcGroup; // Window rectangle
// Group information // Group information
HANDLE hGroup; // Handle to GROUP object PGROUP pGroup; // Pointer to GROUP structure
} GROUPINFO, * PGROUPINFO; } GROUPWND, * PGROUPWND;
/* Global Variables */
extern HWND hWndMDIClient;
/* Local Variables */
/* Function Prototypes */ /* Function Prototypes */
BOOL InitializeGroups();
VOID TempCreateGroup();
// Group Window
LRESULT CALLBACK GroupWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); 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);

View File

@@ -19,18 +19,18 @@
/* Variables */ /* Variables */
// Global // Global
BOOL bIsDefaultShell = FALSE; BOOL bIsDefaultShell = FALSE;
// Window Related // Handles
HINSTANCE hAppInstance;
HANDLE hAppHeap;
HWND hWndProgMgr = NULL;
// Icons
HICON hProgMgrIcon = NULL; HICON hProgMgrIcon = NULL;
HICON hGroupIcon = NULL; HICON hGroupIcon = NULL;
HINSTANCE hAppInstance;
HWND hWndProgMgr = NULL;
HWND hWndMDIClient = NULL;
// Global Strings // Global Strings
WCHAR szAppTitle[32]; WCHAR szAppTitle[32];
WCHAR szProgMgr[] = L"progmgr"; WCHAR szProgMgr[] = L"progmgr";
WCHAR szWebsite[64]; WCHAR szWebsite[64];
WCHAR szClass[16]; WCHAR szClass[16];
WCHAR szGrpClass[16];
/* Functions */ /* Functions */
@@ -45,16 +45,18 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
HMENU hMenu; HMENU hMenu;
HMENU hSystemMenu; HMENU hSystemMenu;
WNDCLASS wc = { 0 }; WNDCLASS wc = { 0 };
WNDCLASSEX wce = { 0 };
WCHAR szBuffer[MAX_PATH]; WCHAR szBuffer[MAX_PATH];
RECT rcRoot; RECT rcRoot;
POINT ptOffset; POINT ptOffset;
// Initialize the instance
hAppInstance = hInstance; hAppInstance = hInstance;
// Create our global heap handle
hAppHeap = GetProcessHeap();
// Create Strings // Create Strings
LoadString(hAppInstance, IDS_PMCLASS, szClass, ARRAYSIZE(szClass)); LoadString(hAppInstance, IDS_PMCLASS, szClass, ARRAYSIZE(szClass));
LoadString(hAppInstance, IDS_GRPCLASS, szGrpClass, ARRAYSIZE(szGrpClass));
LoadString(hAppInstance, IDS_APPTITLE, szAppTitle, ARRAYSIZE(szAppTitle)); LoadString(hAppInstance, IDS_APPTITLE, szAppTitle, ARRAYSIZE(szAppTitle));
LoadString(hAppInstance, IDS_WEBSITE, szWebsite, ARRAYSIZE(szWebsite)); LoadString(hAppInstance, IDS_WEBSITE, szWebsite, ARRAYSIZE(szWebsite));
@@ -71,22 +73,8 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
wc.hbrBackground = NULL; wc.hbrBackground = NULL;
wc.lpszMenuName = MAKEINTRESOURCE(IDM_MAIN); wc.lpszMenuName = MAKEINTRESOURCE(IDM_MAIN);
wc.lpszClassName = szClass; wc.lpszClassName = szClass;
if (!RegisterClass(&wc))
return FALSE;
// Register the Group Window Class if (!RegisterClass(&wc))
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; return FALSE;
// Load the Accelerator table // Load the Accelerator table
@@ -95,15 +83,14 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
return FALSE; return FALSE;
// Perform Registry actions, close if registry is inaccessible. // Perform Registry actions, close if registry is inaccessible.
if (InitializeRegistryKeys()) if (!InitializeRegistryKeys())
{ return FALSE;
bIsDefaultShell = IsProgMgrDefaultShell();
LoadConfig(); bIsDefaultShell = IsProgMgrDefaultShell();
}
else // Load configuration, but don't load groups yet
{ if(LoadConfig(TRUE, TRUE, FALSE) != RCE_SUCCESS)
return FALSE; return FALSE;
}
// Get size of the root HWND // Get size of the root HWND
GetWindowRect(GetDesktopWindow(), &rcRoot); GetWindowRect(GetDesktopWindow(), &rcRoot);
@@ -114,10 +101,10 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
// Create main window with a default size // Create main window with a default size
// NOTE: i pulled 320x240 out of my ass, make this dynamic later // NOTE: i pulled 320x240 out of my ass, make this dynamic later
if (!CreateWindow(wc.lpszClassName, szAppTitle, WS_OVERLAPPEDWINDOW | WS_VISIBLE, if (!(hWndProgMgr = CreateWindowW(wc.lpszClassName, szAppTitle, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
rcRoot.left + ptOffset.x, rcRoot.top + ptOffset.y, rcRoot.left + ptOffset.x, rcRoot.top + ptOffset.y,
rcRoot.left + ptOffset.x + 320, rcRoot.top + ptOffset.y + 240, rcRoot.left + ptOffset.x + 320, rcRoot.top + ptOffset.y + 240,
0, 0, hAppInstance, NULL)) 0, 0, hAppInstance, NULL)))
return 2; return 2;
// Set the window size from the registry, but only if the coords make sense // Set the window size from the registry, but only if the coords make sense
@@ -163,6 +150,10 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
// CreateDesktopWindow(); // CreateDesktopWindow();
} }
// Create the frame window
if (!InitializeGroups())
return FALSE;
while (GetMessage(&msg, NULL, 0, 0) > 0) while (GetMessage(&msg, NULL, 0, 0) > 0)
{ {
if (!TranslateMDISysAccel(hWndMDIClient, &msg) && if (!TranslateMDISysAccel(hWndMDIClient, &msg) &&

View File

@@ -29,18 +29,19 @@
#define RF_RETRY 0x0002 // Cancel the operation, but leave the dialog open #define RF_RETRY 0x0002 // Cancel the operation, but leave the dialog open
/* Global Variables */ /* Global Variables */
// PROGMGR.C
extern BOOL bIsDefaultShell; extern BOOL bIsDefaultShell;
// Handles
extern HINSTANCE hAppInstance;
extern HANDLE hAppHeap;
extern HWND hWndProgMgr;
// Icons
extern HICON hProgMgrIcon; extern HICON hProgMgrIcon;
extern HICON hGroupIcon; extern HICON hGroupIcon;
extern HINSTANCE hAppInstance; // Strings
extern HWND hWndProgMgr;
extern HWND hWndMDIClient;
extern WCHAR szAppTitle[32]; extern WCHAR szAppTitle[32];
extern WCHAR szProgMgr[]; extern WCHAR szProgMgr[];
extern WCHAR szWebsite[64]; extern WCHAR szWebsite[64];
extern WCHAR szClass[16]; extern WCHAR szClass[16];
extern WCHAR szGrpClass[16];
/* Function Prototypes */ /* Function Prototypes */
// DESKTOP.C // DESKTOP.C

View File

@@ -33,28 +33,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{ {
case WM_CREATE: case WM_CREATE:
{ {
CLIENTCREATESTRUCT ccs;
RECT rc;
// Frame Window
hWndProgMgr = hWnd;
// Create the MDI Client Window
ccs.hWindowMenu = GetSubMenu(GetMenu(hWnd), IDM_WINDOW);
ccs.idFirstChild = IDM_WINDOW_CHILDSTART;
GetClientRect(hWndProgMgr, &rc);
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,
hWnd, (HMENU)1, hAppInstance, (LPWSTR)&ccs)))
{
return FALSE;
}
TempCreateGroup(hWndMDIClient);
break; break;
} }