From 739c56e3145812c29b8add82465230bbb812aba2 Mon Sep 17 00:00:00 2001 From: freedom Date: Tue, 15 Aug 2023 22:05:04 -0600 Subject: [PATCH] dialog work so far, has a gdi resource leak --- progmgr/dialog.c | 94 ++++++++++++++++++++++++++++++++++++++++++----- progmgr/dialog.h | 4 +- progmgr/wndproc.c | 11 +++++- 3 files changed, 97 insertions(+), 12 deletions(-) diff --git a/progmgr/dialog.c b/progmgr/dialog.c index b7a69c4..b766d72 100644 --- a/progmgr/dialog.c +++ b/progmgr/dialog.c @@ -11,49 +11,125 @@ /* Headers */ #include "progmgr.h" #include "dialog.h" +#include "group.h" #include "resource.h" // #define WIN32_LEAN_AND_MEAN #include +#include /* Functions */ - /* * * *\ - GroupDlgProc - - Dialog procedure for creating or modifying - a group. + NewGroupDlgProc - + Dialog procedure for creating a group. RETURNS - TRUE if message is handled, FALSE otherwise. \* * * */ -BOOL CALLBACK GroupDlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) +BOOL CALLBACK NewGroupDlgProc(HWND hWndDlg, UINT message, WPARAM wParam, LPARAM lParam) { + BOOL bOKEnabled = FALSE; + WCHAR szBuffer[] = { L"\0" }; + HICON hIconDef = NULL; + HICON hIconDlg = NULL; + WCHAR szIconPath[MAX_PATH] = { L"\0" }; + int iIconIndex = 0; + switch (message) { case WM_INITDIALOG: + // TODO: + // Enable creation of common groups (enable the controls) + // if permissions are available. + + // Populate the icon with the default path and index. + GetModuleFileName(NULL, (LPWSTR)&szIconPath, MAX_PATH); + iIconIndex = IDI_PROGGRP - 1; - // Place message cases here. + // Get the default hIcon so we can delete it later + hIconDef = (HICON)SendDlgItemMessage(hWndDlg, IDD_STAT_ICON, STM_GETICON, 0, 0); + + // Set the icon in the dialog + hIconDlg = ExtractIcon(hAppInstance, (LPWSTR)&szIconPath, iIconIndex); + SendDlgItemMessage(hWndDlg, IDD_STAT_ICON, STM_SETICON, (WPARAM)hIconDlg, 0); + + // Set the maximum input length of the text boxes + SendDlgItemMessage(hWndDlg, IDD_NAME, EM_LIMITTEXT, MAX_TITLE_LENGTH, 0); + + // Disable the OK button since we're starting with no text in the box. + EnableWindow(GetDlgItem(hWndDlg, IDD_OK), bOKEnabled); + + break; + + case WM_COMMAND: + switch (GET_WM_COMMAND_ID(wParam, lParam)) + { + + case IDD_CHICON: + if (PickIconDlg(hWndDlg, (LPWSTR)&szIconPath, ARRAYSIZE(szIconPath), &iIconIndex) == TRUE) + { + // Since we've got the new icon... + hIconDlg = ExtractIcon(hAppInstance, (LPWSTR)&szIconPath, iIconIndex); + SendDlgItemMessage(hWndDlg, IDD_STAT_ICON, STM_SETICON, (WPARAM)hIconDlg, 0); + } + + break; + + case IDD_OK: + // Check that all the applicable fields are filled out + 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); + + break; + + case IDD_CANCEL: + EndDialog(hWndDlg, FALSE); + break; + + default: + break; + } default: + // Cleanup + if (hIconDef) + DestroyIcon(hIconDef); + if (hIconDlg) + DestroyIcon(hIconDlg); + return FALSE; } } /* * * *\ - ItemDlgProc - + NewItemDlgProc - Dialog procedure for creating or modifying an item. RETURNS - TRUE if message is handled, FALSE otherwise. \* * * */ -BOOL CALLBACK ItemDlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) +BOOL CALLBACK NewItemDlgProc(HWND hWndDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: - // Place message cases here. + break; + + case WM_COMMAND: + switch (GET_WM_COMMAND_ID(wParam, lParam)) + { + + case IDD_CANCEL: + EndDialog(hWndDlg, FALSE); + break; + + default: + break; + } default: return FALSE; diff --git a/progmgr/dialog.h b/progmgr/dialog.h index dcf5215..a483923 100644 --- a/progmgr/dialog.h +++ b/progmgr/dialog.h @@ -12,5 +12,5 @@ #pragma once /* Function Prototypes */ -BOOL CALLBACK ItemDlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam); -BOOL CALLBACK GroupDlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam); +BOOL CALLBACK NewGroupDlgProc(HWND hWndDlg, UINT message, WPARAM wParam, LPARAM lParam); +BOOL CALLBACK NewItemDlgProc(HWND hWndDlg, UINT message, WPARAM wParam, LPARAM lParam); diff --git a/progmgr/wndproc.c b/progmgr/wndproc.c index 6842707..211c530 100644 --- a/progmgr/wndproc.c +++ b/progmgr/wndproc.c @@ -9,6 +9,7 @@ /* Headers */ #include "progmgr.h" +#include "dialog.h" #include "group.h" #include "resource.h" #include "registry.h" @@ -39,7 +40,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case WM_SYSCOMMAND: { - if ((wParam >= IDM_MAIN) || (wParam <= IDM_TASKMGR)) + if ((wParam >= IDM_MAIN) && (wParam <= IDM_TASKMGR)) { if (wParam == IDM_TASKMGR) { @@ -97,6 +98,14 @@ LRESULT CALLBACK CmdProc(HWND hWnd, WPARAM wParam, LPARAM lParam) ExitWindowsDialog(hWnd); break; + case IDM_FILE_NEW_GROUP: + DialogBox(hAppInstance, MAKEINTRESOURCE(DLG_GROUP), hWnd, (DLGPROC)NewGroupDlgProc); + break; + + case IDM_FILE_NEW_ITEM: + DialogBox(hAppInstance, MAKEINTRESOURCE(DLG_ITEM), hWnd, (DLGPROC)NewItemDlgProc); + break; + case IDM_FILE_RUN: RunFileDlg(hWnd, NULL, NULL, NULL, NULL, RFF_CALCDIRECTORY); break;