diff --git a/progmgr/dialog.c b/progmgr/dialog.c index 5819d6e..b660fae 100644 --- a/progmgr/dialog.c +++ b/progmgr/dialog.c @@ -16,6 +16,7 @@ // #define WIN32_LEAN_AND_MEAN #include #include +#include /* Functions */ @@ -27,12 +28,22 @@ \* * * */ 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; - WCHAR szBuffer[] = { L"\0" }; + WCHAR szBuffer[MAX_TITLE_LENGTH] = { L"\0" }; HICON hIconDef = NULL; HICON hIconDlg = NULL; WCHAR szIconPath[MAX_PATH] = { L"\0" }; - int iIconIndex = 0; + INT iIconIndex = 0; switch (message) { @@ -41,6 +52,8 @@ BOOL CALLBACK NewGroupDlgProc(HWND hWndDlg, UINT message, WPARAM wParam, LPARAM // TODO: // Enable creation of common groups (enable the controls) // if permissions are available. + // TODO: + // fix minor GDI font/region leak // Populate the icon with the default path and index. GetModuleFileName(NULL, (LPWSTR)&szIconPath, MAX_PATH); @@ -62,6 +75,19 @@ BOOL CALLBACK NewGroupDlgProc(HWND hWndDlg, UINT message, WPARAM wParam, LPARAM break; 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)) { @@ -79,9 +105,39 @@ BOOL CALLBACK NewGroupDlgProc(HWND hWndDlg, UINT message, WPARAM wParam, LPARAM // Check that all the applicable fields are filled out 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 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; case IDD_CANCEL: diff --git a/progmgr/group.c b/progmgr/group.c index 6ff808d..f8c05b9 100644 --- a/progmgr/group.c +++ b/progmgr/group.c @@ -71,25 +71,11 @@ BOOL InitializeGroups() if (!RegisterClassEx(&wce)) return FALSE; - // TempCreateGroup(); - - CreateGroupWindow(NULL); + // CreateGroupWindow(NULL); return TRUE; } - -/* * * *\ - TempCreateGroup - - th - RETURNS - - real -\* * * */ -VOID TempCreateGroup() -{ - return; -} - /* * * *\ CreateGroupWindow - Create an MDI window from a group structure @@ -101,35 +87,69 @@ PGROUPWND CreateGroupWindow(PGROUP pgGroup) { GROUPWND gw = { 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: 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! + // TODO: Automatically add itself to the array of + // PGW pointers? + + // Get group minimized/maximized flags mcs.szClass = szGrpClass; - mcs.szTitle = L""; + mcs.szTitle = gw.grp.szName; mcs.hOwner = hAppInstance; - mcs.x = mcs.y = mcs.cx = mcs.cy = CW_USEDEFAULT; + if ((gw.grp.rcGroup.left == CW_USEDEFAULT) & (gw.grp.rcGroup.right == 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.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; + // 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 - Retrieve the flags of a group window. RETURNS - - DWORD containing the flags of the group. - Otherwise 0xFFFFFFFF if failure. + TRUE if the flag mask is applied + FALSE if the flags aren't set \* * * */ -DWORD GetGroupFlags(PGROUPWND pgw) +BOOL GetGroupFlags(PGROUPWND pgw, DWORD dwFlags) { HWND hWndGrp; @@ -184,7 +204,7 @@ GROUP SaveGroup(PGROUPWND pgw) WCHAR szGroupName[MAX_TITLE_LENGTH]; // Find the group and copy it - grp = *pgw->pGroup; + grp = pgw->grp; // Get the window handle as well hWndGrp = pgw->hWndGroup; @@ -196,7 +216,7 @@ GROUP SaveGroup(PGROUPWND pgw) GetWindowText(hWndGrp, szGroupName, MAX_TITLE_LENGTH); StringCchCopy(grp.szName, MAX_TITLE_LENGTH, szGroupName); - grp.dwFlags = GetGroupFlags(pgw); + grp.dwFlags = GRP_FLAG_MAXIMIZED;// GetGroupFlags(pgw); GetSystemTimeAsFileTime(&grp.ftLastWrite); diff --git a/progmgr/group.h b/progmgr/group.h index 4d3a40b..552656f 100644 --- a/progmgr/group.h +++ b/progmgr/group.h @@ -39,7 +39,7 @@ typedef struct _ITEM { UINT uiHotkeyVirtualKey; // Icon WCHAR szIconPath[MAX_PATH]; - UINT uiIconIndex; + INT iIconIndex; } ITEM, * PITEM; // Group format, .GRP @@ -52,9 +52,11 @@ typedef struct _GROUP { WCHAR szName[MAX_TITLE_LENGTH]; DWORD dwFlags; // Use with GRP_FLAG_* values. FILETIME ftLastWrite; + // Window information + RECT rcGroup; // Icon WCHAR szIconPath[MAX_PATH]; - UINT uiIconIndex; + INT iIconIndex; // Items WORD cItems; // Number of items PITEM iItems; // Array of items @@ -66,7 +68,7 @@ typedef struct _GROUPWND { HWND hWndGroup; HWND hWndListView; // Group - PGROUP pGroup; // Pointer to GROUP structure + GROUP grp; // Pointer to GROUP structure } GROUPWND, * PGROUPWND; /* Global Variables */ @@ -76,11 +78,11 @@ extern HWND hWndMDIClient; /* Function Prototypes */ BOOL InitializeGroups(); -VOID TempCreateGroup(); // Group Window LRESULT CALLBACK GroupWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); PGROUPWND CreateGroupWindow(PGROUP pgGroup); // Group information -DWORD GetGroupFlags(PGROUPWND pgw); +BOOL SetGroupFlags(PGROUPWND pgw, DWORD dwFlags); +BOOL GetGroupFlags(PGROUPWND pgw, DWORD dwFlags); // Import/export functions GROUP SaveGroup(PGROUPWND pgw);