//-------------------------------------------------------------------------
    static INT_PTR CALLBACK MainDialogProc(
        HWND hWnd,
        UINT message,
        WPARAM wParam,
        LPARAM lParam)
    {
        switch (message)
        {
            case WM_INITDIALOG:
            {
                ResetPermissionDialog::hDlg = hWnd;

                SendDlgItemMessage(
                    hDlg,
                    IDCHK_RESETPERM,
                    BM_SETCHECK,
                    BST_CHECKED,
                    0);

                SendDlgItemMessage(
                    hDlg,
                    IDCHK_DONTFOLLOWLINKS,
                    BM_SETCHECK,
                    BST_CHECKED,
                    0);

                SendDlgItemMessage(
                    hDlg,
                    IDCHK_RECURSE,
                    BM_SETCHECK,
                    BST_CHECKED,
                    0);

                HICON t = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SMALL));
                SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM)t);

                LPCTSTR Arg = GetArgs();

                if (Arg != NULL)
                    SetFolderText(Arg);
    #ifdef _DEBUG
                //else
                //    SetFolderText(_TEXT("C:\\Temp\\perm"));
    #endif
                if (Arg != NULL)
                    UpdateCommandText();
                return (INT_PTR)TRUE;
            }

            case WM_MENUCOMMAND:
                break;
            case WM_COMMAND:
            {
    #ifdef _DEBUG
                TCHAR b[1024];
                _sntprintf_s(b, _countof(b), _TEXT("WM_COMMAND: wmParam=%08X lParam=%08X\n"), wParam, lParam);
                OutputDebugString(b);
    #endif
                UINT wmId = LOWORD(wParam);
                UINT wmEvent = HIWORD(wParam);

                switch (wmId)
                {
                    case IDCHK_RECURSE:
                    case IDCHK_DONTFOLLOWLINKS:
                    case IDCHK_TAKEOWN:
                    case IDCHK_RESETPERM:
                    case IDCHK_RM_HS:
                    {
                        if (wmEvent == BN_CLICKED)
                        {
                            UpdateCommandText();
                            return TRUE;
                        }
                        break;
                    }
                    case IDM_ADDTOEXPLORERFOLDERRIGHT:
                    case IDM_REMOVEFROMEXPLORERFOLDERCONTEXTMENU:
                    {
                        AddToExplorerContextMenu(wmId == IDM_ADDTOEXPLORERFOLDERRIGHT);
                        break;
                    }
                    case IDBTN_ABOUT:
                    {
                        DialogBox(
                            hInstance,
                            MAKEINTRESOURCE(IDD_ABOUTBOX),
                            hDlg,
                            AboutDlgProc);

                        return TRUE;
                    }
                    case IDBTN_CHOOSE_FOLDER:
                    {
                        stringT out;
                        if (BrowseFolder(hDlg, STR_SELECT_FOLDER, out))
                        {
                            SetFolderText(out.c_str());
                            UpdateCommandText();
                        }
                        return TRUE;
                    }
                    case IDBTN_MORE_ACTIONS:
                    {
                        ShowMoreActionsMenu();
                        return TRUE;
                    }
                    case IDOK:
                    {
                        ExecuteCommand();
                        return TRUE;
                    }
                }
                break;
            }
            // Close dialog
            case WM_CLOSE:
            {
                EndDialog(hDlg, 0);
                return TRUE;
            }
        }
        return FALSE;
    }
