Annotation of os232sdk/toolkt20/c/samples/style/sty_file.c, revision 1.1

1.1     ! root        1: /*==============================================================*\
        !             2:  *  File.c - routines for handling the standard file menu
        !             3:  *                  commands
        !             4:  *      Created 1990, Microsoft, IBM  Corp.
        !             5:  *--------------------------------------------------------------
        !             6:  *
        !             7:  *  This module contains the code for the WM_COMMAND messages
        !             8:  *  posted by the standard File menu.
        !             9:  *
        !            10:  *--------------------------------------------------------------
        !            11:  *
        !            12:  *  This source file contains the following functions:
        !            13:  *
        !            14:  *           FileNew(mp2);
        !            15:  *           FileOpen(mp2);
        !            16:  *           FileSave(mp2);
        !            17:  *           FileSaveAs(mp2);
        !            18:  *           FilePrint(mp2);
        !            19:  *           FilePageSetup(mp2);
        !            20:  *           FilePrintSetup(mp2);
        !            21:  *           FileExit(mp2);
        !            22:  *           WriteFileToDisk(hf);
        !            23:  *           GetFileName();
        !            24:  *           UpdateTitleText(hwnd);
        !            25:  *
        !            26: \*==============================================================*/
        !            27: 
        !            28: /*--------------------------------------------------------------*\
        !            29:  *  Include files, macros, defined constants, and externs
        !            30: \*--------------------------------------------------------------*/
        !            31: 
        !            32: #define INCL_WINFRAMEMGR
        !            33: #define INCL_WINSWITCHLIST
        !            34: #define INCL_WINMLE
        !            35: #define INCL_WINSTDFILE
        !            36: 
        !            37: 
        !            38: /* The comments around this line should be removed when the import/export
        !            39:     bug in MLEs is fixed */
        !            40: /* #define MLE_BUGS_FIXED */
        !            41: 
        !            42: #include <os2.h>
        !            43: #include <string.h>
        !            44: #include "sty_main.h"
        !            45: #include "sty_xtrn.h"
        !            46: #include "sty_dlg.h"
        !            47: 
        !            48: /*--------------------------------------------------------------*\
        !            49:  *  Global variables
        !            50: \*--------------------------------------------------------------*/
        !            51: 
        !            52: CHAR szFullPath[CCHMAXPATH] = "";
        !            53: 
        !            54: /*--------------------------------------------------------------*\
        !            55:  *  Entry point declarations
        !            56: \*--------------------------------------------------------------*/
        !            57: 
        !            58: 
        !            59: /****************************************************************\
        !            60:  *  New file routine
        !            61:  *--------------------------------------------------------------
        !            62:  *
        !            63:  *  Name:   FileNew(mp2)
        !            64:  *
        !            65:  *  Purpose: Processes the File menu's New item
        !            66:  *
        !            67:  *  Usage:  called whenever New from the File menu is selected
        !            68:  *
        !            69:  *  Method:
        !            70:  *
        !            71:  *
        !            72:  *  Returns:
        !            73:  *
        !            74: \****************************************************************/
        !            75: VOID FileNew(mp2)
        !            76: MPARAM mp2;         /* second parameter of WM_COMMAND message */
        !            77: {
        !            78:     SHORT sT;
        !            79: 
        !            80:     /*--------------------------------------------------------------*\
        !            81:      *  Enter routines for creating a new file and window
        !            82:     \*--------------------------------------------------------------*/
        !            83: 
        !            84:     /* save file if changed */
        !            85:     if(WinSendMsg(hwndMLE, MLM_QUERYCHANGED, NULL, NULL))  {
        !            86:         sT = MessageBox(hwndMLE,
        !            87:                         IDMSG_OVERWRITEFILE,
        !            88:                         MB_QUERY | MB_YESNOCANCEL,
        !            89:                         FALSE);
        !            90: 
        !            91: 
        !            92:         if(sT == MBID_CANCEL)   /* if user cancels the New, then return */
        !            93:             return;
        !            94: #ifdef MLE_BUGS_FIXED
        !            95:         else
        !            96:             if(sT == MBID_YES)
        !            97:                 FileSave(NULL);
        !            98: #endif
        !            99:             /* if sT == MBID_NO, continue with New File processing */
        !           100: 
        !           101: 
        !           102:     }
        !           103: 
        !           104:     /* disable redrawing of the MLE so the text doesn't "flash" when
        !           105:         the MLE is cleared */
        !           106:     WinSendMsg(hwndMLE, MLM_DISABLEREFRESH, NULL, NULL);
        !           107: 
        !           108:     /* clear the MLE by selecting all of the text and clearing it */
        !           109:     WinSendMsg(hwndMLE,
        !           110:                MLM_SETSEL,
        !           111:                MPFROMSHORT(NULL),
        !           112:                (MPARAM)WinSendMsg(hwndMLE, MLM_QUERYTEXTLENGTH, NULL, NULL));
        !           113: 
        !           114:     WinSendMsg(hwndMLE, MLM_CLEAR, NULL, NULL);
        !           115: 
        !           116:     /* reset the changed flag */
        !           117:     WinSendMsg(hwndMLE, MLM_SETCHANGED, MPFROMSHORT((BOOL)FALSE), NULL);
        !           118: 
        !           119:     /* enable redrawing of the MLE */
        !           120:     WinSendMsg(hwndMLE, MLM_ENABLEREFRESH, NULL, NULL);
        !           121: 
        !           122:     /* reset file name to NULL and update the main title bar*/
        !           123:     szFullPath[0] = 0;
        !           124:     UpdateTitleText(hwndMainFrame);
        !           125: 
        !           126: 
        !           127:     /* This routine currently doesn't use the mp2 parameter but       *\
        !           128:      *  it is referenced here to prevent an 'Unreferenced Parameter'
        !           129:     \*  warning at compile time.                                      */
        !           130:     mp2;
        !           131: 
        !           132: }   /* FileNew() */
        !           133: 
        !           134: 
        !           135: #ifdef MLE_BUGS_FIXED
        !           136: 
        !           137: 
        !           138: /****************************************************************\
        !           139:  *  Open file routine
        !           140:  *--------------------------------------------------------------
        !           141:  *
        !           142:  *  Name:   FileOpen(mp2)
        !           143:  *
        !           144:  *  Purpose: Processes the File menu's Open item.
        !           145:  *
        !           146:  *  Usage:  called whenever New from the File menu is selected
        !           147:  *
        !           148:  *  Method:  calls the standard file open dialog to get the
        !           149:  *          file name.  The file name is passed onto DosOpen
        !           150:  *          which returns the handle to the file.  The file
        !           151:  *          input procedure is called and then the file handle
        !           152:  *          is closed.
        !           153:  *
        !           154:  *  Returns:
        !           155:  *
        !           156: \****************************************************************/
        !           157: VOID FileOpen(mp2)
        !           158: MPARAM mp2;     /* second parameter of WM_COMMAND message */
        !           159: {
        !           160:     FILEDLG fdg;
        !           161:     HFILE hfIn;
        !           162:     ULONG ulAction;
        !           163:     FILESTATUS fstsInfo;
        !           164:     PVOID pvBuf;
        !           165:     CHAR szTitle[MESSAGELEN], szButton[MESSAGELEN];
        !           166: 
        !           167:     fdg.cbsize = sizeof(FILEDLG);
        !           168: 
        !           169:     if(!WinLoadString(hab, NULL, IDS_OPENDLGTITLE, MESSAGELEN, szTitle))  {
        !           170:         MessageBox(hwndMain, IDMSG_CANNOTLOADSTRING, MB_OK | MB_ERROR, TRUE);
        !           171:         return;
        !           172:     }
        !           173: 
        !           174:     if(!WinLoadString(hab, NULL, IDS_OPENDLGBUTTON, MESSAGELEN, szButton))  {
        !           175:         MessageBox(hwndMain, IDMSG_CANNOTLOADSTRING, MB_OK | MB_ERROR, TRUE);
        !           176:         return;
        !           177:     }
        !           178: 
        !           179:     fdg.usDialogType = OPEN_DIALOG;
        !           180:     fdg.pszTitle = szTitle;
        !           181:     fdg.pszOKButton = szButton;
        !           182:     fdg.lUser = 0L;
        !           183:     fdg.fl = FDS_HELPBUTTON | FDS_CENTER;
        !           184:     fdg.pfnDlgProc = NULL;
        !           185:     fdg.lReturn = 0L;
        !           186:     fdg.lSRC = 0L;
        !           187:     fdg.hmod = NULL;
        !           188:     fdg.idDlg = IDD_FILEOPEN;
        !           189:     fdg.x = 0;
        !           190:     fdg.y = 0;
        !           191: 
        !           192:     if(!WinLoadString(hab,
        !           193:                       NULL,
        !           194:                       IDS_FILEOPENEXT,
        !           195:                       CCHMAXPATH,
        !           196:                       fdg.szFullFile))  {
        !           197: 
        !           198:         MessageBox(hwndMain, IDMSG_CANNOTLOADSTRING, MB_OK | MB_ERROR, TRUE);
        !           199:         return;
        !           200:     }
        !           201: 
        !           202:     fdg.pszIType = 0L;
        !           203:     fdg.ppszITypeList = 0L;
        !           204:     fdg.pszIDrive = 0L;
        !           205:     fdg.ppszIDriveList = 0L;
        !           206:     fdg.sEAType = 0;
        !           207: 
        !           208:     /* get the file */
        !           209:     if(!KitFileDlg(hwndMain, (PFILEDLG)&fdg))
        !           210:         return;
        !           211: 
        !           212: 
        !           213:     /*--------------------------------------------------------------*\
        !           214:      *  Upon sucessful return of a file, open it for reading
        !           215:     \*--------------------------------------------------------------*/
        !           216: 
        !           217:     if(fdg.lReturn == ID_OK)  {
        !           218:         if( DosOpen(fdg.szFullFile,
        !           219:                     &hfIn,
        !           220:                     &ulAction,
        !           221:                     0L,
        !           222:                     FILE_NORMAL,
        !           223:                     FILE_OPEN,
        !           224:                     OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE,
        !           225:                     0L))  {
        !           226: 
        !           227:             MessageBox(hwndMain,
        !           228:                        IDMSG_CANNOTOPENINPUTFILE,
        !           229:                        MB_OK | MB_ERROR,
        !           230:                        FALSE);
        !           231:             return;
        !           232:         }
        !           233: 
        !           234:         /* copy file name into file name buffer */
        !           235:         strcpy(szFullPath, fdg.szFullFile);
        !           236: 
        !           237:         /*--------------------------------------------------------------*\
        !           238:          *  Place routine for reading the file here
        !           239:         \*--------------------------------------------------------------*/
        !           240: 
        !           241:         /* get the length of the file */
        !           242:         if(DosQueryFileInfo(hfIn,
        !           243:                             1,
        !           244:                             (PVOID)&fstsInfo,
        !           245:                             sizeof(FILESTATUS)))  {
        !           246:             MessageBox(hwndMain,
        !           247:                        IDMSG_CANNOTGETFILEINFO,
        !           248:                        MB_OK | MB_ERROR,
        !           249:                        FALSE);
        !           250: 
        !           251:             DosClose(hfIn);
        !           252:             return;
        !           253:         }
        !           254: 
        !           255: 
        !           256:         /* allocate a buffer for the file */
        !           257:         if(DosAllocMem((PPVOID)&pvBuf,
        !           258:                        (ULONG)fstsInfo.cbFileAlloc,
        !           259:                         fALLOC))  {
        !           260:             MessageBox(hwndMain,
        !           261:                        IDMSG_CANNOTALLOCATEMEMORY,
        !           262:                        MB_OK | MB_ERROR,
        !           263:                        FALSE);
        !           264: 
        !           265:             DosClose(hfIn);
        !           266:             return;
        !           267:         }
        !           268: 
        !           269:         /* read in the file */
        !           270:         if(DosRead(hfIn, pvBuf, fstsInfo.cbFileAlloc, &ulAction))  {
        !           271:             MessageBox(hwndMain,
        !           272:                        IDMSG_CANNOTREADFILE,
        !           273:                        MB_OK | MB_ERROR,
        !           274:                        FALSE);
        !           275: 
        !           276:             DosClose(hfIn);
        !           277:             return;
        !           278:         }
        !           279: 
        !           280:         /* set the file into the MLE */
        !           281:         WinSendMsg(hwndMLE,
        !           282:                    MLM_SETIMPORTEXPORT,
        !           283:                    MPFROMP((PBYTE)pvBuf),
        !           284:                    MPFROMSHORT(fstsInfo.cbFileAlloc));
        !           285: 
        !           286:         WinSendMsg(hwndMLE,
        !           287:                    MLM_IMPORT,
        !           288:                    MPFROMP(NULL),
        !           289:                    MPFROMSHORT(fstsInfo.cbFileAlloc));
        !           290: 
        !           291:         /* reset the changed flag */
        !           292:         WinSendMsg(hwndMLE, MLM_SETCHANGED, MPFROMSHORT((BOOL)FALSE), NULL);
        !           293: 
        !           294:         DosFreeMem(pvBuf);
        !           295: 
        !           296:         DosClose(hfIn);
        !           297: 
        !           298:         UpdateTitleText(hwndMainFrame);
        !           299:     }
        !           300: 
        !           301: 
        !           302: 
        !           303:     /* This routine currently doesn't use the mp2 parameter but       *\
        !           304:      *  it is referenced here to prevent an 'Unreferenced Parameter'
        !           305:     \*  warning at compile time.                                      */
        !           306:     mp2;
        !           307: 
        !           308: }   /* FileOpen() */
        !           309: 
        !           310: 
        !           311: /****************************************************************\
        !           312:  *  Save file routine
        !           313:  *--------------------------------------------------------------
        !           314:  *
        !           315:  *  Name:   FileSave(mp2)
        !           316:  *
        !           317:  *  Purpose: Processes the File menu's Save item.
        !           318:  *
        !           319:  *  Usage:  called whenever Save from the File menu is
        !           320:  *          selected
        !           321:  *
        !           322:  *  Method:  Routine calls the application's save routine
        !           323:  *
        !           324:  *  Returns:
        !           325:  *
        !           326: \****************************************************************/
        !           327: VOID FileSave(mp2)
        !           328: MPARAM mp2;     /* second parameter of WM_COMMAND message */
        !           329: {
        !           330:     HFILE hf;
        !           331:     ULONG ulAction;
        !           332: 
        !           333:     /*
        !           334:      * If the file currently is untitled, we will need to get a file
        !           335:      * name from the user before we can open the file.  Getting a
        !           336:      * file name is normally done during the FileSaveAs operation
        !           337:      * so we will treat this save as a SaveAs and call FileSaveAs().
        !           338:      * If the file is titled, then we save the file.
        !           339:      *
        !           340:      * NOTE:  This routine will be called by FileSaveAs(), but only
        !           341:      *  after a valid file name has been obtained.  So, FileSaveAs()
        !           342:      *  will not be called again from this routine.
        !           343:      */
        !           344:     if(szFullPath[0] == 0)  {
        !           345:         FileSaveAs(mp2);
        !           346:         return;
        !           347:     }
        !           348: 
        !           349:     /* open the file */
        !           350:     if( DosOpen(szFullPath,
        !           351:                 &hf,
        !           352:                 &ulAction,
        !           353:                 0L,
        !           354:                 FILE_NORMAL,
        !           355:                 FILE_OPEN | FILE_CREATE,
        !           356:                 OPEN_ACCESS_WRITEONLY | OPEN_SHARE_DENYNONE,
        !           357:                 0L))  {
        !           358: 
        !           359:         MessageBox(hwndMain,
        !           360:                    IDMSG_CANNOTOPENOUTPUTFILE,
        !           361:                    MB_OK | MB_ERROR,
        !           362:                    FALSE);
        !           363:         return;
        !           364:     }
        !           365: 
        !           366:     WriteFileToDisk(hf);
        !           367: 
        !           368:     DosClose(hf);
        !           369: 
        !           370: 
        !           371:     /* This routine currently doesn't use the mp2 parameter but       *\
        !           372:      *  it is referenced here to prevent an 'Unreferenced Parameter'
        !           373:     \*  warning at compile time.                                      */
        !           374:     mp2;
        !           375: 
        !           376: }   /* FileSave() */
        !           377: 
        !           378: /****************************************************************\
        !           379:  *  Save As file routine
        !           380:  *--------------------------------------------------------------
        !           381:  *
        !           382:  *  Name:   FileSaveAs(mp2)
        !           383:  *
        !           384:  *  Purpose: Processes the File menu's Save As item.
        !           385:  *
        !           386:  *  Usage:  called whenever Save As from the File menu is
        !           387:  *          selected
        !           388:  *
        !           389:  *  Method:  Routine calls the application's Save As routine
        !           390:  *
        !           391:  *  Returns:
        !           392:  *
        !           393: \****************************************************************/
        !           394: VOID FileSaveAs(mp2)
        !           395: MPARAM mp2;     /* second parameter of WM_COMMAND message */
        !           396: {
        !           397:     HFILE hf;
        !           398:     ULONG ulAction;
        !           399:     SHORT sT;
        !           400: 
        !           401:     while(TRUE)  {      /* infinite loop until we break out of it */
        !           402: 
        !           403:         /* if no file name, then get a file name */
        !           404:         if(!GetFileName())
        !           405:             return;
        !           406: 
        !           407:         /* See if the file exists.  If it does, then confirm that the
        !           408:          * user wants to overwrite it.  If he doesn't, then get a new
        !           409:          * file name
        !           410:          */
        !           411:         if( DosOpen(szFullPath,     /* file name from, GetFileName() */
        !           412:                     &hf,            /* handle of opened file */
        !           413:                     &ulAction,
        !           414:                     0L,
        !           415:                     FILE_NORMAL,
        !           416:                     FILE_CREATE,
        !           417:                     OPEN_ACCESS_WRITEONLY | OPEN_SHARE_DENYNONE,
        !           418:                     0L))  {
        !           419: 
        !           420:             MessageBox(hwndMain,
        !           421:                        IDMSG_CANNOTOPENOUTPUTFILE,
        !           422:                        MB_OK | MB_ERROR,
        !           423:                        FALSE);
        !           424:             return;
        !           425:         } else
        !           426:             DosClose(hf);
        !           427: 
        !           428:         /* if file exists, ask if we want to overwrite it */
        !           429:         if(ulAction == FILE_EXISTED)  {
        !           430:             sT = MessageBox(hwndMLE,
        !           431:                             IDMSG_OVERWRITEFILE,
        !           432:                             MB_QUERY | MB_YESNOCANCEL,
        !           433:                             FALSE);
        !           434: 
        !           435: 
        !           436:             if(sT == MBID_CANCEL)
        !           437:                 return;
        !           438: 
        !           439:             if(sT == MBID_YES)
        !           440:                 break;
        !           441: 
        !           442:             /* if user selected no, repeat the sequence */
        !           443:         }
        !           444: 
        !           445:     }   /* while(TRUE) */
        !           446: 
        !           447:     UpdateTitleText(hwndMainFrame);
        !           448: 
        !           449:     /*
        !           450:      * Now that we have a valid file name, save the file.  This is
        !           451:      * normally done under the File Save function so we can just
        !           452:      * call the FileSave() function here.  Note that FileSave() will
        !           453:      * not call FileSaveAs() back since there is a valid file name
        !           454:      */
        !           455:      FileSave(mp2);
        !           456: 
        !           457: 
        !           458: 
        !           459:     /* This routine currently doesn't use the mp2 parameter but       *\
        !           460:      *  it is referenced here to prevent an 'Unreferenced Parameter'
        !           461:     \*  warning at compile time.                                      */
        !           462:     mp2;
        !           463: 
        !           464: }   /* FileSaveAs() */
        !           465: 
        !           466: #endif
        !           467: 
        !           468: #ifdef PRINT_DLGS_ENABLED
        !           469: 
        !           470: /****************************************************************\
        !           471:  *  Print file routine
        !           472:  *--------------------------------------------------------------
        !           473:  *
        !           474:  *  Name:   FilePrint(mp2)
        !           475:  *
        !           476:  *  Purpose: Processes the File menu's Print item.
        !           477:  *
        !           478:  *  Usage:  called whenever Print from the File menu is
        !           479:  *          selected
        !           480:  *
        !           481:  *  Method:  Routine calls the application's print routine
        !           482:  *
        !           483:  *  Returns:
        !           484:  *
        !           485: \****************************************************************/
        !           486: VOID FilePrint(mp2)
        !           487: MPARAM mp2;     /* second parameter of WM_COMMAND message */
        !           488: {
        !           489: 
        !           490:     Print(hwndMain);
        !           491: 
        !           492: 
        !           493:     /* This routine currently doesn't use the mp2 parameter but       *\
        !           494:      *  it is referenced here to prevent an 'Unreferenced Parameter'
        !           495:     \*  warning at compile time.                                      */
        !           496:     mp2;
        !           497: 
        !           498: }   /* FilePrint() */
        !           499: 
        !           500: /****************************************************************\
        !           501:  *  Page setup routine
        !           502:  *--------------------------------------------------------------
        !           503:  *
        !           504:  *  Name:   FilePageSetup(mp2)
        !           505:  *
        !           506:  *  Purpose: Processes the File menu's Page Setup item.
        !           507:  *
        !           508:  *  Usage:  called whenever Page Setup from the File menu is
        !           509:  *          selected
        !           510:  *
        !           511:  *  Method:  Routine calls the application's page setup routine
        !           512:  *
        !           513:  *  Returns:
        !           514:  *
        !           515: \****************************************************************/
        !           516: VOID FilePageSetup(mp2)
        !           517: MPARAM mp2;     /* second parameter of WM_COMMAND message */
        !           518: {
        !           519: 
        !           520:     PageSetup(hwndMain);
        !           521: 
        !           522:     /* This routine currently doesn't use the mp2 parameter but       *\
        !           523:      *  it is referenced here to prevent an 'Unreferenced Parameter'
        !           524:     \*  warning at compile time.                                      */
        !           525:     mp2;
        !           526: 
        !           527: }   /* FilePageSetup() */
        !           528: 
        !           529: /****************************************************************\
        !           530:  *  Print Setup routine
        !           531:  *--------------------------------------------------------------
        !           532:  *
        !           533:  *  Name:   FilePageSetup(mp2)
        !           534:  *
        !           535:  *  Purpose: Processes the File menu's Print Setup item.
        !           536:  *
        !           537:  *  Usage:  called whenever Print Setup from the File menu is
        !           538:  *          selected
        !           539:  *
        !           540:  *  Method:  Routine calls the application's Print Setup routine
        !           541:  *
        !           542:  *  Returns:
        !           543:  *
        !           544: \****************************************************************/
        !           545: VOID FilePrintSetup(mp2)
        !           546: MPARAM mp2;     /* second parameter of WM_COMMAND message */
        !           547: {
        !           548: 
        !           549:     PrintSetup(hwndMain);
        !           550: 
        !           551:     /* This routine currently doesn't use the mp2 parameter but       *\
        !           552:      *  it is referenced here to prevent an 'Unreferenced Parameter'
        !           553:     \*  warning at compile time.                                      */
        !           554:     mp2;
        !           555: 
        !           556: }   /* FilePrintSetup() */
        !           557: 
        !           558: #endif  /* PRINT_DLGS_ENABLED */
        !           559: 
        !           560: /****************************************************************\
        !           561:  *  Exit routine
        !           562:  *--------------------------------------------------------------
        !           563:  *
        !           564:  *  Name:   FileExit(mp2)
        !           565:  *
        !           566:  *  Purpose: Processes the File menu's Exit item.
        !           567:  *
        !           568:  *  Usage:  called whenever Exit from the file menu is
        !           569:  *          selected
        !           570:  *
        !           571:  *  Method:  Routine posts a WM_CLOSE message to the main
        !           572:  *           application window.
        !           573:  *
        !           574:  *  Returns:
        !           575:  *
        !           576: \****************************************************************/
        !           577: VOID FileExit(mp2)
        !           578: MPARAM mp2;     /* second parameter of WM_COMMAND message */
        !           579: {
        !           580: 
        !           581:     WinPostMsg(hwndMain, WM_CLOSE, (MPARAM)NULL, (MPARAM)NULL);
        !           582: 
        !           583: 
        !           584:     /* This routine currently doesn't use the mp2 parameter but       *\
        !           585:      *  it is referenced here to prevent an 'Unreferenced Parameter'
        !           586:     \*  warning at compile time.                                      */
        !           587:     mp2;
        !           588: 
        !           589: }   /* FileExit() */
        !           590: 
        !           591: #ifdef MLE_BUGS_FIXED
        !           592: 
        !           593: /****************************************************************\
        !           594:  *  Write file routine
        !           595:  *--------------------------------------------------------------
        !           596:  *
        !           597:  *  Name:   WriteFileToDisk(hf)
        !           598:  *
        !           599:  *  Purpose: Writes the current file to the file in szFileName
        !           600:  *
        !           601:  *  Usage:  called from FileSave and FileSaveAs when a file
        !           602:  *          is to be saved to disk
        !           603:  *
        !           604:  *  Method:  Routine uses the file handle specified and gets
        !           605:  *           the text from the MLE and writes the text to the
        !           606:  *           file.
        !           607:  *
        !           608:  *  Returns:
        !           609:  *
        !           610: \****************************************************************/
        !           611: VOID WriteFileToDisk(hf)
        !           612: HFILE hf;       /* handle to the input file */
        !           613: {
        !           614:     ULONG ulWrite;
        !           615:     PVOID pvBuf;
        !           616:     ULONG ulFileLen;
        !           617: 
        !           618:     /* get the length of the file */
        !           619:     ulFileLen = (ULONG)WinSendMsg(hwndMLE, MLM_QUERYTEXTLENGTH, NULL, NULL);
        !           620:     if(!ulFileLen)
        !           621:         return;
        !           622: 
        !           623:     /* allocate a buffer for the file */
        !           624:     if(DosAllocMem((PPVOID) &pvBuf, ulFileLen, fALLOC))  {
        !           625:         MessageBox(hwndMLE,
        !           626:                    IDMSG_CANNOTALLOCATEMEMORY,
        !           627:                    MB_OK | MB_ERROR,
        !           628:                    FALSE);
        !           629:         return;
        !           630:     }
        !           631: 
        !           632: 
        !           633:     /* get the file from the MLE */
        !           634:     WinSendMsg(hwndMLE,
        !           635:                MLM_SETIMPORTEXPORT,
        !           636:                MPFROMP((PBYTE)pvBuf),
        !           637:                MPFROMLONG(ulFileLen));
        !           638: 
        !           639:     WinSendMsg(hwndMLE,
        !           640:                MLM_EXPORT,
        !           641:                MPFROMP(NULL),
        !           642:                MPFROMLONG(&ulFileLen));
        !           643: 
        !           644:     /* Write the file */
        !           645:     if(DosWrite(hf, pvBuf, ulFileLen, &ulWrite))  {
        !           646:         MessageBox(hwndMLE,
        !           647:                    IDMSG_CANNOTWRITETOFILE,
        !           648:                    MB_OK | MB_ERROR,
        !           649:                    FALSE);
        !           650:         return;
        !           651:     }
        !           652: 
        !           653:     /* reset the changed flag */
        !           654:     WinSendMsg(hwndMLE, MLM_SETCHANGED, MPFROMSHORT((BOOL)FALSE), NULL);
        !           655: 
        !           656:     DosFreeMem(pvBuf);
        !           657: 
        !           658: 
        !           659: }   /* WriteFileToDisk() */
        !           660: 
        !           661: /****************************************************************\
        !           662:  *  Get file name routine
        !           663:  *--------------------------------------------------------------
        !           664:  *
        !           665:  *  Name:   GetFileName()
        !           666:  *
        !           667:  *  Purpose: Gets the name of the save file.
        !           668:  *
        !           669:  *  Usage:  called when the user is needs to supply a name for
        !           670:  *          the file to be saved
        !           671:  *
        !           672:  *  Method:  calls the standard file open dialog to get the
        !           673:  *          file name.
        !           674:  *
        !           675:  *  Returns: TRUE if successfull in getting a file name, FALSE
        !           676:  *              if not
        !           677:  *
        !           678: \****************************************************************/
        !           679: BOOL GetFileName(VOID)
        !           680: {
        !           681:     FILEDLG fdg;
        !           682:     CHAR szTitle[MESSAGELEN], szButton[MESSAGELEN];
        !           683: 
        !           684:     fdg.cbsize = sizeof(FILEDLG);
        !           685:     fdg.usDialogType = SAVEAS_DIALOG;
        !           686: 
        !           687:     if(!WinLoadString(hab, NULL, IDS_SAVEDLGTITLE, MESSAGELEN, szTitle))  {
        !           688:         MessageBox(hwndMain, IDMSG_CANNOTLOADSTRING, MB_OK | MB_ERROR, TRUE);
        !           689:         return FALSE;
        !           690:     }
        !           691: 
        !           692:     if(!WinLoadString(hab, NULL, IDS_SAVEDLGBUTTON, MESSAGELEN, szButton))  {
        !           693:         MessageBox(hwndMain, IDMSG_CANNOTLOADSTRING, MB_OK | MB_ERROR, TRUE);
        !           694:         return FALSE;
        !           695:     }
        !           696: 
        !           697:     fdg.pszTitle = szTitle;
        !           698:     fdg.pszOKButton = szButton;
        !           699: 
        !           700:     fdg.lUser = 0L;
        !           701:     fdg.fl = FDS_HELPBUTTON | FDS_CENTER;
        !           702:     fdg.pfnDlgProc = NULL;
        !           703:     fdg.lReturn = 0L;
        !           704:     fdg.lSRC = 0L;
        !           705:     fdg.hmod = NULL;
        !           706:     fdg.idDlg = IDD_FILESAVE;
        !           707:     fdg.x = 0;
        !           708:     fdg.y = 0;
        !           709:     fdg.pszIType = 0L;
        !           710:     fdg.ppszITypeList = 0L;
        !           711:     fdg.pszIDrive = 0L;
        !           712:     fdg.ppszIDriveList = 0L;
        !           713:     fdg.sEAType = 0;
        !           714:     strcpy(fdg.szFullFile, szFullPath);
        !           715: 
        !           716:     /* get the file */
        !           717:     if(!KitFileDlg(hwndMLE, (PFILEDLG)&fdg))
        !           718:         return FALSE;
        !           719: 
        !           720:     if(fdg.lReturn != ID_OK)
        !           721:         return FALSE;
        !           722: 
        !           723:     /* copy file name and path returned into buffers */
        !           724:     strcpy(szFullPath, fdg.szFullFile);
        !           725: 
        !           726:     return TRUE;
        !           727: 
        !           728: }   /* GetFileName() */
        !           729: 
        !           730: #endif  /* MLE_BUGS_FIXED */
        !           731: 
        !           732: 
        !           733: /****************************************************************\
        !           734:  *  Appends the app name to the title bar text
        !           735:  *--------------------------------------------------------------
        !           736:  *
        !           737:  *  Name:   UpdateTitleText(hwnd)
        !           738:  *
        !           739:  *  Purpose: Updates the text in the main window's title bar to
        !           740:  *          display the app name, followed by the separator,
        !           741:  *          followed by the file name
        !           742:  *
        !           743:  *  Usage:  called at init time and when the text file is changed
        !           744:  *
        !           745:  *  Method:  gets the program name, appends the separator, and
        !           746:  *          appends the file name.
        !           747:  *
        !           748:  *  Returns:
        !           749:  *
        !           750: \****************************************************************/
        !           751: VOID UpdateTitleText(hwnd)
        !           752: HWND hwnd;      /* handle to frame window */
        !           753: {
        !           754:     CHAR szBuf[MAXNAMEL];
        !           755:     CHAR szSeparator[TITLESEPARATORLEN+1];
        !           756:     PSZ pszT;
        !           757: 
        !           758:     WinQueryTaskTitle(NULL, szBuf, MAXNAMEL);
        !           759: 
        !           760:     WinLoadString(hab,
        !           761:                   NULL,
        !           762:                   IDS_TITLEBARSEPARATOR,
        !           763:                   TITLESEPARATORLEN,
        !           764:                   szSeparator);
        !           765: 
        !           766:     strcat(szBuf, szSeparator);
        !           767: 
        !           768:     if(szFullPath[0] == '\0')
        !           769:         pszT = szUntitled;
        !           770:     else
        !           771:         pszT = szFullPath;
        !           772: 
        !           773:     strcat(szBuf, pszT);
        !           774: 
        !           775:     WinSetWindowText(WinWindowFromID(hwnd, FID_TITLEBAR), szBuf);
        !           776: 
        !           777: }   /* UpdateTitleText() */

unix.superglobalmegacorp.com

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