Back to index

lightning-sunbird  0.9+nobinonly
dirpick.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include <windows.h>
00039 #include <windowsx.h>
00040 #include <direct.h>
00041 #include <stdio.h>
00042 
00043 #include "resource.h"
00044 
00045 extern HINSTANCE hInst;
00046 
00047 #define ITEM_BITMAPWIDTH     16
00048 #define ITEM_BITMAPHEIGHT    16
00049 #define ITEM_LEFTMARGIN       4
00050 #define ITEM_GAP              4
00051 
00052 static HWND hWndDirPicker;
00053 static HICON hIconDrives[5];
00054 static HICON hIconFolders[3];
00055 static LPSTR lpszStringToReturn;
00056 static char szUNCRoot[256] = "";
00057 
00058 UINT DriveType(UINT iType);
00059 
00060 static void fillComboBox(HWND hWnd) 
00061 {
00062   HWND hWndCB = GetDlgItem(hWnd, ID_COMBO_DIR);
00063   HWND hWndTempLB = GetDlgItem(hWnd, ID_LISTTEMP_DIR);
00064   if(hWndCB == NULL)
00065     return;
00066   ComboBox_ResetContent(hWndCB);
00067   ListBox_ResetContent(hWndTempLB);
00068   ListBox_Dir(hWndTempLB, DDL_DRIVES|DDL_EXCLUSIVE, (LPSTR)"*");
00069 
00070   int iDriveCount = ListBox_GetCount(hWndTempLB);
00071   int iCurDrive=_getdrive() - 1;
00072 
00073   char szDrive[16];
00074   char szItem[80];
00075 
00076   for (int i = 0; i < iDriveCount;  i++) 
00077   {
00078     ListBox_GetText(hWndTempLB, i, szDrive);
00079     CharLower(szDrive);
00080     int iDrive = szDrive[2] - 'a';
00081     char szRoot[16];
00082     sprintf(szRoot, "%c:\\", szDrive[2]);
00083 
00084     int iType = DriveType(iDrive);
00085 
00086     if(iType < 2)
00087       continue;
00088 
00089     //Start the item string with the drive letter, colon, and two spaces
00090     sprintf(szItem, "%c%s", szDrive[2], ": ");
00091 
00092     if((iType == DRIVE_FIXED) || (iType == DRIVE_RAMDISK)) 
00093     { // get volume ID
00094       char szVolumeID[80];
00095       DWORD dwMaxLength;
00096       DWORD dwSysFlags;
00097       GetVolumeInformation(szRoot,             // address of root directory of the file system 
00098                            szVolumeID,         // address of name of the volume 
00099                            sizeof(szVolumeID), // length of lpVolumeNameBuffer 
00100                            NULL,               // address of volume serial number 
00101                            &dwMaxLength,       // address of system's maximum filename length
00102                            &dwSysFlags,        // address of file system flags 
00103                            NULL,               // address of name of file system 
00104                            NULL);              // length of lpFileSystemNameBuffer 
00105 
00106       CharLower(szVolumeID);
00107       lstrcat(szItem, szVolumeID);
00108     }
00109 
00110     //For network drives, go grab the \\server\share for it.
00111     if(DRIVE_REMOTE == iType) 
00112     {
00113       char szNet[64];
00114       szNet[0] = '\0';
00115       DWORD dwSizeOfszNet = sizeof(szNet);
00116 
00117       sprintf(szDrive, "%c:", szDrive[2]);
00118       CharUpper(szDrive);
00119       WNetGetConnection(szDrive, szNet, &dwSizeOfszNet);
00120       CharLower(szNet);
00121       lstrcat(szItem, szNet);
00122     }
00123 
00124     int index = ComboBox_AddString(hWndCB, szItem);
00125     ComboBox_SetItemData(hWndCB, index, MAKELONG(iDrive, iType));
00126     if(iDrive == iCurDrive)
00127       ComboBox_SetCurSel(hWndCB, index);
00128     if(szUNCRoot[0] != '\0')
00129       ComboBox_SetCurSel(hWndCB, -1);
00130   }
00131 }
00132 
00133 static void fillTempLBWithDirs(HWND hWndTempLB, LPSTR lpszDir) 
00134 {
00135   BOOL bDone = FALSE;
00136   WIN32_FIND_DATA ffdataStruct;
00137 
00138   char szPath[_MAX_PATH];
00139   char szFileName[_MAX_PATH];
00140   lstrcpy(szPath, lpszDir);
00141   if(szPath[lstrlen(szPath) - 1] == '\\')
00142     szPath[lstrlen(szPath) - 1] = '\0';
00143   lstrcpy(szFileName, szPath);
00144   lstrcat(szFileName, "\\*");
00145   HANDLE handle = FindFirstFile(szFileName, &ffdataStruct);
00146   if(handle == INVALID_HANDLE_VALUE) 
00147   {
00148     FindClose(handle);
00149     return;
00150   }
00151   while(!bDone) 
00152   {
00153     lstrcpy(szFileName, szPath);
00154     lstrcat(szFileName, "\\");
00155     lstrcat(szFileName, ffdataStruct.cFileName);
00156     if(ffdataStruct. dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) 
00157     {
00158       char szStringToAdd[_MAX_PATH + 2];
00159       lstrcpy(szStringToAdd, "[");
00160       lstrcat(szStringToAdd, ffdataStruct.cFileName);
00161       lstrcat(szStringToAdd, "]");
00162       CharLower(szStringToAdd);
00163       ListBox_AddString(hWndTempLB, szStringToAdd);
00164     }
00165     bDone = !FindNextFile(handle, &ffdataStruct);
00166   }
00167   FindClose(handle);
00168 }
00169 
00170 static void fillListBox(HWND hWnd, LPSTR lpszDir) 
00171 {
00172   HWND hWndLB = GetDlgItem(hWnd, ID_LIST_DIR);
00173   HWND hWndTempLB = GetDlgItem(hWnd, ID_LISTTEMP_DIR);
00174   HWND hWndEdit = GetDlgItem(hWnd, ID_EDIT_DIR);
00175   if((hWndLB == NULL) || (lpszDir == NULL))
00176     return;
00177   
00178   int iLastChar = lstrlen(lpszDir);
00179   if(lpszDir[iLastChar - 1] == '\\')
00180     lpszDir[iLastChar - 1] = '\0';
00181 
00182   SetWindowRedraw(hWndLB, FALSE);
00183   ListBox_ResetContent(hWndLB);
00184   ListBox_ResetContent(hWndTempLB);
00185 
00186   LPSTR lpszLast;
00187   lpszLast = CharLower(lpszDir);
00188 
00189   SetWindowText(hWndLB, lpszDir);
00190 
00191   char szDir[_MAX_DIR];
00192   char szFullDir[_MAX_DIR];
00193   sprintf(szFullDir, "%s", lpszDir);
00194   sprintf(szDir, "%s\\*.*", lpszDir);
00195 
00196   BOOL bFirst = TRUE;
00197   char ch;
00198   int index;
00199   while (TRUE) 
00200   {
00201     LPSTR lpsz;
00202     if((lpszDir[0] == '\\') && (lpszDir[1] == '\\') && bFirst)
00203       lpsz = strchr(lpszLast + lstrlen(szUNCRoot), '\\');
00204     else
00205       lpsz = strchr(lpszLast, '\\');
00206     if(lpsz != NULL) {
00207       if (bFirst)
00208         ch = *(++lpsz);
00209       else
00210         ch = *lpsz;
00211       *lpsz = 0;
00212     } 
00213     else 
00214     {
00215       //If we're looking at a drive only, then append a backslash
00216       if (lpszLast == lpszDir && bFirst)
00217         lstrcat(lpszLast, "\\");
00218     }
00219     //Add the drive string--includes the last one where lpsz == NULL
00220     index = ListBox_AddString(hWndLB, lpszLast);
00221 
00222     UINT i = (NULL != lpsz) ? ID_ICON_FOLDEROPEN : ID_ICON_OPENSELECT;
00223     ListBox_SetItemData(hWndLB, index, MAKELONG(index, i));
00224 
00225     if(NULL == lpsz)
00226       break;
00227 
00228       //Restore last character.
00229     *lpsz = ch;
00230     lpsz += (bFirst) ? 0 : 1;
00231 
00232     bFirst=FALSE;
00233     lpszLast = lpsz;
00234   }
00235   int indent = index + 1;
00236 
00237   //Get available directories
00238   fillTempLBWithDirs(hWndTempLB, lpszDir);
00239 
00240   int itemCount = ListBox_GetCount(hWndTempLB);
00241 
00242   for (int i = 0; i < itemCount; i++) {
00243     index = ListBox_GetText(hWndTempLB, i, lpszDir);
00244     //Skip directories beginning with . (skipping . and ..)
00245     if(lpszDir[1] == '.')
00246       continue;
00247     //Remove the ending ']'
00248     iLastChar = lstrlen(lpszDir);
00249     lpszDir[iLastChar - 1] = '\0';
00250     //Add the string to the real directory list.
00251     index = ListBox_AddString(hWndLB, lpszDir + 1);
00252     ListBox_SetItemData(hWndLB, index, MAKELONG(indent, ID_ICON_FOLDERCLOSED));
00253   }
00254   //Force a listbox repaint.
00255   SetWindowRedraw(hWndLB, TRUE);
00256   InvalidateRect(hWndLB, NULL, TRUE);
00257 
00258   if(szFullDir[lstrlen(szFullDir) - 1] == ':')
00259     lstrcat(szFullDir, "\\");
00260   Edit_SetText(hWndEdit, szFullDir);
00261 
00262   GetScrollRange(hWndLB, SB_VERT, (LPINT)&i, (LPINT)&index);
00263 
00264   if(!(i == 0 && index == 0))
00265     ListBox_SetTopIndex(hWndLB, max((int)(index - 2), 0));
00266 
00267   ListBox_SetCurSel(hWndLB, indent - 1);
00268 }
00269 
00270 static void onDrawItem(LPDRAWITEMSTRUCT lpdis, BOOL bDrive) 
00271 {
00272   if((int)lpdis->itemID < 0)
00273     return;
00274 
00275   char szItem[_MAX_DIR];
00276   DWORD dwItemData;
00277 
00278   if(bDrive) 
00279   {
00280     dwItemData = ComboBox_GetItemData(lpdis->hwndItem, lpdis->itemID);
00281     ComboBox_GetLBText(lpdis->hwndItem, lpdis->itemID, szItem);
00282   } 
00283   else 
00284   {
00285     dwItemData = ListBox_GetItemData(lpdis->hwndItem, lpdis->itemID);
00286     ListBox_GetText(lpdis->hwndItem, lpdis->itemID, szItem);
00287   }
00288 
00289   if(lpdis->itemAction & (ODA_DRAWENTIRE | ODA_SELECT)) 
00290   {
00291     COLORREF colorText;
00292     COLORREF colorBack;
00293     if(lpdis->itemState & ODS_SELECTED) 
00294     {
00295       colorText = SetTextColor(lpdis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
00296       colorBack = SetBkColor(lpdis->hDC, GetSysColor(COLOR_HIGHLIGHT));
00297     }
00298     HICON hIcon;
00299     int indent = 0;
00300     if(bDrive) 
00301     {
00302       int iType=(int)HIWORD(dwItemData);
00303       switch (iType) 
00304       {
00305         case DRIVE_REMOVABLE:
00306           hIcon = hIconDrives[0];
00307           break; 
00308         case DRIVE_FIXED:
00309           hIcon = hIconDrives[1];
00310           break;
00311         case DRIVE_REMOTE:
00312           hIcon = hIconDrives[2];
00313           break; 
00314         case DRIVE_CDROM:
00315           hIcon = hIconDrives[3];
00316           break; 
00317         case DRIVE_RAMDISK:
00318           hIcon = hIconDrives[4];
00319           break; 
00320       }
00321 
00322     } 
00323     else 
00324     {
00325       int iconID = (int)HIWORD(lpdis->itemData);
00326       switch (iconID) 
00327       {
00328         case ID_ICON_FOLDERCLOSED:
00329           hIcon = hIconFolders[0];
00330           break;
00331         case ID_ICON_FOLDEROPEN:
00332           hIcon = hIconFolders[1];
00333           break;
00334         case ID_ICON_OPENSELECT:
00335           hIcon = hIconFolders[2];
00336           break;
00337       }
00338       indent = 4 * (1 + LOWORD(lpdis->itemData));
00339     }
00340 
00341     ExtTextOut(lpdis->hDC, 
00342                lpdis->rcItem.left + ITEM_LEFTMARGIN + ITEM_BITMAPWIDTH + ITEM_GAP + indent,
00343                lpdis->rcItem.top,
00344                ETO_OPAQUE | ETO_CLIPPED,
00345                &lpdis->rcItem,
00346                szItem,
00347                lstrlen(szItem),
00348                NULL);
00349 
00350     BOOL res = DrawIcon(lpdis->hDC, 
00351                         lpdis->rcItem.left + ITEM_LEFTMARGIN + indent,
00352                         lpdis->rcItem.top, 
00353                         hIcon);
00354 
00355     if(lpdis->itemState & ODS_SELECTED) 
00356     {
00357       SetTextColor(lpdis->hDC, colorText);
00358       SetBkColor(lpdis->hDC, colorBack);
00359     }
00360   }
00361   if((lpdis->itemAction & ODA_FOCUS) || (lpdis->itemState & ODS_FOCUS))
00362     DrawFocusRect(lpdis->hDC, &lpdis->rcItem);
00363 }
00364 
00365 static void fillUNCRootArray(LPSTR lpsz) 
00366 {
00367   char szCurDir[_MAX_PATH];
00368   _getcwd(szCurDir, sizeof(szCurDir));
00369   lstrcpy(szUNCRoot, lpsz);
00370   if(szUNCRoot[lstrlen(szUNCRoot) - 1] == '\\')
00371     szUNCRoot[lstrlen(szUNCRoot) - 1] = '\0';
00372   for(;;) 
00373   {
00374     LPSTR lptemp = strrchr(szUNCRoot, '\\');
00375     if(lptemp == NULL)
00376       break;
00377     *lptemp = '\0';
00378     if(_chdir(szUNCRoot) == -1) 
00379     {
00380       *lptemp = '\\';
00381       break;
00382     }
00383   }
00384   _chdir(szCurDir);
00385 }
00386 
00387 static void onInitDialog(HWND hWnd, LPSTR lpsz) 
00388 {
00389   hWndDirPicker = hWnd;
00390   lpszStringToReturn = lpsz;
00391   
00392   hIconDrives[0] = LoadIcon(hInst, MAKEINTRESOURCE(ID_ICON_DRIVEFLOPPY));
00393   hIconDrives[1] = LoadIcon(hInst, MAKEINTRESOURCE(ID_ICON_DRIVEHARD));
00394   hIconDrives[2] = LoadIcon(hInst, MAKEINTRESOURCE(ID_ICON_DRIVENETWORK));
00395   hIconDrives[3] = LoadIcon(hInst, MAKEINTRESOURCE(ID_ICON_DRIVECDROM));
00396   hIconDrives[4] = LoadIcon(hInst, MAKEINTRESOURCE(ID_ICON_DRIVERAM));
00397 
00398   hIconFolders[0] = LoadIcon(hInst, MAKEINTRESOURCE(ID_ICON_FOLDERCLOSED));
00399   hIconFolders[1] = LoadIcon(hInst, MAKEINTRESOURCE(ID_ICON_FOLDEROPEN));
00400   hIconFolders[2] = LoadIcon(hInst, MAKEINTRESOURCE(ID_ICON_OPENSELECT));
00401   
00402   if(lpsz[0] == '\0') 
00403     _getcwd(lpsz, _MAX_PATH);
00404   else if(lpsz[lstrlen(lpsz) - 1] == ':')
00405     lstrcat(lpsz, "\\");
00406 
00407   int ret = _chdir(lpsz);
00408   if(ret == -1) 
00409   {
00410     char szText[_MAX_PATH + 80];
00411     sprintf(szText, "The specified directory %s\ncannot be found", lpsz);
00412     MessageBox(GetParent(hWnd), szText, "Choose Directory", MB_ICONEXCLAMATION|MB_OK);
00413     _getcwd(lpsz, _MAX_PATH);
00414   }
00415   if((lpsz[0] == '\\') && (lpsz[1] == '\\'))
00416     fillUNCRootArray(lpsz);
00417   fillListBox(hWnd, lpsz);
00418   fillComboBox(hWnd);
00419 }
00420 
00421 static void shutDialog(HWND hWnd) 
00422 {
00423   szUNCRoot[0] = '\0';
00424 }
00425 
00426 static void onCommand(HWND hWnd, int id, HWND hWndCtl, UINT codeNotify) 
00427 {
00428   char szCurDir[_MAX_PATH];
00429   switch(id) 
00430   {
00431     case ID_LIST_DIR:
00432       if(codeNotify == LBN_DBLCLK) 
00433       {
00434         int index = ListBox_GetCurSel(hWndCtl);
00435         DWORD dwItemData = ListBox_GetItemData(hWndCtl, index);
00436 
00437         if(HIWORD(dwItemData) == ID_ICON_OPENSELECT) 
00438         {
00439           shutDialog(hWnd);
00440           char szString[_MAX_PATH];
00441           Edit_GetText(GetDlgItem(hWndDirPicker, ID_EDIT_DIR), szString, sizeof(szString));
00442           lstrcpy(lpszStringToReturn, szString);
00443           EndDialog(hWnd, IDOK);
00444           break;
00445         }
00446 
00447         ListBox_GetText(hWndCtl, index, szCurDir);
00448 
00449         char szDir[_MAX_DIR];
00450         LPSTR lpsz;
00451         if((HIWORD(dwItemData) == ID_ICON_FOLDEROPEN) && (index != 0)) 
00452         {
00453           GetWindowText(hWndCtl, szDir, sizeof(szDir));
00454           lpsz=_fstrstr(szDir, szCurDir);
00455           *(lpsz + lstrlen(szCurDir)) = '\0';
00456           lstrcpy(szCurDir, szDir);
00457         }
00458         if (_chdir(szCurDir) == 0) 
00459         {
00460           _getcwd(szCurDir, _MAX_PATH);
00461           fillListBox(hWndDirPicker, szCurDir);
00462         }
00463       }
00464       break;
00465     case ID_COMBO_DIR:
00466       if(codeNotify == CBN_SELCHANGE) 
00467       {
00468         char szDrive[80];
00469         int index = ComboBox_GetCurSel(hWndCtl);
00470         if(index == CB_ERR)
00471           break;
00472         ComboBox_GetLBText(hWndCtl, index, szDrive);
00473 
00474         int iCurDrive = _getdrive();
00475 Retry:
00476         HCURSOR hCursorOld = SetCursor(LoadCursor(NULL, IDC_WAIT));
00477         SetCapture(hWndDirPicker);
00478         if((0 == _chdrive((int)(szDrive[0] - 'a' + 1))) && (NULL != _getcwd(szCurDir, _MAX_PATH))) 
00479         {
00480           fillListBox(hWndDirPicker, szCurDir);
00481           ListBox_SetTopIndex(GetDlgItem(hWndDirPicker, ID_LIST_DIR), 0);
00482           SetCursor(hCursorOld);
00483           ReleaseCapture();
00484           break;
00485         }
00486         SetCursor(hCursorOld);
00487         ReleaseCapture();
00488 
00489         char szText[80];        
00490         sprintf(szText, "Cannot read drive %c:", szDrive[0]);
00491         if(IDRETRY == MessageBox(hWndDirPicker, szText, "Choose Directory", MB_ICONEXCLAMATION|MB_RETRYCANCEL))
00492           goto Retry;
00493         
00494         //Changing drives failed so restore drive and selection
00495         _chdrive(iCurDrive);
00496 
00497         sprintf(szDrive, "%c:", (char)(iCurDrive + 'a' - 1));
00498         index = ComboBox_SelectString(hWndCtl, -1, szDrive);
00499       }
00500       break;
00501     case IDOK:
00502       shutDialog(hWnd);
00503       char szString[_MAX_PATH];
00504       Edit_GetText(GetDlgItem(hWndDirPicker, ID_EDIT_DIR), szString, sizeof(szString));
00505       lstrcpy(lpszStringToReturn, szString);
00506       EndDialog(hWnd, IDOK);
00507       break;
00508     case IDCANCEL:
00509       shutDialog(hWnd);
00510       lpszStringToReturn[0] = '\0';
00511       EndDialog(hWnd, IDCANCEL);
00512       break;
00513     default:
00514       break;
00515   }
00516 }
00517 
00518 static BOOL CALLBACK DirPickDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) 
00519 {
00520   switch(msg) {
00521     case WM_INITDIALOG:
00522       onInitDialog(hWnd, (LPSTR)lParam);
00523       break;
00524     case WM_COMMAND:
00525       HANDLE_WM_COMMAND(hWnd, wParam, lParam, onCommand);
00526       break;
00527     case WM_MEASUREITEM: 
00528     {
00529       static int cyItem = -1;      //Height of a listbox item
00530       LPMEASUREITEMSTRUCT lpmis = (LPMEASUREITEMSTRUCT)lParam;
00531       if(cyItem == -1) 
00532       {
00533         HFONT hFont = (HFONT)SendMessage(hWnd, WM_GETFONT, 0, 0L);
00534         if(hFont == NULL)
00535           hFont = GetStockFont(SYSTEM_FONT);
00536         HDC hDC = GetDC(hWnd);
00537         HFONT hFontOld = SelectFont(hDC, hFont);
00538         TEXTMETRIC tm;
00539         GetTextMetrics(hDC, &tm);
00540         cyItem = max(ITEM_BITMAPHEIGHT, tm.tmHeight);
00541         SelectFont(hDC, hFontOld);
00542         ReleaseDC(hWnd, hDC);
00543       }
00544 
00545       lpmis->itemHeight = cyItem;
00546     }
00547       break;
00548     case WM_DRAWITEM:
00549       onDrawItem((LPDRAWITEMSTRUCT)lParam, ((UINT)wParam == ID_COMBO_DIR));
00550       return TRUE; // to prevent default action in listbox (drawing focus)
00551     default:
00552       return FALSE;
00553   }
00554   return TRUE;
00555 }
00556 
00557 /*
00558  * DriveType
00559  *
00560  * Purpose:
00561  *  Augments the Windows API GetDriveType with a call to the CD-ROM
00562  *  extensions to determine if a drive is a floppy, hard disk, CD-ROM,
00563  *  RAM-drive, or networked  drive.
00564  *
00565  * Parameters:
00566  *  iDrive          UINT containing the zero-based drive index
00567  *
00568  * Return Value:
00569  *  UINT            One of the following values describing the drive:
00570  *                  DRIVE_FLOPPY, DRIVE_HARD, DRIVE_CDROM, DRIVE_RAMDISK,
00571  *                  DRIVE_NETWORK.
00572  *
00573  * Copyright (c)1992 Kraig Brockschmidt, All Right Reserved
00574  * Compuserve:  70750,2344
00575  * Internet  :  kraigb@microsoft.com
00576  *
00577  */
00578 UINT DriveType(UINT iDrive) 
00579 {
00580   //Validate possible drive indices
00581   if((0 > iDrive)  || (25 < iDrive))
00582     return (UINT)-1;
00583 
00584   static char path[] = "d:\\";
00585   path[0] = 'a' + iDrive;
00586   int iType = GetDriveType(path);  
00587 
00588   /*
00589    * Under Windows NT, GetDriveType returns complete information
00590    * not provided under Windows 3.x which we now get through other
00591    * means.
00592    */
00593 
00594   return iType;
00595 }
00596 
00597 BOOL PickupDirectory(HWND hWndOwner, LPSTR lpszString) 
00598 {
00599   if(hWndOwner == NULL)
00600     hWndOwner = GetDesktopWindow();
00601   int ret = DialogBoxParam(hInst, MAKEINTRESOURCE(ID_DIALOG_CHOOSEDIR), hWndOwner, DirPickDlgProc, (LPARAM)lpszString);
00602   return (ret == IDOK);
00603 }