/*++ Copyright (c) 1990 Microsoft Corporation Module Name: fddlgs.c Abstract: Dialog routines and dialog support subroutines. Author: Ted Miller (tedm) 7-Jan-1992 --*/ #include "fdisk.h" // used in color dialog to indicate what the user has chosen for // the various graph element types DWORD SelectedColor[LEGEND_STRING_COUNT]; DWORD SelectedHatch[LEGEND_STRING_COUNT]; // used in color dialog, contains element (ie, partition, logical volume, // etc) we're selecting for (ie, which item is diaplyed in static text of // combo box). DWORD CurrentElement; // handle of active color dialogs box. Used by rectangle custom control. HWND hDlgColor; BOOL InitColorDlg( IN HWND hdlg ); VOID CenterDialog( HWND hwnd ) /*++ Routine Description: Centers a dialog relative to the app's main window Arguments: hwnd - window handle of dialog to center Return Value: None. --*/ { RECT rcFrame, rcWindow; LONG x, y, w, h; POINT point; LONG sx = GetSystemMetrics(SM_CXSCREEN), sy = GetSystemMetrics(SM_CYSCREEN); point.x = point.y = 0; ClientToScreen(hwndFrame,&point); GetWindowRect (hwnd ,&rcWindow); GetClientRect (hwndFrame,&rcFrame ); w = rcWindow.right - rcWindow.left + 1; h = rcWindow.bottom - rcWindow.top + 1; x = point.x + ((rcFrame.right - rcFrame.left + 1 - w) / 2); y = point.y + ((rcFrame.bottom - rcFrame.top + 1 - h) / 2); if (x + w > sx) { x = sx - w; } else if (x < 0) { x = 0; } if (y + h > sy) { y = sy - h; } else if (y < 0) { y = 0; } MoveWindow(hwnd,x,y,w,h,FALSE); } BOOL CALLBACK MinMaxDlgProc( IN HWND hwnd, IN UINT msg, IN WPARAM wParam, IN LPARAM lParam ) /*++ Routine Description: Dialog procedure for the enter size dialog box. This dialog allows the user to enter a size for a partition, or use spin controls (a tiny scroll bar) to select the size. Possible outcomes are cancel or OK. In the latter case the EndDialog code is the size. In the former it is 0. Arguments: hwnd - window handle of dialog box msg - message # wParam - msg specific data lParam - msg specific data Return Value: msg dependent --*/ { TCHAR outputString[MESSAGE_BUFFER_SIZE]; PMINMAXDLG_PARAMS params; BOOL validNumber; DWORD sizeMB; static DWORD minSizeMB, maxSizeMB, helpContextId; switch (msg) { case WM_INITDIALOG: CenterDialog(hwnd); params = (PMINMAXDLG_PARAMS)lParam; // set up caption LoadString(hModule, params->CaptionStringID, outputString, sizeof(outputString)/sizeof(TCHAR)); SetWindowText(hwnd, outputString); // set up minimum/maximum text LoadString(hModule, params->MinimumStringID, outputString, sizeof(outputString)/sizeof(TCHAR)); SetDlgItemText(hwnd, IDC_MINMAX_MINLABEL, outputString); LoadString(hModule, params->MaximumStringID, outputString, sizeof(outputString)/sizeof(TCHAR)); SetDlgItemText(hwnd, IDC_MINMAX_MAXLABEL, outputString); LoadString(hModule, params->SizeStringID, outputString, sizeof(outputString)/sizeof(TCHAR)); SetDlgItemText(hwnd, IDC_MINMAX_SIZLABEL, outputString); minSizeMB = params->MinSizeMB; maxSizeMB = params->MaxSizeMB; helpContextId = params->HelpContextId; wsprintf(outputString, TEXT("%u"), minSizeMB); SetDlgItemText(hwnd, IDC_MINMAX_MIN, outputString); wsprintf(outputString, TEXT("%u"), maxSizeMB); SetDlgItemText(hwnd, IDC_MINMAX_MAX, outputString); // also put the size in the edit control and select the text wsprintf(outputString, TEXT("%u"), maxSizeMB); SetDlgItemText(hwnd, IDC_MINMAX_SIZE, outputString); SendDlgItemMessage(hwnd, IDC_MINMAX_SIZE, EM_SETSEL, 0, -1); SetFocus(GetDlgItem(hwnd, IDC_MINMAX_SIZE)); return FALSE; // indicate focus set to a control case WM_VSCROLL: switch (LOWORD(wParam)) { case SB_LINEDOWN: case SB_LINEUP: sizeMB = GetDlgItemInt(hwnd, IDC_MINMAX_SIZE, &validNumber, FALSE); if (!validNumber) { Beep(500,100); } else { if (((sizeMB > minSizeMB) && (LOWORD(wParam) == SB_LINEDOWN)) || ((sizeMB < maxSizeMB) && (LOWORD(wParam) == SB_LINEUP ))) { if (sizeMB > maxSizeMB) { sizeMB = maxSizeMB; } else if (LOWORD(wParam) == SB_LINEUP) { sizeMB++; } else { sizeMB--; } wsprintf(outputString, TEXT("%u"), sizeMB); SetDlgItemText(hwnd, IDC_MINMAX_SIZE, outputString); SendDlgItemMessage(hwnd, IDC_MINMAX_SIZE, EM_SETSEL, 0, -1); } else { Beep(500,100); } } } break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: sizeMB = GetDlgItemInt(hwnd, IDC_MINMAX_SIZE, &validNumber, FALSE); if (!validNumber || !sizeMB || (sizeMB > maxSizeMB) || (sizeMB < minSizeMB)) { ErrorDialog(MSG_INVALID_SIZE); } else { EndDialog(hwnd, sizeMB); } break; case IDCANCEL: EndDialog(hwnd, 0); break; case FD_IDHELP: DialogHelp(helpContextId); break; default: return FALSE; } break; default: return FALSE; } return TRUE; } BOOL CALLBACK DriveLetterDlgProc( IN HWND hdlg, IN UINT msg, IN WPARAM wParam, IN LPARAM lParam ) /*++ Routine Description: Dialog for allowing the user to select a drive letter for a partition, logical drive, volume set, or stripe set. The EndDialog codes are as follows: 0 - user cancelled NO_DRIVE_LETTER_EVER - user opted not to assign a drive letter other - the drive letter chosen by the user Arguments: hdlg - window handle of dialog box msg - message # wParam - msg specific data lParam - msg specific data Return Value: msg dependent --*/ { static HWND hwndCombo; static DWORD currentSelection; TCHAR driveLetter; TCHAR driveLetterString[3]; DWORD defRadioButton, selection; PREGION_DESCRIPTOR regionDescriptor; PFT_OBJECT ftObject; TCHAR description[256]; switch (msg) { case WM_INITDIALOG: // lParam points to the region descriptor regionDescriptor = (PREGION_DESCRIPTOR)lParam; FDASSERT(DmSignificantRegion(regionDescriptor)); hwndCombo = GetDlgItem(hdlg,IDC_DRIVELET_COMBOBOX); CenterDialog(hdlg); // Add each available drive letter to the list of available // drive letters. driveLetterString[1] = TEXT(':'); driveLetterString[2] = 0; for (driveLetter='C'; driveLetter <= 'Z'; driveLetter++) { if (DriveLetterIsAvailable((CHAR)driveLetter)) { *driveLetterString = driveLetter; SendMessage(hwndCombo, CB_ADDSTRING, 0, (LONG)driveLetterString); } } // Format the description of the partition. if (ftObject = GET_FT_OBJECT(regionDescriptor)) { TCHAR descr[256]; DWORD resid = 0; // Ft. Description is something like "Stripe set with parity #0" switch (ftObject->Set->Type) { case Mirror: resid = IDS_DLGCAP_MIRROR; break; case Stripe: resid = IDS_STATUS_STRIPESET; break; case StripeWithParity: resid = IDS_DLGCAP_PARITY; break; case VolumeSet: resid = IDS_STATUS_VOLUMESET; break; default: FDASSERT(FALSE); } LoadString(hModule, resid, descr, sizeof(descr)/sizeof(TCHAR)); wsprintf(description, descr, ftObject->Set->Ordinal); } else { // Non-ft. Description is something like '500 MB Unformatted // logical drive on disk 3' or '400 MB HPFS partition on disk 4' LPTSTR args[4]; TCHAR sizeStr[20], partTypeStr[100], diskNoStr[10], typeName[150]; TCHAR formatString[256]; args[0] = sizeStr; args[1] = typeName; args[2] = partTypeStr; args[3] = diskNoStr; wsprintf(sizeStr, "%u", regionDescriptor->SizeMB); wsprintf(typeName, "%ws", PERSISTENT_DATA(regionDescriptor)->TypeName); LoadString(hModule, regionDescriptor->RegionType == REGION_LOGICAL ? IDS_LOGICALVOLUME : IDS_PARTITION, partTypeStr, sizeof(partTypeStr)/sizeof(TCHAR)); wsprintf(diskNoStr, "%u", regionDescriptor->Disk); LoadString(hModule, IDS_DRIVELET_DESCR, formatString, sizeof(formatString)/sizeof(TCHAR)); FormatMessage(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY, formatString, 0, 0, description, sizeof(description), (va_list *)args); } SetWindowText(GetDlgItem(hdlg, IDC_DRIVELET_DESCR), description); driveLetter = (TCHAR)PERSISTENT_DATA(regionDescriptor)->DriveLetter; if ((driveLetter != NO_DRIVE_LETTER_YET) && (driveLetter != NO_DRIVE_LETTER_EVER)) { DWORD itemIndex; // There is a default drive letter. Place it on the list, // check the correct radio button, and set the correct default // in the combo box. driveLetterString[0] = (TCHAR)driveLetter; itemIndex = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LONG)driveLetterString); SendMessage(hwndCombo, CB_SETCURSEL, itemIndex, 0); defRadioButton = IDC_DRIVELET_RBASSIGN; SetFocus(hwndCombo); currentSelection = itemIndex; } else { // Default is no drive letter. Disable the combo box. Select // the correct radio button. EnableWindow(hwndCombo, FALSE); defRadioButton = IDC_DRIVELET_RBNOASSIGN; SendMessage(hwndCombo, CB_SETCURSEL, (DWORD)(-1), 0); SetFocus(GetDlgItem(hdlg, IDC_DRIVELET_RBNOASSIGN)); currentSelection = 0; } CheckRadioButton(hdlg, IDC_DRIVELET_RBASSIGN, IDC_DRIVELET_RBNOASSIGN, defRadioButton); return FALSE; // focus set to control case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: // If the 'no letter' button is checked, return NO_DRIVE_LETTER_EVER if (IsDlgButtonChecked(hdlg, IDC_DRIVELET_RBNOASSIGN)) { EndDialog(hdlg, NO_DRIVE_LETTER_EVER); break; } // Otherwise, get the currently selected item in the listbox. selection = SendMessage(hwndCombo, CB_GETCURSEL, 0, 0); SendMessage(hwndCombo, CB_GETLBTEXT, selection, (LONG)driveLetterString); EndDialog(hdlg,(int)(unsigned)(*driveLetterString)); break; case IDCANCEL: EndDialog(hdlg, 0); break; case FD_IDHELP: DialogHelp(HC_DM_DLG_DRIVELETTER); break; case IDC_DRIVELET_RBASSIGN: if (HIWORD(wParam) == BN_CLICKED) { EnableWindow(hwndCombo, TRUE); SendMessage(hwndCombo, CB_SETCURSEL, currentSelection, 0); SetFocus(hwndCombo); } break; case IDC_DRIVELET_RBNOASSIGN: if (HIWORD(wParam) == BN_CLICKED) { currentSelection = SendMessage(hwndCombo, CB_GETCURSEL, 0, 0); SendMessage(hwndCombo, CB_SETCURSEL, (DWORD)-1, 0); EnableWindow(hwndCombo, FALSE); } break; default: return FALSE; } break; default: return FALSE; } return TRUE; } BOOL CALLBACK DisplayOptionsDlgProc( IN HWND hdlg, IN UINT msg, IN WPARAM wParam, IN LPARAM lParam ) /*++ Routine Description: Dialog procedure for display options. Currently the only display option is to alter the graph type (proportional/equal) on each disk. For this dialog, lParam on creation must point to a buffer into which this dialog procedure will place the user's new choices for the graph display type for each disk. Arguments: hdlg - window handle of dialog box msg - message # wParam - msg specific data lParam - msg specific data Return Value: msg dependent --*/ { static PBAR_TYPE newBarTypes; static HWND hwndCombo; DWORD selection; DWORD i; switch (msg) { case WM_INITDIALOG: CenterDialog(hdlg); newBarTypes = (PBAR_TYPE)lParam; hwndCombo = GetDlgItem(hdlg, IDC_DISK_COMBOBOX); // Add each disk to the combo box. for (i=0; i