home *** CD-ROM | disk | FTP | other *** search
- #define NOCOMM
- #include <windows.h>
- #include <dos.h>
- #include <direct.h>
- #include <memory.h>
- #include <stdlib.h>
- #include <string.h>
- #include "sfiledlg.h"
- #include "getdrvx.h"
-
- #define FATTR_DIRS (0x0010|0x4000|0x8000)
- #define FATTR_FILES (0)
-
- #define WM_SFDLG_REDRAW (WM_USER+1)
-
- #define PATHSIZE (128)
- #define NDRIVETYPES (7)
-
- /* Function Prototypes */
- int FAR PASCAL _export SFileDlgProc(HWND hDlg, WORD wMsg, WORD wParam,
- LONG lParam);
- void FNameSplit(LPSTR lpszSrcFName, LPSTR lpszDstPath, LPSTR lpszDstFName);
- int DriveNo(LPSTR str);
- BOOL GetVolumeLabel(int nDrive, LPSTR lpszLabel);
- BOOL GetCurDir(int nDrive, LPSTR lpszCurDir);
- BOOL IsDir(LPSTR str);
- BOOL IsWild(LPSTR str);
- BOOL DoWmInitDialog(HWND hDlg, WORD wMsg, WORD wParam, LONG lParam);
- BOOL DoWmDestroy(HWND hDlg, WORD wMsg, WORD wParam, LONG lParam);
- BOOL DoWmSFDlgRedraw(HWND hDlg, WORD wMsg, WORD wParam, LONG lParam);
- BOOL DoWmDrawItem(HWND hDlg, WORD wMsg, WORD wParam, LONG lParam);
- BOOL DoWmMeasureItem(HWND hDlg, WORD wMsg, WORD wParam, LONG lParam);
- BOOL DoCmdOk(HWND hDlg, WORD wParam, LONG lParam);
- BOOL DoCmdCancel(HWND hDlg, WORD wParam, LONG lParam);
- BOOL DoCmdFileName(HWND hDlg, WORD wParam, LONG lParam);
- BOOL DoCmdDirs(HWND hDlg, WORD wParam, LONG lParam);
- BOOL DoCmdTypes(HWND hDlg, WORD wParam, LONG lParam);
-
- /* Types */
- typedef struct {
- HANDLE hImage;
- HANDLE hMask;
- } DrivesBmp;
-
- typedef struct {
- int idImage;
- int idMask;
- } DrivesId;
-
- /* Global variables that remain for the life of the DLL */
- DrivesBmp _dr_bmp[NDRIVETYPES];
- DrivesId _dr_id[NDRIVETYPES] = {
- {BMP_FOLDER, BMP_FOLDERM},
- {BMP_REMOVE, BMP_REMOVEM},
- {BMP_FIXED, BMP_FIXEDM },
- {BMP_REMOTE, BMP_REMOTEM},
- {BMP_CDROM, BMP_CDROMM },
- {BMP_RAM, BMP_RAMM },
- {BMP_SUBST, BMP_SUBSTM }
- };
-
- /*
- For drives A: to Z:, _pdr_bmp[1] to _pdr_bmp[26] contain pointers into
- the drive types bitmap array _dr_bmp (_pdr_bmp[0] points to the
- folder bitmap).
- */
- DrivesBmp* _pdr_bmp[27];
- char _dr_path[27][PATHSIZE];
-
- short _nBmWidth;
- short _nBmHeight;
- HDC _hBitmapDC;
- HBRUSH _hBrSelect;
-
- HANDLE _hLibInstance;
- LPSTR _lpszProperty = "STRUCT_SFDLG";
-
- /* Global variables used as scratch buffers */
- char _szDir[PATHSIZE];
- char _szName[PATHSIZE];
-
- int FAR PASCAL LibMain(HANDLE hLibInstance, WORD wDataSeg, WORD wHeapSize,
- LPSTR lpszCmdLine)
- {
- int i;
- BITMAP bm;
-
- if (wHeapSize > 0)
- UnlockData(0);
-
- _hLibInstance = hLibInstance;
-
- // Load bitmaps
- for (i=0; i<NDRIVETYPES; ++i)
- {
- _dr_bmp[i].hImage =
- LoadBitmap(_hLibInstance, MAKEINTRESOURCE(_dr_id[i].idImage));
- _dr_bmp[i].hMask =
- LoadBitmap(_hLibInstance, MAKEINTRESOURCE(_dr_id[i].idMask));
-
- if (!_dr_bmp[i].hImage || !_dr_bmp[i].hMask)
- {
- MessageBeep(0);
- return 0;
- }
- }
-
- // Load other resources
- _hBitmapDC = CreateCompatibleDC(NULL);
- _hBrSelect = CreateSolidBrush( GetSysColor(COLOR_HIGHLIGHT) );
-
- // Set all bitmaps to the folder
- for (i=0; i<=26; ++i)
- _pdr_bmp[i] = &_dr_bmp[0];
-
- // Initialize drive array
- for (i=1; i<=26; ++i)
- {
- int idBmp;
- int j;
- char ch;
- static char pathbuf[PATHSIZE];
-
- switch (GetDriveTypeX(i-1))
- {
- case DRIVE_REMOVE: idBmp = BMP_REMOVE; break;
- case DRIVE_FIXED: idBmp = BMP_FIXED; break;
- case DRIVE_REMOTE: idBmp = BMP_REMOTE; break;
- case DRIVE_CDROM: idBmp = BMP_CDROM; break;
- case DRIVE_RAM: idBmp = BMP_RAM; break;
- case DRIVE_SUBST: idBmp = BMP_SUBST; break;
- default: idBmp = BMP_FIXED;
- }
-
- for (j=0; j<NDRIVETYPES; ++j)
- if (idBmp == _dr_id[j].idImage)
- {
- _pdr_bmp[i] = &_dr_bmp[j];
- break;
- }
-
- ch = 'a' + (char)i - 1;
-
- wsprintf(_dr_path[i], "%c:", ch);
-
- if (idBmp == BMP_REMOTE || idBmp == BMP_SUBST)
- {
- wsprintf(pathbuf, "%c:.", ch);
- if (GetCanonicalPath(pathbuf, pathbuf))
- wsprintf(_dr_path[i], "%c: %s", ch, (LPSTR) AnsiLower(pathbuf));
- }
- else
- if (idBmp == BMP_FIXED || idBmp == BMP_RAM)
- {
- if (GetVolumeLabel(i, pathbuf))
- wsprintf(_dr_path[i], "%c: %s", ch, (LPSTR) pathbuf);
- }
-
- }
-
- GetObject(_dr_bmp[0].hImage, sizeof (BITMAP), (LPSTR) &bm);
- _nBmWidth = bm.bmWidth;
- _nBmHeight = bm.bmHeight;
-
- return 1;
- }
-
- int FAR PASCAL _export WEP(int nParameter)
- {
- int i;
-
- DeleteObject(_hBrSelect);
- DeleteDC(_hBitmapDC);
-
- for (i=0; i<NDRIVETYPES; ++i)
- {
- DeleteObject(_dr_bmp[i].hImage);
- DeleteObject(_dr_bmp[i].hMask);
- }
-
- return 1;
- }
-
-
- /****************************************************************************
- int FAR PASCAL SFileDlg(SFDlg FAR* sfdlg)
-
- PURPOSE: Interface routine to the File dialog box
-
- PARAMETERS: struct SFDlg FAR* sfdlg (see SFILEDLG.H)
-
- RETURNS: 1 File selected, 0 No file selected
-
- NOTES: On return, sfdlg->FileSpec contains the selected filename.
- ****************************************************************************/
- int FAR PASCAL _export SFileDlg(SFDlg FAR* sfdlg)
- {
- FARPROC lpfnSFileDlgProc;
- BOOL nReturn;
- HANDLE hSFDlg;
- SFDlg FAR* lpSFDlg;
-
- if (sfdlg->lpszTitle == NULL || *sfdlg->lpszTitle == '\0')
- sfdlg->lpszTitle = "Get File";
-
- FNameSplit(sfdlg->lpszFileSpec, _szDir, _szName);
-
- // If no filename is given, use default type name
- if (*_szName == '\0')
- {
- lstrcpy(_szName, sfdlg->lpTypes[sfdlg->nType].szFile);
- lstrcpy(sfdlg->lpszFileSpec, _szName);
- }
-
- // If no path is given, use current directory as path
- if (*_szDir == '\0')
- {
- GetCurDir(0, sfdlg->lpszFileSpec);
- lstrcat(sfdlg->lpszFileSpec, _szName);
- }
-
- // Create a structure accessible to the dialog box
- hSFDlg = GlobalAlloc(GHND, sizeof (SFDlg));
- if ((lpSFDlg = (SFDlg FAR*) GlobalLock(hSFDlg)) == NULL)
- {
- MessageBeep(0);
- return 0;
- }
- *lpSFDlg = *sfdlg;
-
- // Call the dialog box, initializing it with the structure handle
- lpfnSFileDlgProc = MakeProcInstance((FARPROC) SFileDlgProc, _hLibInstance);
- nReturn = DialogBoxParam(_hLibInstance, "DLG_SFILEDLG", sfdlg->hWnd,
- lpfnSFileDlgProc, hSFDlg);
- FreeProcInstance(lpfnSFileDlgProc);
-
- *sfdlg = *lpSFDlg;
-
- GlobalUnlock(hSFDlg);
- GlobalFree(hSFDlg);
-
- return nReturn;
- }
-
-
- /****************************************************************************
- int FAR PASCAL SFileDlgProc(HWND hDlg, WORD wMsg, WORD wParam,
- LONG lParam)
-
- PURPOSE: File dialog box Windows callback function
-
- RETURNS: TRUE if message was processed
- ****************************************************************************/
- int FAR PASCAL _export SFileDlgProc(HWND hDlg, WORD wMsg, WORD wParam,
- LONG lParam)
- {
- switch(wMsg)
- {
- case WM_INITDIALOG :
- return DoWmInitDialog(hDlg, wMsg, wParam, lParam);
-
- case WM_DESTROY:
- return DoWmDestroy(hDlg, wMsg, wParam, lParam);
-
- case WM_MEASUREITEM:
- return DoWmMeasureItem(hDlg, wMsg, wParam, lParam);
-
- case WM_DRAWITEM:
- return DoWmDrawItem(hDlg, wMsg, wParam, lParam);
-
- case WM_SFDLG_REDRAW:
- return DoWmSFDlgRedraw(hDlg, wMsg, wParam, lParam);
-
- case WM_COMMAND :
- switch(wParam)
- {
- case IDOK :
- return DoCmdOk(hDlg, wParam, lParam);
-
- case IDCANCEL :
- return DoCmdCancel(hDlg, wParam, lParam);
-
- case IDD_FILENAME:
- return DoCmdFileName(hDlg, wParam, lParam);
-
- case IDD_DIRS:
- return DoCmdDirs(hDlg, wParam, lParam);
-
- case IDD_TYPES:
- return DoCmdTypes(hDlg, wParam, lParam);
- }
- }
-
- return FALSE;
- }
-
- ////////////////////////////////////////////////////////////////////////
- // SFileDlgProc message handlers
- ////////////////////////////////////////////////////////////////////////
- BOOL DoWmInitDialog(HWND hDlg, WORD wMsg, WORD wParam, LONG lParam)
- {
- int i;
- SFDlg FAR* lpSFDlg;
-
- // Attach the data handle to a property
- SetProp(hDlg, _lpszProperty, (WORD) lParam);
- lpSFDlg = (SFDlg FAR*) GlobalLock((HANDLE) lParam);
-
- // Set window title
- SetWindowText(hDlg, lpSFDlg->lpszTitle);
-
- // Add file type descriptions to TYPES listbox
- for (i=0; *lpSFDlg->lpTypes[i].szFile; ++i)
- {
- SendDlgItemMessage(hDlg, IDD_TYPES, CB_ADDSTRING,
- NULL, (LONG) (LPSTR) lpSFDlg->lpTypes[i].szDesc);
- }
-
- GlobalUnlock((HANDLE) lParam);
-
- // Update list box
- SendMessage(hDlg, WM_SFDLG_REDRAW, 0, 0L);
-
- SetFocus(GetDlgItem(hDlg, IDD_FILENAME));
- return TRUE;
- }
-
- BOOL DoWmDestroy(HWND hDlg, WORD wMsg, WORD wParam, LONG lParam)
- {
- RemoveProp(hDlg, _lpszProperty);
- return TRUE;
- }
-
- BOOL DoWmSFDlgRedraw(HWND hDlg, WORD wMsg, WORD wParam, LONG lParam)
- {
- HANDLE hSFDlg;
- SFDlg FAR* lpSFDlg;
-
- hSFDlg = GetProp(hDlg, _lpszProperty);
- lpSFDlg = (SFDlg FAR*) GlobalLock(hSFDlg);
-
- FNameSplit(lpSFDlg->lpszFileSpec, _szDir, _szName);
-
- // Fill DIRECTORIES listbox
- if (!DlgDirList(hDlg, _szDir, IDD_DIRS, IDD_PATH, FATTR_DIRS))
- {
- MessageBeep(0);
-
- // Invalid directory, try again using root
- lstrcpy(_szDir, "\\");
- DlgDirList(hDlg, _szDir, IDD_DIRS, IDD_PATH, FATTR_DIRS);
- }
-
- // Fill FILES list combo box
- DlgDirListComboBox(hDlg, _szName, IDD_FILENAME, 0, FATTR_FILES);
-
- // Set string in FILES edit combo box
- SendDlgItemMessage(hDlg, IDD_FILENAME, EM_LIMITTEXT, PATHSIZE, 0L);
- SetDlgItemText(hDlg, IDD_FILENAME, _szName);
-
- // Make selection in TYPES listbox
- SendDlgItemMessage(hDlg, IDD_TYPES, LB_SELECTSTRING, -1,
- (LONG) (LPSTR) lpSFDlg->lpTypes[lpSFDlg->nType].szDesc);
-
- GlobalUnlock(hSFDlg);
- return TRUE;
- }
-
- void DrawDirItem(HWND hDlg, LPDRAWITEMSTRUCT ds)
- {
- int nOldBkMode;
- DWORD dwOldColor;
- int nDriveNo;
- HBITMAP hOldBitmap;
-
- SendDlgItemMessage(hDlg, IDD_DIRS, LB_GETTEXT, ds->itemID,
- (LONG) (LPSTR) _szDir);
- nDriveNo = DriveNo(_szDir);
-
- // Draw the bitmap mask
- hOldBitmap = SelectObject(_hBitmapDC, _pdr_bmp[nDriveNo]->hMask);
- BitBlt(ds->hDC, 1, ds->rcItem.top, _nBmWidth, _nBmHeight, _hBitmapDC,
- 0, 0, SRCAND);
-
- // Draw the bitmap image
- SelectObject(_hBitmapDC, _pdr_bmp[nDriveNo]->hImage);
- BitBlt(ds->hDC, 1, ds->rcItem.top, _nBmWidth, _nBmHeight, _hBitmapDC,
- 0, 0, SRCPAINT);
-
- SelectObject(_hBitmapDC, hOldBitmap);
-
- nOldBkMode = SetBkMode(ds->hDC, TRANSPARENT);
- dwOldColor = GetTextColor(ds->hDC);
-
- // Draw text for item
- SetTextColor(ds->hDC, GetSysColor( (ds->itemState & ODS_SELECTED) ?
- COLOR_HIGHLIGHTTEXT: COLOR_WINDOWTEXT));
- if (nDriveNo == 0)
- TextOut(ds->hDC, _nBmWidth+5, ds->rcItem.top, _szDir, lstrlen(_szDir));
- else
- TextOut(ds->hDC, _nBmWidth+5, ds->rcItem.top, _dr_path[nDriveNo],
- lstrlen(_dr_path[nDriveNo]));
-
- SetTextColor(ds->hDC, dwOldColor);
- SetBkMode(ds->hDC, nOldBkMode);
- }
-
- BOOL DoWmDrawItem(HWND hDlg, WORD wMsg, WORD wParam, LONG lParam)
- {
- LPDRAWITEMSTRUCT ds = (LPDRAWITEMSTRUCT) lParam;
-
- if (ds->CtlID == IDD_DIRS)
- {
- switch (ds->itemAction)
- {
- case ODA_SELECT:
- case ODA_DRAWENTIRE:
- // Draw or erase selection bar
- FillRect(ds->hDC, &(ds->rcItem), (ds->itemState & ODS_SELECTED) ?
- _hBrSelect: GetStockObject(WHITE_BRUSH));
- DrawDirItem(hDlg, ds);
- return TRUE;
-
- case ODA_FOCUS:
- if ((ds->itemState & ODS_FOCUS) == ODS_FOCUS)
- DrawFocusRect(ds->hDC, &(ds->rcItem));
- else
- {
- // Erase selection bar and focus rect
- FillRect(ds->hDC, &(ds->rcItem), GetStockObject(WHITE_BRUSH));
- DrawDirItem(hDlg, ds);
- }
- return TRUE;
- }
- }
-
- return FALSE;
- }
-
- BOOL DoWmMeasureItem(HWND hDlg, WORD wMsg, WORD wParam, LONG lParam)
- {
- LPMEASUREITEMSTRUCT ms = (LPMEASUREITEMSTRUCT) lParam;
-
- if (ms->CtlID == IDD_DIRS)
- {
- HWND hWndDir;
- RECT rcDir;
-
- // Width of an item is the width of the directory listbox
- hWndDir = GetDlgItem(hDlg, IDD_DIRS);
- GetWindowRect(hWndDir, &rcDir);
- ms->itemWidth = rcDir.right;
-
- // Height of an item is the height of the first bitmap
- ms->itemHeight = _nBmHeight;
-
- return TRUE;
- }
- return FALSE;
- }
-
- BOOL DoCmdOk(HWND hDlg, WORD wParam, LONG lParam)
- {
- BOOL bEnd = TRUE; // assume that the file name is OK
- HANDLE hSFDlg;
- SFDlg FAR* lpSFDlg;
-
- hSFDlg = GetProp(hDlg, _lpszProperty);
- lpSFDlg = (SFDlg FAR*) GlobalLock(hSFDlg);
-
- GetDlgItemText(hDlg, IDD_FILENAME, lpSFDlg->lpszFileSpec,
- lpSFDlg->nMaxFileSpec);
-
- // If the name is a directory, append the default file name
- if (IsDir(lpSFDlg->lpszFileSpec))
- lstrcat(lpSFDlg->lpszFileSpec, lpSFDlg->lpTypes[lpSFDlg->nType].szFile);
-
- // Check for wildcards
- if (IsWild(lpSFDlg->lpszFileSpec))
- bEnd = FALSE;
-
- // Add path if necessary
- FNameSplit(lpSFDlg->lpszFileSpec, _szDir, _szName);
- if (*_szDir == '\0')
- {
- GetCurDir(0, _szDir);
- lstrcat(lstrcpy(lpSFDlg->lpszFileSpec, _szDir), _szName);
- }
-
- GlobalUnlock(hSFDlg);
-
- if (bEnd)
- EndDialog(hDlg, IDOK);
- else
- SendMessage(hDlg, WM_SFDLG_REDRAW, 0, 0L);
-
- return TRUE;
- }
-
- BOOL DoCmdCancel(HWND hDlg, WORD wParam, LONG lParam)
- {
- EndDialog(hDlg, IDCANCEL);
- return TRUE;
- }
-
- BOOL DoCmdFileName(HWND hDlg, WORD wParam, LONG lParam)
- {
- switch (HIWORD(lParam))
- {
- case LBN_DBLCLK:
- // Fake click on the OK button
- SendMessage(hDlg, WM_COMMAND, IDOK, 0L);
- return TRUE;
- }
- return FALSE;
- }
-
- BOOL DoCmdDirs(HWND hDlg, WORD wParam, LONG lParam)
- {
- HANDLE hSFDlg;
- SFDlg FAR* lpSFDlg;
-
- switch (HIWORD(lParam))
- {
- case LBN_SELCHANGE:
- // Put directory selection in FILES edit combo box
- DlgDirSelect(hDlg, _szDir, IDD_DIRS);
- SetDlgItemText(hDlg, IDD_FILENAME, _szDir);
- return TRUE;
-
- case LBN_DBLCLK:
- hSFDlg = GetProp(hDlg, _lpszProperty);
- lpSFDlg = (SFDlg FAR*) GlobalLock(hSFDlg);
-
- FNameSplit(lpSFDlg->lpszFileSpec, _szDir, _szName);
-
- // Get new directory
- if (DlgDirSelect(hDlg, _szDir, IDD_DIRS))
- lstrcpy(lpSFDlg->lpszFileSpec, _szDir);
- else
- *(lpSFDlg->lpszFileSpec) = '\0';
-
- // Append current file selection
- lstrcat(lpSFDlg->lpszFileSpec, _szName);
-
- GlobalUnlock(hSFDlg);
-
- // Update list box
- SendMessage(hDlg, WM_SFDLG_REDRAW, 0, 0L);
- return TRUE;
- }
-
- return FALSE;
- }
-
- BOOL DoCmdTypes(HWND hDlg, WORD wParam, LONG lParam)
- {
- HANDLE hSFDlg;
- SFDlg FAR* lpSFDlg;
-
- switch (HIWORD(lParam))
- {
- int nType;
-
- case LBN_SELCHANGE:
- hSFDlg = GetProp(hDlg, _lpszProperty);
- lpSFDlg = (SFDlg FAR*) GlobalLock(hSFDlg);
-
- // Get new file type
- nType = (int) SendDlgItemMessage(hDlg,IDD_TYPES,CB_GETCURSEL,0,0L);
- if (nType != LB_ERR)
- {
- // Use the file type as file name
- lstrcpy(lpSFDlg->lpszFileSpec, lpSFDlg->lpTypes[nType].szFile);
- lpSFDlg->nType = nType;
-
- // Update edit combo box
- SetDlgItemText(hDlg, IDD_FILENAME, lpSFDlg->lpszFileSpec);
-
- // Fake a click on the OK button
- SendMessage(hDlg, WM_COMMAND, IDOK, 0L);
- }
-
- GlobalUnlock(hSFDlg);
- return TRUE;
- }
- return FALSE;
- }
-
- ////////////////////////////////////////////////////////////////////////
- // End SFileDlgProc handlers
- ////////////////////////////////////////////////////////////////////////
-
- void FNameSplit(LPSTR lpszSrcFName, LPSTR lpszDstPath, LPSTR lpszDstFName)
- {
- LPSTR lpStr;
-
- lpStr = lpszSrcFName + lstrlen(lpszSrcFName);
-
- // Search for the last occurrance of ':' or '\'
- while (lpStr > lpszSrcFName && *lpStr != ':' && *lpStr != '\\')
- --lpStr;
-
- if (lpStr == lpszSrcFName && *lpStr != '\\') // No path was given
- {
- lstrcpy(lpszDstFName, lpszSrcFName);
- *lpszDstPath = 0;
- }
- else
- {
- lstrcpy(lpszDstFName, lpStr+1);
- _fmemcpy(lpszDstPath, lpszSrcFName, lpStr-lpszSrcFName+1);
- lpszDstPath[lpStr-lpszSrcFName+1] = '\0';
- }
- }
-
- /****************************************************************************
- BOOL GetVolumeLabel(int nDrive, LPSTR lpszLabel)
-
- PURPOSE: Get the drive volume label.
-
- PARAMETERS: int nDrive drive number
- LPSTR lpszLabel buffer to hold the drive label
-
- RETURNS: TRUE on success
- *****************************************************************************/
- BOOL GetVolumeLabel(int nDrive, LPSTR lpszLabel)
- {
- static struct find_t ftBuf;
- static char buf[10];
- static char file[_MAX_FNAME];
- static char ext[_MAX_EXT];
-
- wsprintf(buf, "%c:\\*.*", 'a'+nDrive-1);
-
- if (_dos_findfirst(buf, _A_VOLID, &ftBuf) != 0)
- return FALSE;
-
- _splitpath(ftBuf.name, NULL, NULL, file, ext);
-
- lstrcpy(lpszLabel, file);
- if (*ext)
- lstrcat(lpszLabel, ext+1); // copy extension w/o the "."
-
- return TRUE;
- }
-
- /****************************************************************************
- BOOL GetCurDir(int nDrive, LPSTR CurDir)
-
- PURPOSE: Get the current directory.
-
- PARAMETERS: int nDrive drive number
- LPSTR lpszCurDir buffer to hold the directory name
-
- RETURNS: TRUE on success
- *****************************************************************************/
- BOOL GetCurDir(int nDrive, LPSTR lpszCurDir)
- {
- static BYTE d;
- LPSTR lpszDir;
-
- lpszDir = lpszCurDir;
-
- if ((d = (BYTE)nDrive)== 0)
- {
- // get current drive
- _asm mov ah, 0x19;
- _asm int 0x21;
- _asm mov d, al; // 0=A:,1=B:,2=C:...
- }
-
- *lpszDir++ = d + 'a';
- *lpszDir++ = ':';
- *lpszDir++ = '\\';
-
- ++d; // 0=default,1=A:,2=B:,...
- _asm push ds;
- _asm mov ah, 0x47;
- _asm mov dl, d;
- _asm lds si, lpszDir;
- _asm int 0x021;
- _asm pop ds;
- _asm jc gcw1; // error
-
- if (*(lpszDir+lstrlen(lpszDir)-1) != '\\')
- lstrcat(lpszDir, "\\");
- return TRUE;
-
- gcw1:
- *lpszCurDir = '\0';
- return FALSE;
- }
-
- /****************************************************************************
- int DriveNo(LPSTR lpStr)
-
- PURPOSE: Get a number representing a drive.
-
- PARAMETERS: LPSTR lpDriveStr A string in the format "[-x-]"
- where x is a drive letter a-z.
-
- RETURNS: An integer from 1 to 26 for valide drive strings, or 0 on error
- *****************************************************************************/
- int DriveNo(LPSTR lpDriveStr)
- {
- LPSTR lpStr;
-
- return (*(lpStr = AnsiNext(lpDriveStr)) == '-') ?
- (*AnsiNext(AnsiLower(lpStr))) - 'a' + 1 : 0;
- }
-
- BOOL IsDir(LPSTR lpStr)
- {
- char last_char;
-
- // if the name ends with a ':' or '\' then it is a directory
- last_char = *AnsiPrev(lpStr, lpStr+lstrlen(lpStr));
- return (last_char == ':' || last_char == '\\') ? TRUE: FALSE;
- }
-
- BOOL IsWild(LPSTR lpStr)
- {
- return (_fstrpbrk(lpStr, "*?") != 0) ? TRUE: FALSE;
- }
-
-
-