//-------------------------------------------------------------------------
INT_PTR CALLBACK ResetPermissionDialog::MainDialogProc(
    HWND hWnd,
    UINT message,
    WPARAM wParam,
    LPARAM lParam)
{
    switch (message)
    {
        case WM_INITDIALOG:
        {
            hDlg = hWnd;

            // Set the initial states/configuration
            bRecurse = true;
            bResetPerm = true;
            bRmHidSys = false;
            bTakeOwn = false;
            bDontFollowLinks = true;

            UpdateCheckboxes(false);

            HICON hIcon = LoadIcon(
                hInstance,
                MAKEINTRESOURCE(IDI_SMALL));

            SendMessage(
                hDlg,
                WM_SETICON,
                ICON_BIG,
                (LPARAM)hIcon);

            LPCTSTR Arg = GetArg(1);

    #ifdef _DEBUG
            if (Arg == NULL)
                Arg = _TEXT("C:\\Temp\\perm");

			// Enable editing for the folder text editbox in debug mode
            SendDlgItemMessage(hDlg, IDTXT_FOLDER, EM_SETREADONLY, FALSE, 0);
    #endif

            if (Arg != NULL)
            {
                SetFolderText(Arg);
                UpdateCommandText();
            }

            return TRUE;
        }

        case WM_MENUCOMMAND:
            break;

        case WM_COMMAND:
        {
            UINT wmId = LOWORD(wParam);
            UINT wmEvent = HIWORD(wParam);
    #ifdef _DEBUG
            TCHAR b[1024];
            _sntprintf_s(
                b,
                _countof(b),
                _TEXT("WM_COMMAND: wmParam=%08X lParam=%08X | ID=%04X Event=%04X\n"),
                wParam,
                lParam,
                wmId,
                wmEvent);
            OutputDebugString(b);
			
			// Reflect the folder text changes when the control is editable
            if (wmId == IDTXT_FOLDER && wmEvent == EN_CHANGE)
                UpdateCommandText();
    #endif
            switch (wmId)
            {
                //
                // Handle checkboxes
                //
                case IDCHK_RECURSE:
                case IDCHK_DONTFOLLOWLINKS:
                case IDCHK_TAKEOWN:
                case IDCHK_RESETPERM:
                case IDCHK_RM_HS:
                {
                    // Reforumulate the command text on each option change
                    if (wmEvent == BN_CLICKED)
                    {
                        UpdateCommandText();
                        return TRUE;
                    }
                    break;
                }

                //
                // Handle context menu
                //
                case IDM_ADDTOEXPLORERFOLDERCONTEXTMENU:
                case IDM_REMOVEFROMEXPLORERFOLDERCONTEXTMENU:
                    AddToExplorerContextMenu(wmId == IDM_ADDTOEXPLORERFOLDERCONTEXTMENU);
                    break;

                case IDM_BACKUPPERMSCONTEXTMENU:
                case IDM_RESTOREPERMSCONTEXTMENU:
                    BackRestorePermissions(wmId == IDM_BACKUPPERMSCONTEXTMENU);
                    break;

                //
                // About box
                //
                case IDBTN_ABOUT:
                {
                    DialogBox(
                        hInstance,
                        MAKEINTRESOURCE(IDD_ABOUTBOX),
                        hDlg,
                        AboutDlgProc);

                    return TRUE;
                }

                //
                // Choose folder
                //
                case IDBTN_CHOOSE_FOLDER:
                {
                    stringT Folder;
                    if (BrowseFolder(hDlg, STR_SELECT_FOLDER, Folder))
                    {
                        SetFolderText(Folder.c_str());
                        UpdateCommandText();
                    }
                    return TRUE;
                }

                //
                // Trigger the "Advanced" menu
                //
                case IDBTN_ADVANCED:
                {
                    ShowPopupMenu(IDR_ADVANCED_MENU, IDBTN_ADVANCED);
                    return TRUE;
                }

                //
                // GO button
                //
                case IDOK:
                {
                    // Validate the input folder and execute the command
                    ExecuteWindowCommand(true);
                    return TRUE;
                }

                // HELP button
                case IDBTN_HELP:
                {
                    ShellExecute(
                        hDlg,
                        _TEXT("open"),
                        STR_HELP_URL,
                        nullptr,
                        nullptr,
                        SW_SHOW);

                    return TRUE;
                }
            } // switch(wmId)
            break;
        } // case WM_COMMAND

        // Close dialog
        case WM_CLOSE:
            EndDialog(hDlg, IDOK);
            return TRUE;
    }
    return FALSE;
}