Annotation of os232sdk/toolkt20/c/samples/opendlg/file.c, revision 1.1

1.1     ! root        1: /*
        !             2:     FILE.C -- Open/Save As Dialog Box library routines
        !             3:    Created by Microsoft, IBM  Corporation 1990
        !             4: */
        !             5: #define  INCL_DOS
        !             6: #define  INCL_DOSQUEUES
        !             7: #include "tool.h"
        !             8: #include <string.h>
        !             9: 
        !            10: 
        !            11: /****************************************************************************\
        !            12: * This function is the Open dialog box window procedure.  It handles input,
        !            13: * allows the user to change directories, checks for legal filenames, opens
        !            14: * specified files, appends default extensions and returns the file's name.
        !            15: *
        !            16: * The return values are
        !            17: *   TDF_INVALID - Library error (internal error),
        !            18: *   TDF_NOOPEN  - User hits cancel
        !            19: *   TDF_NEWOPEN - Created new file (file left open)
        !            20: *   TDF_OLDOPEN - Opened existing file (file left open)
        !            21: \****************************************************************************/
        !            22: 
        !            23: MRESULT EXPENTRY DlgOpenWndProc(hwnd, msg, mp1, mp2)
        !            24: HWND hwnd;
        !            25: USHORT msg;
        !            26: MPARAM mp1;
        !            27: MPARAM mp2;
        !            28:     {
        !            29:     PDLF pdlf;
        !            30:     PSZ  lpchFile;
        !            31:     CHAR sz[MAX_FNAME_LEN];
        !            32: 
        !            33:     switch (msg)
        !            34:         {
        !            35:     case WM_INITDLG:
        !            36:         /* initialize dialog box */
        !            37:         DlgInitOpen(hwnd, LONGFROMMP(mp2));
        !            38: 
        !            39:         /* fill static field with path name and fill list box with
        !            40:            filenames that lMatch spec */
        !            41:         if (!DlgDirList(hwnd, ((PDLF)(mp2))->pszExt+1, ID_DIRLIST,
        !            42:                         ID_FILELIST, ID_PATH, ((PDLF)(mp2))->rgbFlags))
        !            43:             /* NOTE: shouldn't we post a message if something screws up? */
        !            44:             WinDismissDlg(hwnd, TDF_INVALID);
        !            45:         break;
        !            46: 
        !            47:     case WM_COMMAND:
        !            48:         pdlf = (PDLF) WinQueryWindowULong(hwnd, 0);
        !            49:         switch (SHORT1FROMMP(mp1))
        !            50:             {
        !            51:         case MBID_OK:
        !            52:             /* Open button pressed */
        !            53:             /* get name from edit box */
        !            54:             WinQueryWindowText(WinWindowFromID(hwnd, ID_EDIT),
        !            55:                 CBROOTNAMEMAX, (PSZ)pdlf->szFileName);
        !            56:            Upper((PSZ)pdlf->szFileName);
        !            57:             if (strlen((PSZ)pdlf->szFileName))
        !            58:                 DlgOpenName(hwnd, pdlf);
        !            59:             break;
        !            60: 
        !            61:         case MBID_CANCEL:
        !            62:             /* Cancel button pressed, dismiss dialog box */
        !            63:             WinDismissDlg(hwnd, TDF_NOOPEN);
        !            64:            break;
        !            65: 
        !            66:        case MBID_HELP:
        !            67:            /* Help button pressed */
        !            68:            WinMessageBox( HWND_DESKTOP
        !            69:                         , hwnd
        !            70:                         , pdlf->pszInstructions
        !            71:                         , pdlf->pszTitle
        !            72:                         , NULL
        !            73:                         , MB_OK | MB_APPLMODAL );
        !            74:            break;
        !            75:             }
        !            76:         break;
        !            77: 
        !            78:     case WM_CONTROL:
        !            79:         pdlf = (PDLF) WinQueryWindowULong(hwnd, 0);
        !            80:         switch (SHORT1FROMMP(mp1))
        !            81:             {
        !            82:         case ID_DIRLIST:
        !            83:             /* user clicked in directory list box */
        !            84:             switch (SHORT2FROMMP(mp1))
        !            85:                 {
        !            86:             case LN_SELECT:
        !            87:                 /* single click case */
        !            88:                 /* get current edit string */
        !            89:                 WinQueryWindowText(WinWindowFromID(hwnd, ID_EDIT),
        !            90:                                    CBROOTNAMEMAX, (PSZ)sz);
        !            91:                 Upper((PSZ)sz);
        !            92: 
        !            93:                 /* get selected string */
        !            94:                 if (DlgDirSelect(hwnd, (PSZ)pdlf->szFileName, ID_DIRLIST))
        !            95:                     {
        !            96:                     /* if edit field contains wild card, then append file
        !            97:                       part to selected directory, otherwise append
        !            98:                       last wildcard search spec */
        !            99:                     lpchFile = FileInPath((PSZ)sz);
        !           100:                    strcat( (PSZ)pdlf->szFileName
        !           101:                           , DlgSearchSpec( lpchFile)
        !           102:                             ? lpchFile
        !           103:                             : (PSZ)pdlf->szLastWild );
        !           104:                     /* set edit box to resulting name */
        !           105:                     WinSetWindowText(WinWindowFromID(hwnd, ID_EDIT),
        !           106:                                      (PSZ)pdlf->szFileName);
        !           107:                     }
        !           108:                 break;
        !           109: 
        !           110:             case LN_ENTER:
        !           111:                /* get text from edit box */
        !           112:                WinQueryWindowText(WinWindowFromID(hwnd, ID_EDIT),
        !           113:                                   CBROOTNAMEMAX, (PSZ)pdlf->szFileName);
        !           114:                Upper((PSZ)pdlf->szFileName);
        !           115:                if( DlgSearchSpec( (PSZ)pdlf->szFileName))
        !           116:                    {
        !           117:                    DlgDirList( hwnd
        !           118:                              , (PSZ)pdlf->szFileName
        !           119:                              , ID_DIRLIST
        !           120:                              , ID_FILELIST
        !           121:                              , ID_PATH
        !           122:                              , pdlf->rgbFlags );
        !           123:                    strcpy( (PSZ)pdlf->szLastWild
        !           124:                           , FileInPath( (PSZ)pdlf->szFileName));
        !           125:                    WinSetWindowText( WinWindowFromID( hwnd, ID_EDIT)
        !           126:                                    , (PSZ)pdlf->szFileName );
        !           127:                    }
        !           128:                 break;
        !           129:                 }
        !           130:             break;
        !           131: 
        !           132:         case ID_FILELIST:
        !           133:             /* user clicked in file list box */
        !           134:             switch (SHORT2FROMMP(mp1))
        !           135:                 {
        !           136:             case LN_SELECT:
        !           137:                 /* single click case */
        !           138: 
        !           139:                /* get current edit string */
        !           140:                /* if it contains a wildcard, save it before obliteration */
        !           141:                 WinQueryWindowText(WinWindowFromID(hwnd, ID_EDIT),
        !           142:                                    CBROOTNAMEMAX, (PSZ)sz);
        !           143:                Upper((PSZ)sz);
        !           144:                if( DlgSearchSpec( (PSZ)sz))
        !           145:                    strcpy( (PSZ)pdlf->szLastWild, FileInPath( (PSZ)sz));
        !           146: 
        !           147:                 /* get selected file name */
        !           148:                 DlgDirSelect(hwnd, (PSZ)pdlf->szFileName, ID_FILELIST);
        !           149:                 /* set edit box to resulting name */
        !           150:                 WinSetWindowText(WinWindowFromID(hwnd, ID_EDIT),
        !           151:                                  (PSZ)pdlf->szFileName);
        !           152:                 break;
        !           153: 
        !           154:             case LN_ENTER:
        !           155:                 /* double click case, single click already processed */
        !           156:                 DlgOpenName(hwnd, pdlf);
        !           157:                 break;
        !           158:                 }
        !           159:             break;
        !           160:             }
        !           161:         break;
        !           162: 
        !           163:     default:
        !           164:         return (WinDefDlgProc(hwnd, msg, mp1, mp2));
        !           165:         }
        !           166: 
        !           167:     return (MRFROMLONG(0L));  /* message processed */
        !           168:     }
        !           169: 
        !           170: 
        !           171: 
        !           172: 
        !           173: /****************************************************************************\
        !           174: * This function stores the pdlf in the dialog window structure, sets
        !           175: * the title and instruction texts and limits the text size.
        !           176: \****************************************************************************/
        !           177: 
        !           178: VOID PASCAL DlgInitOpen (hwnd, lpParm)
        !           179: HWND hwnd;
        !           180: ULONG lpParm;
        !           181:     {
        !           182:     PDLF pdlf;
        !           183: 
        !           184:     /* Set pdlf local to window */
        !           185:     pdlf = (PDLF) lpParm;
        !           186:     WinSetWindowULong(hwnd, 0, lpParm);
        !           187: 
        !           188:     /* set edit box text size limit */
        !           189:     WinSendDlgItemMsg(hwnd, ID_EDIT, EM_SETTEXTLIMIT, (MPARAM)CBROOTNAMEMAX, 0L);
        !           190: 
        !           191:     /* set edit window to search spec */
        !           192:     if (pdlf->pszExt != (PSZ)NULL)
        !           193:         WinSetWindowText(WinWindowFromID(hwnd, ID_EDIT), pdlf->pszExt+1);
        !           194: 
        !           195:     /* set title window */
        !           196:     if (pdlf->pszTitle != (PSZ)NULL)
        !           197:        WinSetWindowText(WinWindowFromID(hwnd, FID_TITLEBAR), pdlf->pszTitle);
        !           198:     }
        !           199: 
        !           200: 
        !           201: 
        !           202: 
        !           203: /****************************************************************************\
        !           204: * This function processes the currently selected name in the open dialog
        !           205: * box.  If the name represents a directory, the current directory is
        !           206: * changed to that one and the corresponding files are displayed.  If the
        !           207: * name is a file, then it is opened.
        !           208: \****************************************************************************/
        !           209: 
        !           210: VOID PASCAL DlgOpenName(hwnd, pdlf)
        !           211: HWND hwnd;
        !           212: PDLF pdlf;
        !           213:     {
        !           214:     PSZ  lpch;
        !           215:     USHORT wVal;
        !           216:     CHAR sz[MAX_FNAME_LEN];
        !           217: 
        !           218:     /* try using current name as a directory */
        !           219:     strcpy((PSZ)sz, (PSZ)pdlf->szFileName);
        !           220:     if (!DlgSearchSpec((PSZ)sz))
        !           221:         DlgAddSearchExt(pdlf, (PSZ)sz);
        !           222:     if (DlgDirList(hwnd, (PSZ)sz, ID_DIRLIST, ID_FILELIST, ID_PATH,
        !           223:                    pdlf->rgbFlags))
        !           224:         {
        !           225:         /* name was a directory, extract and set file name */
        !           226:         lpch = FileInPath((PSZ)sz);
        !           227:         strcpy((PSZ)pdlf->szFileName, lpch);
        !           228:         WinSetWindowText(WinWindowFromID(hwnd, ID_EDIT),
        !           229:                          (PSZ)pdlf->szFileName);
        !           230:         }
        !           231:     else
        !           232:         /* try to open name as a file */
        !           233:         if ((wVal = DlgOpenFile(pdlf, hwnd)) != TDF_NOOPEN)
        !           234:             WinDismissDlg(hwnd, wVal);
        !           235:     }
        !           236: 
        !           237: 
        !           238: 
        !           239: 
        !           240: /****************************************************************************\
        !           241: * This function is the SaveAs dialog box window procedure.  It handles input,
        !           242: * tests for legal filenames and uses message boxes to report any problems.
        !           243: *
        !           244: * Return values are:
        !           245: *     TDF_INVALID - Library error (internal error),
        !           246: *     TDF_NOOPEN  - User hits cancel
        !           247: *   Specific for DLG_NOOPEN
        !           248: *     TDF_NEWSAVE - user wants to save to a new file (file not created)
        !           249: *     TDF_OLDSAVE - user wants to save over existing file (file not opened)
        !           250: *   else
        !           251: *     TDF_NEWSAVE - user wants to save to a new file (file left open)
        !           252: *     TDF_OLDSAVE - user wants to save over existing file (file left open)
        !           253: \****************************************************************************/
        !           254: 
        !           255: MRESULT EXPENTRY DlgSaveAsWndProc(hwnd, msg, mp1, mp2)
        !           256: HWND   hwnd;
        !           257: USHORT msg;
        !           258: MPARAM mp1;
        !           259: MPARAM mp2;
        !           260:     {
        !           261:     PDLF    pdlf;
        !           262:     PSZ     lpchFile;
        !           263:     CHAR    sz[MAX_FNAME_LEN];
        !           264: 
        !           265:     switch (msg)
        !           266:         {
        !           267:     case WM_INITDLG:
        !           268:         /* Store pdlf, set instructions, limit text size */
        !           269:         DlgInitSaveAs(hwnd, LONGFROMMP(mp2));
        !           270: 
        !           271:         /* fill static field with path name and fill list box with
        !           272:            filenames that lMatch spec */
        !           273:         if (!DlgDirList(hwnd, ((PDLF)(mp2))->pszExt+1, ID_DIRLIST,
        !           274:                         ID_FILELIST, ID_PATH, ((PDLF)(mp2))->rgbFlags))
        !           275:             /* NOTE: shouldn't we post a message if something screws up? */
        !           276:             WinDismissDlg(hwnd, TDF_INVALID);
        !           277:         break;
        !           278: 
        !           279:     case WM_COMMAND:
        !           280:         pdlf = (PDLF) WinQueryWindowULong(hwnd, 0);
        !           281:         switch (SHORT1FROMMP(mp1))
        !           282:            {
        !           283:         case MBID_OK:
        !           284:             /* get text from edit box */
        !           285:             WinQueryWindowText(WinWindowFromID(hwnd, ID_EDIT),
        !           286:                                CBROOTNAMEMAX, (PSZ)pdlf->szFileName);
        !           287:            Upper((PSZ)pdlf->szFileName);
        !           288:            if( DlgSearchSpec( (PSZ)pdlf->szFileName))
        !           289:                {
        !           290:                DlgDirList( hwnd
        !           291:                          , (PSZ)pdlf->szFileName
        !           292:                          , ID_DIRLIST
        !           293:                          , ID_FILELIST
        !           294:                          , ID_PATH
        !           295:                          , pdlf->rgbFlags );
        !           296:                strcpy( (PSZ)pdlf->szLastWild
        !           297:                       , FileInPath( (PSZ)pdlf->szFileName));
        !           298:                strcpy( (PSZ)pdlf->szFileName, (PSZ)pdlf->szLastFile);
        !           299:                WinSetWindowText( WinWindowFromID( hwnd, ID_EDIT)
        !           300:                                , (PSZ)pdlf->szFileName );
        !           301:                }
        !           302:            else if( strlen( (PSZ)pdlf->szFileName))
        !           303:                DlgSaveAsName( hwnd, pdlf);
        !           304:             break;
        !           305: 
        !           306:         case MBID_CANCEL:
        !           307:             WinDismissDlg(hwnd, TDF_NOSAVE);
        !           308:             break;
        !           309: 
        !           310:        case MBID_HELP:
        !           311:            /* Help button pressed */
        !           312:            WinMessageBox( HWND_DESKTOP
        !           313:                         , hwnd
        !           314:                         , pdlf->pszInstructions
        !           315:                         , pdlf->pszTitle
        !           316:                         , NULL
        !           317:                         , MB_OK | MB_APPLMODAL );
        !           318:            break;
        !           319:             }
        !           320:         break;
        !           321: 
        !           322:     case WM_CONTROL:
        !           323:         pdlf = (PDLF) WinQueryWindowULong(hwnd, 0);
        !           324:         switch (SHORT1FROMMP(mp1))
        !           325:             {
        !           326:         case ID_DIRLIST:
        !           327:             /* user clicked in directory list box */
        !           328:             switch (SHORT2FROMMP(mp1))
        !           329:                 {
        !           330:             case LN_SELECT:
        !           331:                 /* single click case */
        !           332:                 /* get current edit string */
        !           333:                 WinQueryWindowText(WinWindowFromID(hwnd, ID_EDIT),
        !           334:                                    CBROOTNAMEMAX, (PSZ)sz);
        !           335:                 Upper((PSZ)sz);
        !           336: 
        !           337:                 /* get selected string */
        !           338:                 if (DlgDirSelect(hwnd, (PSZ)pdlf->szFileName, ID_DIRLIST))
        !           339:                     {
        !           340:                     /* if edit field contains wild card, then append file
        !           341:                       part to selected directory, otherwise append
        !           342:                       last wildcard search spec */
        !           343:                     lpchFile = FileInPath((PSZ)sz);
        !           344:                    if( DlgSearchSpec( lpchFile))
        !           345:                        {
        !           346:                        strcat( (PSZ)pdlf->szFileName, lpchFile );
        !           347:                        strcpy( (PSZ)pdlf->szLastWild, lpchFile);
        !           348:                        }
        !           349:                    else
        !           350:                        {
        !           351:                        strcat( (PSZ)pdlf->szFileName, (PSZ)pdlf->szLastWild );
        !           352:                        strcpy( (PSZ)pdlf->szLastFile, lpchFile);
        !           353:                        }
        !           354:                     /* set edit box to resulting name */
        !           355:                     WinSetWindowText(WinWindowFromID(hwnd, ID_EDIT),
        !           356:                                      (PSZ)pdlf->szFileName);
        !           357:                     }
        !           358:                 break;
        !           359: 
        !           360:             case LN_ENTER:
        !           361:                /* get text from edit box */
        !           362:                WinQueryWindowText(WinWindowFromID(hwnd, ID_EDIT),
        !           363:                                   CBROOTNAMEMAX, (PSZ)pdlf->szFileName);
        !           364:                Upper((PSZ)pdlf->szFileName);
        !           365:                if( DlgSearchSpec( (PSZ)pdlf->szFileName))
        !           366:                    {
        !           367:                    DlgDirList( hwnd
        !           368:                              , (PSZ)pdlf->szFileName
        !           369:                              , ID_DIRLIST
        !           370:                              , ID_FILELIST
        !           371:                              , ID_PATH
        !           372:                              , pdlf->rgbFlags );
        !           373:                    strcpy( (PSZ)pdlf->szLastWild
        !           374:                           , FileInPath( (PSZ)pdlf->szFileName));
        !           375:                    strcpy( (PSZ)pdlf->szFileName, (PSZ)pdlf->szLastFile);
        !           376:                    WinSetWindowText( WinWindowFromID( hwnd, ID_EDIT)
        !           377:                                    , (PSZ)pdlf->szFileName );
        !           378:                    }
        !           379:                break;
        !           380:                }
        !           381:             break;
        !           382: 
        !           383:         case ID_FILELIST:
        !           384:             /* user clicked in file list box */
        !           385:             switch (SHORT2FROMMP(mp1))
        !           386:                 {
        !           387:             case LN_SELECT:
        !           388:                 /* single click case */
        !           389: 
        !           390:                /* get current edit string */
        !           391:                /* if it contains a wildcard, save it before obliteration */
        !           392:                 WinQueryWindowText(WinWindowFromID(hwnd, ID_EDIT),
        !           393:                                    CBROOTNAMEMAX, (PSZ)sz);
        !           394:                Upper((PSZ)sz);
        !           395:                if( DlgSearchSpec( (PSZ)sz))
        !           396:                    strcpy( (PSZ)pdlf->szLastWild, FileInPath( (PSZ)sz));
        !           397: 
        !           398:                 /* get selected file name */
        !           399:                 DlgDirSelect(hwnd, (PSZ)pdlf->szFileName, ID_FILELIST);
        !           400:                 /* set edit box to resulting name */
        !           401:                 WinSetWindowText(WinWindowFromID(hwnd, ID_EDIT),
        !           402:                                  (PSZ)pdlf->szFileName);
        !           403:                 break;
        !           404: 
        !           405:             case LN_ENTER:
        !           406:                 /* double click case, single click already processed */
        !           407:                DlgSaveAsName(hwnd, pdlf);
        !           408:                 break;
        !           409:                 }
        !           410:             break;
        !           411:             }
        !           412:         break;
        !           413: 
        !           414:     default:
        !           415:         return (WinDefDlgProc(hwnd, msg, mp1, mp2));
        !           416:         }
        !           417: 
        !           418:     return (MRFROMLONG(0L));    /* message processed */
        !           419:     }
        !           420: 
        !           421: 
        !           422: 
        !           423: /******************************************************************************/
        !           424: /*                                                                           */
        !           425: /* This function attempts to open a file for writing.  It queries if over-    */
        !           426: /* write is OK if the file already exists.                                   */
        !           427: /*                                                                           */
        !           428: /******************************************************************************/
        !           429: VOID PASCAL DlgSaveAsName( hwnd, pdlf)
        !           430: HWND  hwnd;
        !           431: PDLF  pdlf;
        !           432:     {
        !           433:     USHORT  usTdf;
        !           434: 
        !           435:     /* add extension if there is not one already */
        !           436:     AddExt((PSZ)pdlf->szFileName, pdlf->pszExt);
        !           437:     /* test file name legality */
        !           438:     if (!DlgParseFile((PSZ)pdlf->szFileName,
        !           439:                      (PSZ)pdlf->szOpenFile, FALSE, FALSE))
        !           440:        {
        !           441:        /* illegal filename */
        !           442:        DlgAlertBox(hwnd, IDS_IFN, pdlf,
        !           443:                    MB_OK | MB_ICONEXCLAMATION);
        !           444:        return;
        !           445:        }
        !           446:     usTdf = TDF_NEWSAVE;
        !           447:     /* test if file already exists */
        !           448:     if (DlgParseFile((PSZ)pdlf->szFileName,
        !           449:                     (PSZ)pdlf->szOpenFile, TRUE, FALSE))
        !           450:        {
        !           451:        /* overwrite? */
        !           452:        if (DlgAlertBox(hwnd, IDS_REF, pdlf,
        !           453:                        MB_YESNO | MB_DEFBUTTON2 | MB_ICONQUESTION)
        !           454:            == MBID_NO)
        !           455:            return;
        !           456:        usTdf = TDF_OLDSAVE;
        !           457:        }
        !           458:     if (!(pdlf->rgbAction & DLG_NOOPEN) &&
        !           459:        !(OpenFile( (PSZ)pdlf->szFileName
        !           460:                  , pdlf->phFile
        !           461:                  , (PSZ)pdlf->szOpenFile
        !           462:                  , OF_WRITE)))
        !           463:        {
        !           464:        DlgAlertBox(hwnd, IDS_EOF, pdlf,
        !           465:                    MB_OK | MB_ICONEXCLAMATION);
        !           466:        return;
        !           467:        }
        !           468:     WinDismissDlg(hwnd, usTdf);
        !           469:     }
        !           470: 
        !           471: 
        !           472: 
        !           473: /****************************************************************************\
        !           474: * This function initializes the SaveAs dialog box.  It puts the current
        !           475: * directory string in the ID_PATH field and initializes the edit box
        !           476: * with the proposed filename.  It is the simple relative file name if current
        !           477: * dir == pdlf->szOpenFile.  Otherwise, it is the fully qualified name.
        !           478: \****************************************************************************/
        !           479: 
        !           480: VOID PASCAL DlgInitSaveAs (hwnd, lpParm)
        !           481: HWND hwnd;
        !           482: ULONG lpParm;
        !           483:     {
        !           484:     PDLF pdlf;
        !           485:     CHAR sz[MAX_FNAME_LEN];
        !           486:     PSZ  lpszFile, lpszFN, lpszCD;
        !           487: 
        !           488:     /* set pdlf local to window */
        !           489:     pdlf = (PDLF) lpParm;
        !           490:     WinSetWindowULong(hwnd, 0, lpParm);
        !           491: 
        !           492:     /* set edit box text size limit */
        !           493:     WinSendDlgItemMsg(hwnd, ID_EDIT, EM_SETTEXTLIMIT, (MPARAM)CBROOTNAMEMAX, 0L);
        !           494: 
        !           495:     /* set title window */
        !           496:     if (pdlf->pszTitle != (PSZ)NULL)
        !           497:        WinSetWindowText(WinWindowFromID(hwnd, FID_TITLEBAR), pdlf->pszTitle);
        !           498: 
        !           499:     /* set szLastWild to search spec */
        !           500:     if (pdlf->pszExt != (PSZ)NULL)
        !           501:        strcpy( (PSZ)pdlf->szLastWild, (PSZ)pdlf->pszExt+1 );
        !           502: 
        !           503:     /* get current directory */
        !           504:     DosSearchPath(0, (PSZ)szDot, (PSZ)szStar, (PSZ)sz, MAX_FNAME_LEN);
        !           505:     lpszFile = FileInPath((PSZ)sz);
        !           506:     if (lpszFile > (PSZ)sz + 3)
        !           507:         lpszFile--;
        !           508:     *lpszFile = '\0';
        !           509: 
        !           510:     /* compare path part name to previously opened file name and
        !           511:        make the file name relative if they are the same */
        !           512:     lpszFN = (PSZ)pdlf->szOpenFile;
        !           513:     lpszCD = (PSZ)sz;
        !           514:     lpszFile = FileInPath((PSZ)pdlf->szOpenFile);
        !           515:     while (lpszFN < lpszFile && *lpszFN == *lpszCD)
        !           516:         {
        !           517:         lpszFN = NextChar(lpszFN);
        !           518:         lpszCD = NextChar(lpszCD);
        !           519:         }
        !           520:     if (*lpszCD)
        !           521:         lpszFN = (PSZ)pdlf->szOpenFile;
        !           522:     else if (*lpszFN == '\\')
        !           523:        lpszFN = NextChar(lpszFN);
        !           524:     Upper( lpszFN);
        !           525:     WinSetWindowText(WinWindowFromID(hwnd, ID_EDIT), lpszFN);
        !           526:     strcpy( (PSZ)pdlf->szLastFile, lpszFN);
        !           527: 
        !           528:     /* set current path field */
        !           529:     WinSetWindowText(WinWindowFromID(hwnd, ID_PATH),
        !           530:                      DlgFitPathToBox(hwnd, ID_PATH, (PSZ)sz));
        !           531:     }
        !           532: 
        !           533: 
        !           534: 
        !           535: 
        !           536: /****************************************************************************\
        !           537: * This function returns the filename part of the given path string.
        !           538: \****************************************************************************/
        !           539: 
        !           540: PSZ  EXPENTRY FileInPath(lpsz)
        !           541: PSZ  lpsz;
        !           542:     {
        !           543:     PSZ  lpch;
        !           544: 
        !           545:     /* strip path/drive specification from name if there is one */
        !           546:     lpch = lpsz + strlen(lpsz);
        !           547:     while (lpch > lpsz)
        !           548:         {
        !           549:         lpch = PrevChar(lpsz, lpch);
        !           550:         if (*lpch == '\\' || *lpch == ':')
        !           551:             {
        !           552:             lpch = NextChar(lpch);
        !           553:             break;
        !           554:             }
        !           555:         }
        !           556:     return(lpch);
        !           557:     }
        !           558: 
        !           559: 
        !           560: 
        !           561: 
        !           562: /****************************************************************************\
        !           563: * This function adds the extension to a file name if it is missing.
        !           564: \****************************************************************************/
        !           565: 
        !           566: VOID EXPENTRY AddExt(lpsz, lpszExt)
        !           567: PSZ  lpsz;
        !           568: PSZ  lpszExt;
        !           569:     {
        !           570:     PSZ  lpch;
        !           571: 
        !           572:     lpch = lpsz + strlen(lpsz);
        !           573:     while (*lpch != '.' && *lpch != '\\' && *lpch != ':' && lpch > lpsz)
        !           574:         lpch = PrevChar(lpsz, lpch);
        !           575: 
        !           576:     if (*lpch != '.')
        !           577:         strcat(lpsz, (PSZ)(lpszExt+2));
        !           578:     }
        !           579: 
        !           580: 
        !           581: 
        !           582: 
        !           583: /****************************************************************************\
        !           584: * This function adds the "appropriate" extension to a filename, partial
        !           585: * filename, search spec or partial search spec.
        !           586: \****************************************************************************/
        !           587: 
        !           588: VOID PASCAL DlgAddSearchExt(pdlf, lpszEdit)
        !           589: PDLF pdlf;
        !           590: PSZ  lpszEdit;
        !           591:     {
        !           592:     PSZ  lpchLast;
        !           593: 
        !           594:     lpchLast = PrevChar(lpszEdit, lpszEdit + strlen(lpszEdit));
        !           595:     if (*lpchLast == '\\' || *lpchLast == ':')
        !           596:         strcat(lpszEdit, pdlf->pszExt + 1);
        !           597:     else
        !           598:         strcat(lpszEdit, pdlf->pszExt);
        !           599:     }
        !           600: 
        !           601: 
        !           602: 
        !           603: 
        !           604: /****************************************************************************\
        !           605: * This function returns TRUE if lpsz contains a wildcard character '*' or '?';
        !           606: \****************************************************************************/
        !           607: 
        !           608: BOOL PASCAL DlgSearchSpec(lpsz)
        !           609: PSZ  lpsz;
        !           610:    {
        !           611:     for (; *lpsz; lpsz = NextChar(lpsz))
        !           612:         if (*lpsz == '*' || *lpsz == '?')
        !           613:             return TRUE;
        !           614:     return FALSE;
        !           615:    }
        !           616: 
        !           617: 
        !           618: 
        !           619: 
        !           620: /****************************************************************************\
        !           621: * This function displays an error or warning msg.
        !           622: \****************************************************************************/
        !           623: 
        !           624: int PASCAL DlgAlertBox(hwnd, ids, pdlf, wStyle)
        !           625: HWND hwnd;
        !           626: int ids;
        !           627: PDLF pdlf;
        !           628: USHORT wStyle;
        !           629:     {
        !           630:     /* note:  5th param is idHelp */
        !           631:     return (AlertBox(hwnd, ids, (PSZ)pdlf->szFileName, pdlf->pszAppName,
        !           632:                          NULL, wStyle | MB_APPLMODAL));
        !           633:     }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.