Annotation of mstools/samples/filer/drvproc.c, revision 1.1.1.2

1.1       root        1: /******************************Module*Header*******************************\
1.1.1.2 ! root        2: *
        !             3: * Microsoft Developer Support
        !             4: * Copyright (c) 1992 Microsoft Corporation
        !             5: *
        !             6: *
1.1       root        7: * Module Name:  drvproc.c
                      8: *
                      9: * Filer : SDK sample
                     10: *   +   Simple File Management program with GUI front end.
                     11: *       Demonstrates Win32 File I/O API and various User algorithms.
                     12: *
                     13: * DRVPROC.C : Contains procedures relating to child window management.
                     14: *               In this sample, the Drive children handle the directory
                     15: *               and file enumeration, as well as the file I/O operations.
                     16: *
                     17: * Created: 5/05/92
                     18: * Author: Colin Stuart[]
                     19: *
                     20: * Copyright (c) 1990 Microsoft Corporation
                     21: *
                     22: * Dependencies:
                     23: *
                     24: *   (#defines)
                     25: *   (#includes)
                     26: *       Drvproc.h
                     27: *
                     28: \**************************************************************************/
                     29: 
1.1.1.2 ! root       30: #define  STRICT
1.1       root       31: #include <windows.h>
                     32: #include <string.h>
                     33: #include "globals.h"
                     34: #include "filer.h"
                     35: #include "walk.h"
                     36: #include "drvproc.h"
                     37: 
                     38: extern HANDLE   ghModule;
                     39: extern HANDLE   ghHeap;
                     40: extern HANDLE   ghDrvThread;
                     41: extern HFONT    ghFont;
                     42: 
                     43: extern HWND     ghwndCommand;
                     44: extern HWND     ghwndDrives;
                     45: extern HWND     ghActiveChild;
                     46: extern HWND     ghwndDrv1;
                     47: extern HWND     ghwndDrv2;
                     48: extern HWND     ghFocusLB;
                     49: 
                     50: extern LPDINFO  glpDrives;
                     51: 
                     52: extern CRITICAL_SECTION    gHeapCS;  // Global heap critical section var.
                     53: extern CRITICAL_SECTION    gDrvCS;   // Drive list critical section var.
                     54: 
                     55: extern char     gszEditor[DIRECTORY_STRING_SIZE];
                     56: extern char     gszCommandLine[DIRECTORY_STRING_SIZE * 2];
                     57: 
                     58: extern char     gszExtensions[NUM_EXTENSION_STRINGS][EXTENSION_LENGTH];
                     59: 
                     60: /***************************************************************************\
                     61: * DrvWndProc()
                     62: *
                     63: * History:
                     64: * 05-1-92  Created
                     65: \***************************************************************************/
                     66: 
1.1.1.2 ! root       67: LRESULT  WINAPI DrvWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
1.1       root       68: {
                     69: 
                     70:     static DWORD dwDirStyle = WS_BORDER | WS_CHILD | WS_VISIBLE |
                     71:                               LBS_NOINTEGRALHEIGHT | LBS_NOTIFY |
                     72:                               LBS_HASSTRINGS | LBS_WANTKEYBOARDINPUT |
                     73:                               LBS_DISABLENOSCROLL | WS_HSCROLL |
                     74:                               WS_VSCROLL |LBS_USETABSTOPS;
                     75: 
                     76:     static DWORD dwFileStyle = WS_BORDER | WS_CHILD | WS_VISIBLE |
                     77:                                LBS_NOINTEGRALHEIGHT | LBS_NOTIFY |
                     78:                                LBS_HASSTRINGS | LBS_WANTKEYBOARDINPUT |
                     79:                                LBS_DISABLENOSCROLL | WS_HSCROLL |
                     80:                                LBS_EXTENDEDSEL | LBS_MULTIPLESEL |
                     81:                                LBS_MULTICOLUMN | LBS_SORT;
                     82: 
                     83:     switch (message) {
                     84: 
                     85:         //
                     86:         // Creates the text and listbox windows for this Drv child and
                     87:         //  saves its handle in the per Drv child DRVCHILDINFO data structure.
                     88:         //
                     89:        case WM_CREATE: {
                     90:             LPCINFO lpCInfo;
                     91:             HWND    hTextWnd,
                     92:                     hwndLL,
                     93:                     hwndLR;
                     94: 
                     95:             DWORD   dwLoop;
                     96:             LPDINFO lpWalk;
                     97: 
                     98:             LONG    lTabs = LISTBOX_TAB_SIZE;
                     99: 
                    100:             // Create text window
                    101:             hTextWnd = CreateWindow("TextClass", NULL,
                    102:                                     SS_LEFT | WS_CHILD | WS_VISIBLE | WS_BORDER,
                    103:                                     0, 0, 0, 0,
                    104:                                     hwnd,
                    105:                                     (HMENU) TEXT_WINDOW_ID,
                    106:                                     ghModule,
                    107:                                     NULL);
                    108: 
                    109:             // Create List boxes
                    110:             hwndLL = CreateWindow("LISTBOX", NULL,
                    111:                                     dwDirStyle,
                    112:                                     0, 0, 0, 0,
                    113:                                     hwnd,
                    114:                                     (HMENU) LISTL_ID,
                    115:                                     ghModule,
                    116:                                     NULL);
                    117: 
                    118:             hwndLR = CreateWindow("LISTBOX", NULL,
                    119:                                     dwFileStyle,
                    120:                                     0, 0, 0, 0,
                    121:                                     hwnd,
                    122:                                     (HMENU) LISTR_ID,
                    123:                                     ghModule,
                    124:                                     NULL);
                    125: 
                    126:             //
                    127:             // Initialize DRVCHILDINFO structure
                    128:             //
                    129:             lpCInfo = (LPCINFO) ((LPCREATESTRUCT) lParam)->lpCreateParams;
                    130: 
                    131:             lpCInfo->hTextWnd = hTextWnd;
                    132:             lpCInfo->hwndLL = hwndLL;
                    133:             lpCInfo->hwndLR = hwndLR;
                    134: 
                    135:             //
                    136:             // Create Critical Section associated with each list box
                    137:             //
                    138:             InitializeCriticalSection(&(lpCInfo->CritSecL));
                    139:             InitializeCriticalSection(&(lpCInfo->CritSecR));
                    140: 
                    141:             //
                    142:             // Associate window with the current directory LPDINFO structure
                    143:             //   from the Drives linked list
                    144:             //
                    145:             dwLoop = GetCurrentDirectory( DIRECTORY_STRING_SIZE,
                    146:                                           lpCInfo->CaptionBarText );
                    147:             CharUpper(lpCInfo->CaptionBarText);
                    148: 
                    149:             WaitForSingleObject(ghDrvThread, 0xFFFFFFFF);
                    150:             EnterCriticalSection(&gDrvCS);
                    151: 
                    152:             lpWalk = glpDrives;
                    153: 
                    154:             if( dwLoop && dwLoop <= DIRECTORY_STRING_SIZE ){
                    155:                 while( lpWalk && lpWalk->DriveName[0] !=
                    156:                        (lpCInfo->CaptionBarText)[0] )
                    157:                     lpWalk = lpWalk->next;
                    158:                 if( !lpWalk ){
                    159:                     ErrorMsg("Drive Child Create: Drive list error.");
                    160:                     LeaveCriticalSection(&gDrvCS);
                    161:                     return(-1);
                    162:                 }
                    163:             }
                    164:             else{
                    165:                 ErrorMsg("Drive Child Create: GetCurrentDir error.");
                    166:                 LeaveCriticalSection(&gDrvCS);
                    167:                 return(-1);
                    168:             }
                    169: 
                    170:             LeaveCriticalSection(&gDrvCS);
                    171: 
                    172:             lpCInfo->lpDriveInfo = lpWalk;
                    173: 
                    174:             //
                    175:             // Save the handle to DRVCHILDINFO in our window structure
                    176:             //
                    177:             SetWindowLong(hwnd, GWL_USERDATA, (LONG) lpCInfo);
                    178: 
                    179:             //
                    180:             // Initialize child windows
                    181:             //
                    182:             if( !SendMessage(hwndLL, LB_SETTABSTOPS, (WPARAM)1,
                    183:                             (LPARAM)&lTabs) )
                    184:                 ErrorMsg("Drv window Create: Error setting tab stops");
                    185: 
                    186: 
                    187:             //
                    188:             // Set default font.
                    189:             //
                    190:             SendMessage(hwndLL, WM_SETFONT, (WPARAM)ghFont, (LPARAM)FALSE);
                    191:             SendMessage(hwndLR, WM_SETFONT, (WPARAM)ghFont, (LPARAM)FALSE);
                    192: 
                    193:             SendMessage(hwnd, WM_COMMAND, (WPARAM)MM_REFRESH, (LPARAM)NULL);
                    194: 
                    195:             return(1);
                    196:        }
                    197: 
                    198:        case WM_COMMAND: {
                    199:           static LPCINFO     lpCInfo;
                    200:           static SELECTINFO  Select;
                    201: 
                    202:           //
                    203:           // Retrieving this child window's DRVCHILDINFO data for displaying
                    204:           //    messages in the text window
                    205:           //
                    206:           lpCInfo = (LPCINFO) GetWindowLong(hwnd, GWL_USERDATA);
                    207: 
                    208:          switch (LOWORD(wParam)) {
                    209: 
                    210:             case MM_TAB:{
                    211:                 HWND    hFocus;
                    212: 
                    213:                 hFocus = GetFocus();
                    214: 
                    215:                 if( hFocus == lpCInfo->hwndLL )
                    216:                     SetFocus(lpCInfo->hwndLR);
                    217:                 else
                    218:                     if( hFocus == lpCInfo->hwndLR )
                    219:                         SetFocus(ghwndCommand);
                    220:                     else
                    221:                         if( hFocus == ghwndCommand)
                    222:                             SetFocus(lpCInfo->hwndLL);
                    223:                         else
                    224:                             SetFocus(lpCInfo->hwndLL);
                    225: 
                    226:                 return(1);
                    227:             }
                    228: 
                    229:             //
                    230:             //  Clears the selection in the active window.
                    231:             //  Sent when user hits escape key.
                    232:             //
                    233:             case MM_ESCAPE:{
                    234:                 //
                    235:                 // the type of the active window can be determined by querying
                    236:                 //   on unique window style attributes.  Only the file listbox
                    237:                 //   has LBS_SORT, only the dir listbox has LBS_USETABSTOPS.
                    238:                 //
                    239:                 if( IsFileLB(ghFocusLB) )
                    240:                     SendMessage(ghFocusLB, LB_SETSEL, (WPARAM)0, (LPARAM)-1);
                    241:                 else
                    242:                     SendMessage(ghFocusLB, LB_SETCURSEL, (WPARAM)-1, (LPARAM)NULL);
                    243: 
                    244:                 return(1);
                    245:             }
                    246: 
                    247:             case MM_OPEN:{
                    248:                 OpenListBoxItem(lpCInfo, ghFocusLB);
                    249: 
                    250:                 return(1);
                    251:             }
                    252: 
                    253:            case MM_COPY:{
                    254: 
                    255:                 Select.hwnd = hwnd;
                    256:                 Select.dwAction = MM_COPY;
                    257:                 Select.szAction = "COPYING:";
                    258:                 Select.szToFrom = "TO:";
                    259: 
                    260:                 ExecuteFileAction(&Select);
                    261: 
                    262:                 return(1);
                    263:             }
                    264: 
                    265:            case MM_DELETE:{
                    266: 
                    267:                 Select.hwnd = hwnd;
                    268:                 Select.dwAction = MM_DELETE;
                    269:                 Select.szAction = "DELETING:";
                    270:                 Select.szToFrom = "FROM:";
                    271: 
                    272:                 ExecuteFileAction(&Select);
                    273: 
                    274:                 return(1);
                    275:             }
                    276: 
                    277:            case MM_MOVE:{
                    278: 
                    279:                 Select.hwnd = hwnd;
                    280:                 Select.dwAction = MM_MOVE;
                    281:                 Select.szAction = "MOVING:";
                    282:                 Select.szToFrom = "TO:";
                    283: 
                    284:                 ExecuteFileAction(&Select);
                    285: 
                    286:                 return(1);
                    287:             }
                    288: 
                    289:            case MM_RENAME:{
                    290: 
                    291:                 if( DialogBoxParam(ghModule, "RenameDlg", hwnd,
                    292:                               (DLGPROC)RenameProc, (LPARAM)lpCInfo) == -1 ){
                    293:                     ErrorMsg("DriveProc: Rename Dialog Creation Error!");
                    294:                     return(0);
                    295:                 }
                    296: 
                    297:                 return(1);
                    298:             }
                    299: 
                    300:            case MM_MKDIR:{
                    301: 
                    302:                 if( DialogBoxParam(ghModule, "MkDirDlg", hwnd,
                    303:                               (DLGPROC)MkDirProc, (LPARAM)lpCInfo) == -1 ){
                    304:                     ErrorMsg("DriveProc: MkDir Dialog Creation Error!");
                    305:                     return(0);
                    306:                 }
                    307: 
                    308:                 return(1);
                    309:             }
                    310: 
                    311:             //
                    312:             // refreshes contents of directory and file ListBoxes.
                    313:             //
                    314:             case MM_REFRESH:{
                    315: 
                    316:                 if( IsFileLB(lpCInfo->hwndLL) ){
                    317:                     if( !PostMessage(hwnd, WM_COMMAND, MM_FILLFILE,
                    318:                                      (LPARAM)lpCInfo->hwndLL) )
                    319:                         ErrorMsg("Refresh Drv window: Left Fillfile failed");
                    320:                     if( !PostMessage(hwnd, WM_COMMAND, MM_FILLDIR,
                    321:                                      (LPARAM)lpCInfo->hwndLR) )
                    322:                         ErrorMsg("Refresh Drv window: Right Filldir failed");
                    323:                 }
                    324:                 else{
                    325:                     if( !PostMessage(hwnd, WM_COMMAND, MM_FILLDIR,
                    326:                                      (LPARAM)lpCInfo->hwndLL) )
                    327:                         ErrorMsg("Refresh Drv window: Left Filldir failed");
                    328:                     if( !PostMessage(hwnd, WM_COMMAND, MM_FILLFILE,
                    329:                                      (LPARAM)lpCInfo->hwndLR) )
                    330:                         ErrorMsg("Refresh Drv window: Right Fillfile failed");
                    331:                 }
                    332: 
                    333:                 return(1);
                    334:             }
                    335: 
                    336:             //
                    337:             //  Fill listbox in lParam with directory from Drv child's drive.
                    338:             //  Sent by MM_REFRESH.
                    339:             //
                    340:             case MM_FILLDIR:{
                    341: 
                    342:                 DWORD   dwThreadID;
                    343: 
                    344:                 //
                    345:                 // If there is currently a directory enumeration thread
                    346:                 //   running for this Drv Child, and no requests to kill it,
                    347:                 //   leave.
                    348:                 //
                    349:                 if( WaitForSingleObject( lpCInfo->hDirThread, 0) == WAIT_TIMEOUT
                    350:                     && lpCInfo->fAlive )
                    351:                     return(0);
                    352: 
                    353:                 lpCInfo->hDirThread = CreateThread( NULL, 0,
                    354:                               (LPTHREAD_START_ROUTINE)FillDirectoryLB,
                    355:                               (LPVOID)lParam, 0, &dwThreadID);
                    356: 
                    357:                 if( !(lpCInfo->hDirThread) ){
                    358:                     ErrorMsg("FILLDIR: CreateThread failed");
                    359:                     return(0);
                    360:                 }
                    361: 
                    362:                 return(1);
                    363:             }
                    364: 
                    365:             //
                    366:             //  Fill listbox in lParam with files from current directory.
                    367:             //  Sent by MM_REFRESH & LBN_DBLCLK in DrvWndProc, as well as
                    368:             //  DoFileIO. and HandleIOError().
                    369:             //
                    370:             case MM_FILLFILE:{
                    371:                 char                szFiles[DIRECTORY_STRING_SIZE + 20];
                    372:                 char*               lpHold;
                    373:                 LPCRITICAL_SECTION  lpCS;
                    374: 
                    375:                 if( (HWND)lParam == lpCInfo->hwndLL)
                    376:                     lpCS = &(lpCInfo->CritSecL);
                    377:                 else
                    378:                     if( (HWND)lParam == lpCInfo->hwndLR)
                    379:                         lpCS = &(lpCInfo->CritSecR);
                    380:                     else{
                    381:                         ErrorMsg("MM_FILLFILE: Invalid ListBox handle.");
                    382:                         return(0);
                    383:                     }
                    384: 
                    385:                 EnterCriticalSection(lpCS);
                    386: 
                    387:                 //
                    388:                 // Not checking for errors here, as LB_RESETCONTENT always
                    389:                 //  returns true, and LB_DIR returns an error if the directory
                    390:                 //  is empty.
                    391:                 //
                    392:                 SendMessage((HWND)lParam, LB_RESETCONTENT, (WPARAM)NULL, (LPARAM)NULL);
                    393: 
                    394:                 lstrcpy( szFiles, lpCInfo->CaptionBarText );
                    395:                 lpHold = strchr(szFiles, '\0');
                    396:                 lpHold--;
                    397:                 if( *lpHold != '\\')
                    398:                     lstrcat( szFiles, "\\");
                    399:                 lstrcat( szFiles, "*.*");
                    400: 
                    401:                 if( SendMessage( (HWND)lParam, LB_DIR, (WPARAM)0x10,
                    402:                                  (LPARAM)szFiles ) == LB_ERR ){
                    403:                     ErrorMsg("MM_FILLFILE:  Fill ListBox error.");
                    404:                     return(0);
                    405:                 }
                    406: 
                    407:                 SetWindowText(lpCInfo->hTextWnd, lpCInfo->CaptionBarText);
                    408: 
                    409:                 LeaveCriticalSection(lpCS);
                    410: 
                    411:                 return(1);
                    412:             }
                    413: 
                    414:             case MM_TOGGLE:{
                    415: 
                    416:                 SendMessage(lpCInfo->hTextWnd, WM_SETTEXT, (WPARAM)NULL,
                    417:                             (LPARAM)lpCInfo->CaptionBarText);
                    418: 
                    419:                 return(1);
                    420:             }
                    421: 
                    422:             //
                    423:             // The following WM_COMMAND messages are sent by the listboxes
                    424:             //
                    425:             case LISTL_ID:
                    426:             case LISTR_ID:{
                    427:               switch( HIWORD(wParam) ){
                    428:                 //
                    429:                 // In case of double click on a directory, expand the file
                    430:                 // Listbox. if on a file, run or edit file.
                    431:                 //
                    432:                 case LBN_DBLCLK:{
                    433:                     OpenListBoxItem(lpCInfo, (HWND) lParam);
                    434:                     return(1);
                    435:                 }
                    436:                 break;
                    437: 
                    438:                 case LBN_SETFOCUS:{
                    439:                     ghFocusLB = (HWND)lParam;
                    440:                 }
                    441:                 break;
                    442: 
                    443:                 default:
                    444:                     return(1);
                    445:               }
                    446:             }
                    447:             break;
                    448: 
                    449:             default:
                    450:                return(1);
                    451: 
                    452:          }
                    453: 
                    454:        }
                    455:         break;
                    456: 
                    457:         //
                    458:         // Whenever the Drv child window is resized, its children has to be
                    459:         //  resized accordingly.  The GetWindowLong GWL_USERDATA values
                    460:         //  contain the height of the windows queried, set in their respective
                    461:         //  WM_CREATE cases.
                    462:         //
                    463:        case WM_SIZE: {
                    464:             LPCINFO     lpCInfo;
                    465: 
                    466:             int         nListHeight;
                    467:             int         nListWidth;
                    468: 
                    469:             //
                    470:             // First, get the text window's handle from the per Drv child
                    471:             //  DRVCHILDINFO data structure
                    472:             //
                    473:             lpCInfo = (LPCINFO)GetWindowLong(hwnd, GWL_USERDATA);
                    474: 
                    475:             nListHeight = HIWORD(lParam) -
                    476:                           GetWindowLong(lpCInfo->hTextWnd, GWL_USERDATA)
                    477:                           - LIST_BORDER * 2;
                    478: 
                    479:             nListWidth = (LOWORD(lParam) - LIST_BORDER) / 2 - LIST_BORDER;
                    480: 
                    481:             //
                    482:             // Always, put the text window at the top of the Drv window.
                    483:             // Increasing sides and bottom extents by 1 to overlap border
                    484:             //   with Drv child border
                    485:             //
                    486:            MoveWindow(lpCInfo->hTextWnd,
                    487:                       -1,
                    488:                        0,
                    489:                       LOWORD(lParam) + 2,
                    490:                       GetWindowLong(lpCInfo->hTextWnd, GWL_USERDATA) + 1,
                    491:                        TRUE);
                    492: 
                    493:             MoveWindow(lpCInfo->hwndLL,
                    494:                        LIST_BORDER,
                    495:                       GetWindowLong(lpCInfo->hTextWnd, GWL_USERDATA) + 1
                    496:                          + LIST_BORDER,
                    497:                        nListWidth,
                    498:                        nListHeight,
                    499:                        TRUE);
                    500: 
                    501:             MoveWindow(lpCInfo->hwndLR,
                    502:                        (LOWORD(lParam) + LIST_BORDER) / 2,
                    503:                       GetWindowLong(lpCInfo->hTextWnd, GWL_USERDATA) + 1
                    504:                          + LIST_BORDER,
                    505:                        nListWidth,
                    506:                        nListHeight,
                    507:                        TRUE);
                    508: 
                    509:            break;
                    510:         }
                    511: 
                    512:         case WM_PARENTNOTIFY:{
                    513:             LPCINFO lpCInfo;
                    514: 
                    515:             if(wParam == WM_LBUTTONDOWN){
                    516:                 lpCInfo = (LPCINFO) GetWindowLong(hwnd, GWL_USERDATA);
                    517:                 if(lpCInfo == NULL){
                    518:                     ErrorMsg("Drv child: Parent notify error");
                    519:                     return(1);
                    520:                 }
                    521:                 if(HIWORD(wParam) == LISTL_ID)
                    522:                     SetFocus(lpCInfo->hwndLL);
                    523:                 else
                    524:                     if(HIWORD(wParam) == LISTR_ID)
                    525:                         SetFocus(lpCInfo->hwndLR);
                    526:                     else
                    527:                         if(HIWORD(wParam) == TEXT_WINDOW_ID)
                    528:                             SetFocus(lpCInfo->hTextWnd);
                    529:             }
                    530: 
                    531:             break;
                    532:         }
                    533: 
                    534:         //
                    535:         // Same as MainWndProc's MM_ACTIVEDRV case.  The initial PostMessage
                    536:         //   is so the currently active Drv child will not process the message
                    537:         //   until it is no longer in focus.
                    538:         //
                    539:         case WM_MOUSEACTIVATE:{
                    540:             LPCINFO lpCInfo;
                    541: 
                    542:             PostMessage(ghActiveChild, WM_COMMAND, (WPARAM)MM_TOGGLE,
                    543:                         (LPARAM)NULL);
                    544:             ghActiveChild = hwnd;
                    545:             SendMessage(ghActiveChild, WM_COMMAND, (WPARAM)MM_TOGGLE,
                    546:                         (LPARAM)NULL);
                    547: 
                    548:             lpCInfo = (LPCINFO) GetWindowLong(hwnd, GWL_USERDATA);
                    549:             SendMessage(ghwndDrives, WM_COMMAND, MM_ACTIVEDRV,
                    550:                         (LPARAM)lpCInfo->lpDriveInfo);
                    551: 
                    552:             break;
                    553:         }
                    554: 
                    555:         //
                    556:         // Free the DRVCHILDINFO data that associates with this window
                    557:         //  also, reset the menu.
                    558:         //
                    559:        case WM_CLOSE: {
                    560:             LPCINFO lpCInfo;
                    561: 
                    562:            lpCInfo = (LPCINFO)GetWindowLong(hwnd, GWL_USERDATA);
                    563: 
                    564:             DeleteCriticalSection(&(lpCInfo->CritSecL));
                    565:             DeleteCriticalSection(&(lpCInfo->CritSecR));
                    566: 
                    567:             EnterCriticalSection(&gHeapCS);
                    568:             HeapFree(ghHeap, (LPSTR)lpCInfo);
                    569:             LeaveCriticalSection(&gHeapCS);
                    570: 
                    571:             break;
                    572:        }
                    573: 
                    574:        default:
                    575:            return DefWindowProc(hwnd, message, wParam, lParam);
                    576: 
                    577:     } //switch
                    578:     return DefWindowProc(hwnd, message, wParam, lParam);
                    579: }
                    580: 
                    581: 
                    582: /***************************************************************************\
                    583: *
                    584: * IsFileLB()
                    585: *
                    586: * Verifies that the window handle sent in is a File ListBox.  Directory LBs
                    587: *  are not created with the LBS_SORT class style, while file LBs are.  A
                    588: *  query for this value determines the type of LB.  See dwDirStyle and
                    589: *  dwFileStyle at the top of DrvWndProc.
                    590: *
                    591: * History:
                    592: * 6/8/92
                    593: *   Created.
                    594: *
                    595: \***************************************************************************/
                    596: BOOL IsFileLB( HWND hwnd )
                    597: {
                    598: 
                    599:     if( GetWindowLong(hwnd, GWL_STYLE) & LBS_SORT )
                    600:         return(TRUE);
                    601:     else
                    602:         return(FALSE);
                    603: }
                    604: 
                    605: 
                    606: /***************************************************************************\
                    607: *
                    608: * FillDirectoryLB()
                    609: *
                    610: * Calls routines to walk the drive associated with the Drv Child hwnd,
                    611: *   enumerating the directories.
                    612: *
                    613: * History:
                    614: * 5/18/92
                    615: *   Created.
                    616: *
                    617: \***************************************************************************/
                    618: void FillDirectoryLB( HWND hwnd )
                    619: {
                    620:     LPCINFO lpCInfo;
                    621: 
                    622:     lpCInfo = (LPCINFO) GetWindowLong(GetParent(hwnd), GWL_USERDATA);
                    623:     if( !lpCInfo )
                    624:         ExitThread(0);
                    625: 
                    626:     if( !EnumDir(hwnd, lpCInfo) ){
                    627:         ErrorMsg("FILLDIR: Failed adding directories.");
                    628:         ExitThread(0);
                    629:     }
                    630: 
                    631:     ExitThread(1);
                    632: }
                    633: 
                    634: 
                    635: /***************************************************************************\
                    636: *
                    637: * OpenListBoxItem()
                    638: *
                    639: * Attempts to expand a selected list box directory entry into an available
                    640: *  file listbox, or spawn a selected list box file.
                    641: *
                    642: *  input:   lpCInfo   -   pointer to Drv child's LPCINFO structure
                    643: *           hActiveLB   -   handle to active listbox
                    644: *
                    645: * History:
                    646: * 5/27/92
                    647: *   Created.
                    648: *
                    649: \***************************************************************************/
                    650: BOOL OpenListBoxItem(LPCINFO lpCInfo, HWND hActiveLB)
                    651: {
                    652:     HWND    hFileLB;
                    653:     LONG    lIndex;
                    654:     char    szItemBuff[DIRECTORY_STRING_SIZE];
                    655: 
                    656:     //
                    657:     // Retrieve selected (careted) item.
                    658:     //
                    659:     lIndex = SendMessage( hActiveLB, LB_GETCARETINDEX,
                    660:                           (WPARAM)NULL, (LPARAM)NULL );
                    661: 
                    662:     if( SendMessage( hActiveLB, LB_GETTEXT, (WPARAM)lIndex,
                    663:                      (LPARAM)szItemBuff) == LB_ERR ){
                    664:         ErrorMsg("LBN_DBLCLK: Cannot get string.");
                    665:         return(0);
                    666:     }
                    667: 
                    668:     //
                    669:     // Determine whether the item is a directory selected from a directory
                    670:     //   List Box, a directory selected from a file List Box, a file, or
                    671:     //   an invalid condition (ListBox not active).
                    672:     //
                    673:     if( hActiveLB == lpCInfo->hwndLL )
                    674:         if( IsFileLB(lpCInfo->hwndLL) )
                    675:             if( !IsDirectory(lpCInfo->CaptionBarText, szItemBuff) ){
                    676:                 RunListBoxItem(lpCInfo, hActiveLB);
                    677:                 return(1);
                    678:             }
                    679:             else
                    680:                 hFileLB = hActiveLB; //it's a directory in the file list box
                    681:         else
                    682:             hFileLB = lpCInfo->hwndLR;
                    683:     else
                    684:         if( IsFileLB(lpCInfo->hwndLR) )
                    685:             if( !IsDirectory(lpCInfo->CaptionBarText, szItemBuff) ){
                    686:                 RunListBoxItem(lpCInfo, hActiveLB);
                    687:                 return(1);
                    688:             }
                    689:             else
                    690:                 hFileLB = hActiveLB; //it's a directory in the file list box
                    691:         else
                    692:             hFileLB = lpCInfo->hwndLL;
                    693: 
                    694:     //
                    695:     // Expand directory that was opened.
                    696:     //
                    697:     lstrcpy( lpCInfo->CaptionBarText, szItemBuff);
                    698: 
                    699:     SendMessage(GetParent(hActiveLB), WM_COMMAND, (WPARAM)MM_FILLFILE,
                    700:                 (LPARAM)hFileLB);
                    701:     return(1);
                    702: }
                    703: 
                    704: /***************************************************************************\
                    705: *
                    706: * RunListBoxItem()
                    707: *
                    708: * Attempts to spawn the selected list box file. If the file is not executable,
                    709: *   attempts to spawn an editor to edit the file.
                    710: *
                    711: *  input:   lpCInfo   -   pointer to Drv child's LPCINFO structure
                    712: *           hActiveLB   -   handle to active listbox
                    713: *
                    714: * History:
                    715: * 5/27/92
                    716: *   Created.
                    717: *
                    718: \***************************************************************************/
                    719: BOOL RunListBoxItem(LPCINFO lpCInfo, HWND hActiveLB)
                    720: {
                    721:     LONG        lIndex;
                    722:     char        szFileBuff[DIRECTORY_STRING_SIZE];
                    723:     char        szCmdLine[DIRECTORY_STRING_SIZE * 2];
                    724:     LPSTR       szHold;
                    725: 
                    726:     STARTUPINFO si;
                    727:     PROCESS_INFORMATION pi;
                    728: 
                    729: 
                    730:     lstrcpy(szCmdLine, lpCInfo->CaptionBarText);
                    731:     lstrcat(szCmdLine, "\\");
                    732: 
                    733:     //
                    734:     // Get file that was opened, and attempt to spawn. If fails, attempt to
                    735:     // edit it.
                    736:     //
                    737:     lIndex = SendMessage( hActiveLB, LB_GETCARETINDEX,
                    738:                           (WPARAM)NULL, (LPARAM)NULL );
                    739: 
                    740:     if( SendMessage( hActiveLB, LB_GETTEXT, (WPARAM)lIndex,
                    741:                      (LPARAM)szFileBuff) == LB_ERR ){
                    742:         ErrorMsg("RunListBoxItem: Cannot get string.");
                    743:         return(0);
                    744:     }
                    745: 
                    746: 
                    747:     //
                    748:     // Don't assume the file has an extension. if no '.', insert one at end of
                    749:     //   file, so spawned editor will not assume any default extension.
                    750:     //   (i.e. Notepad assumes a .TXT if no extension is given.)
                    751:     //
                    752:     szHold = strchr(szFileBuff, '.');
                    753:     if( !szHold ){
                    754:         szHold = strchr(szFileBuff, '\0');
                    755:         *szHold = '.';
                    756:         *(szHold + sizeof(char)) = '\0';
                    757:     }
                    758: 
                    759:     si.cb = sizeof(STARTUPINFO);
                    760:     si.lpReserved = NULL;
                    761:     si.lpDesktop = NULL;
                    762:     si.lpTitle = NULL;
                    763:     si.dwFlags = NULL;
                    764:     si.cbReserved2 = 0;
                    765:     si.lpReserved2 = NULL;
                    766: 
                    767:     //
                    768:     // Convert file to uppercase for extension comparison.  Raise the
                    769:     //   priority of this thread for the duration of the create process code.
                    770:     //   This is so the CreateProcess will not be held up by the directory
                    771:     //   fill threads.
                    772:     //   If an executable extension, spawn, else edit.
                    773:     //
                    774:     CharUpper(szFileBuff);
                    775: 
                    776:     SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
                    777: 
                    778:     for(lIndex = 0; lIndex < NUM_EXTENSION_STRINGS; lIndex++)
                    779:         if( !lstrcmp(szHold, &gszExtensions[lIndex][0]) ){
                    780: 
                    781:             lstrcat(szCmdLine, szFileBuff);
                    782: 
                    783:             if( !CreateProcess(NULL, (LPCTSTR)szCmdLine, NULL, NULL, FALSE,
                    784:                                CREATE_NEW_CONSOLE | NORMAL_PRIORITY_CLASS,
                    785:                                NULL, lpCInfo->CaptionBarText, &si, &pi) ){
                    786:                 ErrorMsg("Unable to spawn file.");
                    787:                 return(0);
                    788:             }
                    789:             return(1);
                    790:         }
                    791: 
                    792:     LoadString(ghModule, STR_DEF_EDITOR, szCmdLine,
                    793:                DIRECTORY_STRING_SIZE * 2);
                    794:     lstrcat(szCmdLine, " ");
                    795:     lstrcat(szCmdLine, szFileBuff);
                    796: 
                    797:     if( !CreateProcess(NULL, szCmdLine, NULL, NULL, FALSE,
                    798:                        CREATE_NEW_CONSOLE | NORMAL_PRIORITY_CLASS,
                    799:                        NULL, lpCInfo->CaptionBarText, &si, &pi) ){
                    800:         ErrorMsg("Unable to edit file.");
                    801:         return(0);
                    802:     }
                    803: 
                    804:     SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_NORMAL);
                    805: 
                    806:     return(1);
                    807: }
                    808: 
                    809: 
                    810: /***************************************************************************\
                    811: *
                    812: * IsDirectory()
                    813: *
                    814: *  Given an item from a ListBox filled from an LB_DIR call, IsDirectory
                    815: *    verifies whether or not the item is a directory, and if so, returns
                    816: *    true, and places the full directory path in lpszFile.
                    817: *
                    818: *  input:   lpszDir -   Holds current directory
                    819: *           lpszFile    -   Holds item of dubious directoryness.
                    820: *
                    821: * History:
                    822: * 5/30/92
                    823: *   Created.
                    824: *
                    825: \***************************************************************************/
                    826: BOOL IsDirectory(LPSTR lpszDir, LPSTR lpszFile)
                    827: {
                    828:     DWORD   dwAttrib;
                    829:     LPSTR   lpszHold;
                    830:     char    szItem[DIRECTORY_STRING_SIZE * 2];
                    831: 
                    832:     //
                    833:     // if it's '..', go up one directory
                    834:     //
                    835:     if( !lstrcmp(lpszFile, "[..]") ){
                    836:         lstrcpy(lpszFile, lpszDir);
                    837:         lpszHold = strchr(lpszFile, '\0');
                    838:         while( (lpszHold > lpszFile) && (*lpszHold != '\\') )
                    839:             lpszHold--;
                    840:         if(lpszHold <= lpszFile){
                    841:             ErrorMsg("IsDirectory: String parse error.");
                    842:             return(0);
                    843:         }
                    844:         else{
                    845:             if( strchr(lpszFile, '\\') == lpszHold )
                    846:                 lpszHold++;
                    847:             *lpszHold = '\0';
                    848:             return(1);
                    849:         }
                    850:     }
                    851: 
                    852:     //
                    853:     // a directory will have [] around it in the listbox. Check for it.
                    854:     //
                    855:     if( *lpszFile != '[' )
                    856:         return(0);
                    857: 
                    858:     //
                    859:     // a file under some file systems may have [] characters.
                    860:     //   Prepend path, adding a delimiting backslash unless we're in the root.
                    861:     //   If the attribute check is successful, it's a file, so leave.
                    862:     //
                    863:     lstrcpy(szItem, lpszDir);
                    864:     lpszHold = strchr(szItem, '\0');
                    865:     lpszHold--;
                    866:     if( *lpszHold != '\\' ){
                    867:         lpszHold++;
                    868:         *lpszHold = '\\';
                    869:         lpszHold++;
                    870:     }
                    871:     else
                    872:         lpszHold++;
                    873: 
                    874:     lstrcpy(lpszHold, lpszFile);
                    875: 
                    876:     dwAttrib = GetFileAttributes(szItem);
                    877: 
                    878:     if( dwAttrib != 0xFFFFFFFF )
                    879:         return(0);
                    880: 
                    881:     //
                    882:     // remove the [], and check if valid directory.
                    883:     //   if it fails, or it's not a directory, leave.
                    884:     //
                    885:     lstrcpy(lpszHold, &lpszFile[1]);
                    886:     lpszHold = strchr(lpszHold, '\0');
                    887:     lpszHold--;
                    888:     if( *lpszHold != ']' )
                    889:         return(0);
                    890:     *lpszHold = '\0';
                    891: 
                    892:     dwAttrib = GetFileAttributes(szItem);
                    893: 
                    894:     if( (dwAttrib == 0xFFFFFFFF) || !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY) )
                    895:         return(0);
                    896: 
                    897:     //
                    898:     // OK, it's a directory, and szItem now holds the fully qualified path.
                    899:     // copy this to the filename buffer sent in, and return true.
                    900:     //
                    901:     CharUpper(szItem);
                    902:     lstrcpy(lpszFile, szItem);
                    903:     return(1);
                    904: }
                    905: 
                    906: 
                    907: /***************************************************************************\
                    908: *
                    909: * ExecuteFileAction()
                    910: *
                    911: * Creates a dialog box verifying a file action, and carries out the action.
                    912: *
                    913: *  input:   hwnd    -   handle to Drv child.
                    914: *           lpSelect    -   pointer to SELECTINFO structure, containing
                    915: *                           info on the file i/o action to be performed.
                    916: *
                    917: * History:
                    918: * 5/28/92
                    919: *   Created.
                    920: *
                    921: \***************************************************************************/
                    922: BOOL ExecuteFileAction(LPSINFO lpSelect)
                    923: {
                    924: 
                    925:     if( DialogBoxParam(ghModule, "SelectDlg", lpSelect->hwnd,
                    926:                   (DLGPROC)SelectProc, (LPARAM)lpSelect) == -1 ){
                    927:         ErrorMsg("ExecuteFileAction: File I/O Dialog Creation Error!");
                    928:         return(0);
                    929:     }
                    930:     return(1);
                    931: }
                    932: 
                    933: 
                    934: /***************************************************************************\
                    935: * SelectProc()
                    936: *
                    937: * File I/O selection dialog proc.
                    938: *
                    939: * History:
                    940: * 5/28/92
                    941: *   Created.
                    942: \***************************************************************************/
                    943: LRESULT SelectProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
                    944: {
                    945:     static LPSINFO lpSelect;
                    946: 
                    947:     switch (message) {
                    948:       case WM_INITDIALOG:{
                    949: 
                    950:         lpSelect = (LPSINFO)lParam;
                    951: 
                    952:         //
                    953:         // Fill source and destination fields of Select dialog.
                    954:         //
                    955:         if( !FillSelectDlg(hDlg, lpSelect) ){
                    956:             EndDialog(hDlg, wParam);
                    957:             return(1);
                    958:         }
                    959: 
                    960:         //
                    961:         // Set the 'action' text (i.e. "COPYING:", "MOVING:", etc.)
                    962:         //
                    963:         if( !SetDlgItemText(hDlg, SB_ACTION, lpSelect->szAction) ){
                    964:             ErrorMsg("SelectProc: Set Action Text Error.");
                    965:             EndDialog(hDlg, wParam);
                    966:             return(1);
                    967:         }
                    968: 
                    969:         //
                    970:         // Set the "TO:" or "FROM:" text.
                    971:         //
                    972:         if( !SetDlgItemText(hDlg, SB_TOFROM, lpSelect->szToFrom) ){
                    973:             ErrorMsg("SelectProc: Set Action Text Error.");
                    974:             EndDialog(hDlg, wParam);
                    975:             return(1);
                    976:         }
                    977: 
                    978:         break;
                    979:       }
                    980:       case WM_COMMAND:{
                    981:         switch(wParam){
                    982:             case SB_OK:{
                    983:                 DoFileIO(hDlg, lpSelect);
                    984:                 EndDialog(hDlg, wParam);
                    985:                 return(1);
                    986:             }
                    987:             case SB_CANCEL:{
                    988:                 EndDialog(hDlg, wParam);
                    989:                 return(1);
                    990:             }
                    991:         }
                    992:         return(1);
                    993:       }
                    994:     }
                    995: 
                    996:     return(0);
                    997: }
                    998: 
                    999: 
                   1000: /***************************************************************************\
                   1001: *
                   1002: * FillSelectDlg()
                   1003: *
                   1004: * Fills the Select Dialog box with the files selected in the active Drv Child
                   1005: *  for a file i/o action.  Destination defaults to directory selection in
                   1006: *  inactive Drv Child.
                   1007: *
                   1008: *  input:   hDlg    -   handle to Select dialog box.
                   1009: *           hwnd    -   handle to Drv child.
                   1010: *
                   1011: * History:
                   1012: * 5/28/92
                   1013: *   Created.
                   1014: *
                   1015: \***************************************************************************/
                   1016: BOOL FillSelectDlg(HWND hDlg, LPSINFO lpSelect)
                   1017: {
                   1018:     LONG    lCount;         // Number of items selected in ListBox
                   1019:     LONG    lSize;          // Holds size of a string
                   1020:     LONG    lLargest = 0;   // Holds largest string encountered.
                   1021:     UINT    *lpnIndex;      // ptr to array of selected ListBox items' indeces
                   1022:     int     i;              // counter
                   1023: 
                   1024:     LPCINFO lpCInfo;
                   1025:     HWND    hActiveLB;      // handle to Drv child's dir or file list box
                   1026:     HWND    hDest;          // dir of files if delete, else inactive Drv dir.
                   1027: 
                   1028:     HDC     hDC;
                   1029:     TEXTMETRIC  Metrics;
                   1030: 
                   1031:     LPSTR   lpszHold;       // marks end of directory path in szName.
                   1032:     char    szName[DIRECTORY_STRING_SIZE * 2];  // holds ListBox strings.
                   1033: 
                   1034: 
                   1035:     lpCInfo = (LPCINFO)GetWindowLong(lpSelect->hwnd, GWL_USERDATA);
                   1036: 
                   1037:     if( IsFileLB(lpCInfo->hwndLR) )
                   1038:         hActiveLB = lpCInfo->hwndLR;
                   1039:     else
                   1040:         hActiveLB = lpCInfo->hwndLL;
                   1041: 
                   1042:     lCount = SendMessage( hActiveLB, LB_GETSELCOUNT,
                   1043:                           (WPARAM)NULL, (LPARAM)NULL );
                   1044: 
                   1045:     //
                   1046:     // if no items selected, leave.
                   1047:     //
                   1048:     if( !lCount )
                   1049:         return(0);
                   1050: 
                   1051:     //
                   1052:     // Allocate array of lCount listbox indexes, and fill it.
                   1053:     //
                   1054:     EnterCriticalSection(&gHeapCS);
                   1055:     lpnIndex = (UINT*)HeapAlloc( ghHeap, lCount * sizeof(UINT) );
                   1056:     LeaveCriticalSection(&gHeapCS);
                   1057:     if( !lpnIndex ){
                   1058:         ErrorMsg("FillSelectDlg: Item list allocation Error");
                   1059:         return(0);
                   1060:     }
                   1061: 
                   1062:     if( SendMessage( hActiveLB, LB_GETSELITEMS, (WPARAM)lCount,
                   1063:                      (LPARAM)lpnIndex) != lCount ){
                   1064:         ErrorMsg("FillSelectDlg: Get Selections Error");
                   1065:         return(0);
                   1066:     }
                   1067: 
                   1068:     //
                   1069:     // Check if each selected entry is a valid file.
                   1070:     // Fill Dlg ListBox with selected strings from Drv child's ListBox,
                   1071:     //   noting size of largest entry.
                   1072:     //
                   1073: 
                   1074:     lstrcpy(szName, lpCInfo->CaptionBarText);
                   1075:     lpszHold = strchr(szName, '\0');
                   1076:     *lpszHold = '\\';
                   1077:     lpszHold++;
                   1078: 
                   1079:     for( i = 0; i < lCount; i++){
                   1080:         if( SendMessage( hActiveLB, LB_GETTEXT, (WPARAM)lpnIndex[i],
                   1081:                         (LPARAM)lpszHold) == LB_ERR ){
                   1082:             ErrorMsg("FillSelectDlg: Get source string Error");
                   1083:             return(0);
                   1084:         }
                   1085: 
                   1086:         if( GetFileAttributes(szName) == 0xFFFFFFFF ){
                   1087:             lstrcat(lpszHold, ":  Access Denied.");
                   1088:             ErrorMsg(lpszHold);
                   1089:         }
                   1090:         else{
                   1091:             lSize = lstrlen(lpszHold);
                   1092:             if( lSize > lLargest )
                   1093:                 lLargest = lSize;
                   1094: 
                   1095:             if( SendDlgItemMessage( hDlg, SB_SOURCE, LB_ADDSTRING, NULL,
                   1096:                                     (LPARAM)lpszHold) == LB_ERR ){
                   1097:                 ErrorMsg("FillSelectDlg: Add source string Error");
                   1098:                 return(0);
                   1099:             }
                   1100:         }
                   1101:     }
                   1102: 
                   1103:     //
                   1104:     // Get the average char width of current font,
                   1105:     // We then set the dialog listbox column width to
                   1106:     // (longest string + arbitrary column spacing) * ave width.
                   1107:     //
                   1108:     hDC = GetDC(lpSelect->hwnd);
                   1109:     if( !GetTextMetrics(hDC, &Metrics) ){
                   1110:         ErrorMsg("FillSelectDlg: GetTextMetrics Error");
                   1111:         return(0);
                   1112:     }
                   1113: 
                   1114:     ReleaseDC(lpSelect->hwnd, hDC);
                   1115: 
                   1116:     SendDlgItemMessage( hDlg, SB_SOURCE, LB_SETCOLUMNWIDTH,
                   1117:                         (WPARAM)((lLargest + 8) * Metrics.tmAveCharWidth),
                   1118:                         (LPARAM)NULL );
                   1119: 
                   1120:     EnterCriticalSection(&gHeapCS);
                   1121:     HeapFree( ghHeap, (LPSTR)lpnIndex);
                   1122:     LeaveCriticalSection(&gHeapCS);
                   1123: 
                   1124: 
                   1125:     //
                   1126:     // Fill SB_DEST with directory.
                   1127:     // If deleteing, default to the directory of the files.
                   1128:     //
                   1129:     if( lpSelect->dwAction != MM_DELETE ){
                   1130:         //
                   1131:         // Not Deleting.  Default to selected directory (titlebar)
                   1132:         //   of the inactive Drive child.
                   1133:         //
                   1134:         if( lpSelect->hwnd == ghwndDrv1 )
                   1135:             hDest = ghwndDrv2;
                   1136:         else
                   1137:             hDest = ghwndDrv1;
                   1138: 
                   1139:         lpCInfo = (LPCINFO)GetWindowLong(hDest, GWL_USERDATA);
                   1140:     }
                   1141: 
                   1142:    SendDlgItemMessage( hDlg, SB_DEST, EM_LIMITTEXT,
                   1143:                             (WPARAM)DIRECTORY_STRING_SIZE, (LPARAM)0);
                   1144: 
                   1145:    if( SendDlgItemMessage( hDlg, SB_DEST, WM_SETTEXT, NULL,
                   1146:                             (LPARAM)lpCInfo->CaptionBarText) == CB_ERR ){
                   1147:         ErrorMsg("FillSelectDlg: Set Destination text Error");
                   1148:         return(0);
                   1149:     }
                   1150: 
                   1151:     return(1);
                   1152: }
                   1153: 
                   1154: 
                   1155: /***************************************************************************\
                   1156: *
                   1157: * DoFileIO()
                   1158: *
                   1159: * Called by SelectProc.  Carries out the chosed file operations verified
                   1160: *   in the Select Dialog Box.
                   1161: *
                   1162: *  input:   hDlg    -   handle to Select dialog box.
                   1163: *           lpSelect    -   ptr to SELECTINFO structure.
                   1164: *
                   1165: *  returns: 1 if successful
                   1166: *           0 if unsuccessful
                   1167: * History:
                   1168: * 6/3/92
                   1169: *   Created.
                   1170: *
                   1171: \***************************************************************************/
                   1172: BOOL DoFileIO( HWND hDlg, LPSINFO lpSelect)
                   1173: {
                   1174:     LONG    lCount;
                   1175:     LONG    lFile;
                   1176:     LPCINFO lpCInfo;
                   1177:     LPSTR   lpEndDest;
                   1178:     LPSTR   lpEndSource;
                   1179:     BOOL    fError = FALSE;
                   1180: 
                   1181:     char    szSource[DIRECTORY_STRING_SIZE];
                   1182:     char    szDest[DIRECTORY_STRING_SIZE * 2];
                   1183: 
                   1184: 
                   1185:     //
                   1186:     // Find number of files to copy
                   1187:     //
                   1188:     lCount = SendDlgItemMessage( hDlg, SB_SOURCE, LB_GETCOUNT, (WPARAM)NULL,
                   1189:                                  (LPARAM)NULL);
                   1190: 
                   1191:     if( (lCount == LB_ERR) || (lCount == 0) ){
                   1192:         ErrorMsg("Unable to get file selection.");
                   1193:         return(0);
                   1194:     }
                   1195: 
                   1196:     //
                   1197:     // Get source directory path. Add a \ to the end, set pointer to end.
                   1198:     //
                   1199:     lpCInfo = (LPCINFO)GetWindowLong( lpSelect->hwnd, GWL_USERDATA);
                   1200: 
                   1201:     lstrcpy(szSource, lpCInfo->CaptionBarText);
                   1202: 
                   1203:     lpEndSource = strchr(szSource, '\0');
                   1204:     *lpEndSource++ = '\\';
                   1205: 
                   1206:     //
                   1207:     // Get destination directory path. Add a \ to the end, set pointer to end.
                   1208:     //
                   1209:     if( SendDlgItemMessage( hDlg, SB_DEST, WM_GETTEXT,
                   1210:             (WPARAM)DIRECTORY_STRING_SIZE * 2, (LPARAM)szDest) == CB_ERR ){
                   1211:         ErrorMsg("Do I/O: Get Destination error.");
                   1212:         return(0);
                   1213:     }
                   1214: 
                   1215:     lpEndDest = strchr(szDest, '\0');
                   1216:     *lpEndDest++ = '\\';
                   1217: 
                   1218:     //
                   1219:     // for each file, do appropriate I/O.
                   1220:     //
                   1221:     while( lCount ){
                   1222: 
                   1223:         lCount--;
                   1224: 
                   1225:         lFile = SendDlgItemMessage( hDlg, SB_SOURCE, LB_GETTEXT,
                   1226:                                     (WPARAM)0, (LPARAM)lpEndSource);
                   1227:         if( lFile == LB_ERR){
                   1228:             ErrorMsg("DoFileIO: Unable to get file item.");
                   1229:             fError = TRUE;
                   1230:         }
                   1231: 
                   1232:         SendDlgItemMessage( hDlg, SB_SOURCE, LB_DELETESTRING,
                   1233:                             (WPARAM)0, (LPARAM)NULL);
                   1234: 
                   1235:         switch( lpSelect->dwAction ){
                   1236:           case MM_COPY:{
                   1237: 
                   1238:             lstrcpy(lpEndDest, lpEndSource);
                   1239: 
                   1240:             if( !CopyFile( szSource, szDest, TRUE) )
                   1241:                 if( !HandleIOError(lpSelect->hwnd, lpSelect->dwAction,
                   1242:                                    szSource, szDest) )
                   1243:                     fError = TRUE;
                   1244:             break;
                   1245:           }
                   1246: 
                   1247:           case MM_MOVE:{
                   1248: 
                   1249:             lstrcpy(lpEndDest, lpEndSource);
                   1250: 
                   1251:             if( !MoveFile( szSource, szDest) )
                   1252:                 if( !HandleIOError(lpSelect->hwnd, lpSelect->dwAction,
                   1253:                                    szSource, szDest) )
                   1254:                     fError = TRUE;
                   1255:             break;
                   1256:           }
                   1257:           case MM_DELETE:{
                   1258: 
                   1259:             if( !DeleteFile(szSource) )
                   1260:                 if( !HandleIOError(lpSelect->hwnd, lpSelect->dwAction,
                   1261:                                    szSource, szDest) )
                   1262:                     fError = TRUE;
                   1263:             break;
                   1264:           }
                   1265: 
                   1266:         }
                   1267:         if( fError )
                   1268:             break;
                   1269:     }
                   1270: 
                   1271:     //
                   1272:     //  Update appropriate file listboxes.
                   1273:     //
                   1274:     if( fError )
                   1275:         return(0);
                   1276:     else{
                   1277:         UpdateFileLB(ghwndDrv1);
                   1278:         UpdateFileLB(ghwndDrv2);
                   1279:     }
                   1280: 
                   1281:     return(1);
                   1282: }
                   1283: 
                   1284: 
                   1285: /***************************************************************************\
                   1286: *
                   1287: * UpdateFileLB()
                   1288: *
                   1289: * Updates the file listbox of the drive child given by sending an MM_FILLFILE
                   1290: *   message to it.
                   1291: *
                   1292: *  input:   hwnd    -   Handle of drive child to update file listbox of.
                   1293: *
                   1294: * History:
                   1295: * 6/3/92
                   1296: *   Created.
                   1297: *
                   1298: \***************************************************************************/
                   1299: void UpdateFileLB(HWND hwnd)
                   1300: {
                   1301:     LPCINFO lpCInfo;
                   1302:     HWND    hFileLB;
                   1303: 
                   1304:     lpCInfo = (LPCINFO)GetWindowLong(hwnd, GWL_USERDATA);
                   1305: 
                   1306:     if( IsFileLB(lpCInfo->hwndLL) )
                   1307:         hFileLB = lpCInfo->hwndLL;
                   1308:     else
                   1309:         hFileLB = lpCInfo->hwndLR;
                   1310: 
                   1311:     SendMessage(hwnd, WM_COMMAND, (WPARAM)MM_FILLFILE,
                   1312:                 (LPARAM)hFileLB);
                   1313: }
                   1314: 
                   1315: 
                   1316: /***************************************************************************\
                   1317: *
                   1318: * HandleIOError()
                   1319: *
                   1320: * Called by DoFileIO. Handles errors arising from File IO operations
                   1321: *
                   1322: *  input:   hwnd        -   handle to Drv child window
                   1323: *           dwAction    -   File I/O Action.  Window message.
                   1324: *           szSource    -   ptr to Source string
                   1325: *           szDest      -   ptr to Destination string
                   1326: *
                   1327: *  returns: 1 if successful
                   1328: *           0 if unsuccessful
                   1329: *
                   1330: * History:
                   1331: * 6/3/92
                   1332: *   Created.
                   1333: *
                   1334: \***************************************************************************/
                   1335: BOOL HandleIOError(HWND hwnd, DWORD dwAction, LPSTR szSource, LPSTR szDest)
                   1336: {
                   1337:     DWORD   dwError;
                   1338:     int     nReply;
                   1339:     LPCINFO lpCInfo;
                   1340:     char    buff[50];
                   1341: 
                   1342:     dwError = GetLastError();
                   1343: 
                   1344:     CharUpper(szDest);
                   1345: 
                   1346:     switch( dwError ){
                   1347:         case ERROR_ALREADY_EXISTS:
                   1348:         case ERROR_FILE_EXISTS:{
                   1349:           //
                   1350:           // MoveFile file already exists. We can CopyFile & DeleteFile source.
                   1351:           //
                   1352:           nReply = MessageBox(hwnd,
                   1353:                               "File Already Exists!  Overwrite file?",
                   1354:                               szDest, MB_YESNOCANCEL);
                   1355:           switch( nReply ){
                   1356:             case IDYES:{
                   1357: 
                   1358:               lpCInfo = (LPCINFO)GetWindowLong(hwnd, GWL_USERDATA);
                   1359: 
                   1360:               if( !CopyFile( szSource, szDest, FALSE) )
                   1361:                   if( HandleIOError(hwnd, dwAction, szSource, szDest) )
                   1362:                       return(1);
                   1363:                   else
                   1364:                       return(0);
                   1365:               if( dwAction == MM_MOVE )
                   1366:                   if( !DeleteFile( szSource) )
                   1367:                       if( HandleIOError(hwnd, dwAction, szSource, szDest) )
                   1368:                           return(1);
                   1369:                       else
                   1370:                           return(0);
                   1371: 
                   1372:               UpdateFileLB(ghwndDrv1);
                   1373:               UpdateFileLB(ghwndDrv2);
                   1374: 
                   1375:               return(1);
                   1376:             }
                   1377:             case IDNO:{
                   1378:               return(1);
                   1379:             }
                   1380:             case IDCANCEL:{
                   1381:               return(0);
                   1382:             }
                   1383:           }
                   1384:           break;
                   1385:         }
                   1386: 
                   1387:         case ERROR_ACCESS_DENIED:
                   1388:         case ERROR_FILE_NOT_FOUND:
                   1389:         case ERROR_INVALID_PARAMETER:{
                   1390:             wsprintf(buff,
                   1391:                      "Access Denied.  Check file name or security. Error %ld",
                   1392:                       dwError);
                   1393:             MessageBox( hwnd, buff, szDest, MB_OK);
                   1394: 
                   1395:             return(1);
                   1396:         }
                   1397: 
                   1398:         case ERROR_DISK_FULL:{
                   1399:             MessageBox( hwnd,
                   1400:             "ERROR: The disk is full.  Unable to continue.",
                   1401:             szDest, MB_OK);
                   1402:             return(0);
                   1403:         }
                   1404: 
                   1405:         case ERROR_INVALID_NAME:
                   1406:         case ERROR_DIRECTORY:
                   1407:         case ERROR_PATH_NOT_FOUND:{
                   1408:             MessageBox( hwnd,
                   1409:             "ERROR: The path or file does not exist.  Unable to continue.",
                   1410:             szDest, MB_OK);
                   1411:             return(0);
                   1412:         }
                   1413: 
                   1414:         default:{
                   1415:             wsprintf(buff, "File I/O failed. Error %ld", dwError);
                   1416:             ErrorMsg(buff);
                   1417:             return(1);
                   1418:         }
                   1419:     }
                   1420: 
                   1421:     return(1);
                   1422: }
                   1423: 
                   1424: 
                   1425: /***************************************************************************\
                   1426: * RenameProc()
                   1427: *
                   1428: * File I/O rename Dialog Box
                   1429: *
                   1430: * History:
                   1431: * 6/5/92  2am
                   1432: *   Created.
                   1433: \***************************************************************************/
                   1434: LRESULT RenameProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
                   1435: {
                   1436:     static char    szName[DIRECTORY_STRING_SIZE];
                   1437:     static LPSTR   lpszHold;
                   1438:     static HWND    hActiveLB;
                   1439: 
                   1440:     switch (message){
                   1441:       case WM_INITDIALOG:{
                   1442: 
                   1443:         LONG    lIndex;
                   1444:         LPCINFO lpCInfo;
                   1445: 
                   1446: 
                   1447:         lpCInfo = (LPCINFO)lParam;
                   1448: 
                   1449:         if( IsFileLB(lpCInfo->hwndLR) )
                   1450:             hActiveLB = lpCInfo->hwndLR;
                   1451:         else
                   1452:             hActiveLB = lpCInfo->hwndLL;
                   1453: 
                   1454:         lIndex = SendMessage( hActiveLB, LB_GETCARETINDEX,
                   1455:                               (WPARAM)NULL, (LPARAM)NULL);
                   1456:         if( lIndex == LB_ERR ){
                   1457:             ErrorMsg("Rename:  Invalid Selection");
                   1458:             return(1);
                   1459:         }
                   1460: 
                   1461:         //
                   1462:         // Check if selected entry is a valid file.
                   1463:         //
                   1464:         lstrcpy(szName, lpCInfo->CaptionBarText);
                   1465:         lpszHold = strchr(szName, '\0');
                   1466:         *lpszHold = '\\';
                   1467:         lpszHold++;
                   1468: 
                   1469:         if( SendMessage( hActiveLB, LB_GETTEXT, (WPARAM)lIndex,
                   1470:                         (LPARAM)lpszHold) == LB_ERR ){
                   1471:             ErrorMsg("Rename: Get Text Error");
                   1472:             return(1);
                   1473:         }
                   1474: 
                   1475:         //
                   1476:         // if not a valid file (i.e. listbox directory entry in []s), fail.
                   1477:         //
                   1478:         if( GetFileAttributes(szName) == 0xFFFFFFFF ){
                   1479:             lstrcat(lpszHold, ":  Access Denied.");
                   1480:             ErrorMsg(lpszHold);
                   1481:             return(1);
                   1482:         }
                   1483: 
                   1484:         //
                   1485:         // Place name in both source and destination edit controls.
                   1486:         //
                   1487:         CharUpper(szName);
                   1488: 
                   1489:         SendDlgItemMessage( hDlg, SB_SOURCE, EM_LIMITTEXT,
                   1490:                             (WPARAM)DIRECTORY_STRING_SIZE, (LPARAM)0);
                   1491: 
                   1492:         SendDlgItemMessage( hDlg, SB_DEST, EM_LIMITTEXT,
                   1493:                             (WPARAM)DIRECTORY_STRING_SIZE, (LPARAM)0);
                   1494: 
                   1495:         if( SendDlgItemMessage( hDlg, SB_SOURCE, WM_SETTEXT, NULL,
                   1496:                                 (LPARAM)lpszHold) == LB_ERR ){
                   1497:             ErrorMsg("Rename: Add Source String Error");
                   1498:             return(1);
                   1499:         }
                   1500:         if( SendDlgItemMessage( hDlg, SB_DEST, WM_SETTEXT, NULL,
                   1501:                                 (LPARAM)lpszHold) == LB_ERR ){
                   1502:             ErrorMsg("Rename: Add Destination String Error");
                   1503:             return(1);
                   1504:         }
                   1505:         return(1);
                   1506:       }
                   1507:       case WM_COMMAND:{
                   1508:         switch(wParam){
                   1509:             case SB_OK:{
                   1510:                 char    szDest[DIRECTORY_STRING_SIZE];
                   1511:                 LPSTR   lpszCheck;
                   1512: 
                   1513:                 //
                   1514:                 // the entire source dir\file is still in static szName.
                   1515:                 // static lpszHold points to the end of the dir
                   1516:                 //
                   1517:                 *lpszHold = '\0';
                   1518: 
                   1519:                 lstrcpy(szDest, szName);
                   1520: 
                   1521:                 if( SendDlgItemMessage( hDlg, SB_SOURCE, WM_GETTEXT,
                   1522:                                         DIRECTORY_STRING_SIZE,
                   1523:                                         (LPARAM)lpszHold) == LB_ERR ){
                   1524:                     ErrorMsg("Rename: Get Source String Error");
                   1525:                     EndDialog(hDlg, wParam);
                   1526:                     return(1);
                   1527:                 }
                   1528: 
                   1529:                 //
                   1530:                 // If there are any \s in the new filename, fail.
                   1531:                 //
                   1532:                 lpszCheck = strchr(lpszHold, '\\');
                   1533: 
                   1534:                 if( lpszCheck ){
                   1535:                     ErrorMsg("Rename works only in current directory.");
                   1536:                     return(1);
                   1537:                 }
                   1538: 
                   1539:                 lpszHold = strchr(szDest, '\0');
                   1540: 
                   1541:                 if( SendDlgItemMessage( hDlg, SB_DEST, WM_GETTEXT,
                   1542:                                         DIRECTORY_STRING_SIZE,
                   1543:                                         (LPARAM)lpszHold) == LB_ERR ){
                   1544:                     ErrorMsg("Rename: Get Destination String Error");
                   1545:                     EndDialog(hDlg, wParam);
                   1546:                     return(1);
                   1547:                 }
                   1548: 
                   1549:                 //
                   1550:                 // If there are any \s in the new filename, fail.
                   1551:                 //
                   1552:                 lpszCheck = strchr(lpszHold, '\\');
                   1553: 
                   1554:                 if( lpszCheck ){
                   1555:                     ErrorMsg("Rename works only in current directory.");
                   1556:                     return(1);
                   1557:                 }
                   1558: 
                   1559:                 //
                   1560:                 // if strings are identical, leave.
                   1561:                 //
                   1562:                 if( !stricmp(szName, szDest) ){
                   1563:                     EndDialog(hDlg, wParam);
                   1564:                     return(1);
                   1565:                 }
                   1566: 
                   1567:                 if( !MoveFile( szName, szDest) )
                   1568:                     if( !HandleIOError(GetParent(hActiveLB),
                   1569:                                        (DWORD)MM_RENAME, szName, szDest) ){
                   1570:                         EndDialog(hDlg, wParam);
                   1571:                         return(1);
                   1572:                     }
                   1573: 
                   1574:                 //
                   1575:                 // Update files listbox.
                   1576:                 //
                   1577:                 SendMessage(GetParent(hActiveLB), WM_COMMAND, (WPARAM)MM_FILLFILE,
                   1578:                             (LPARAM)hActiveLB);
                   1579: 
                   1580:                 EndDialog(hDlg, wParam);
                   1581:                 return(1);
                   1582:             }
                   1583:             case SB_CANCEL:{
                   1584:                 EndDialog(hDlg, wParam);
                   1585:                 return(1);
                   1586:             }
                   1587:         }
                   1588:         return(1);
                   1589:       } // WM_COMMAND
                   1590:     }
                   1591: 
                   1592:     return(0);
                   1593: }
                   1594: 
                   1595: 
                   1596: /***************************************************************************\
                   1597: * MkDirProc()
                   1598: *
                   1599: * File I/O Make Directory Dialog Box
                   1600: *
                   1601: * History:
                   1602: * 6/5/92  2am
                   1603: *   Created.
                   1604: \***************************************************************************/
                   1605: LRESULT MkDirProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
                   1606: {
                   1607:     switch (message){
                   1608:       case WM_INITDIALOG:{
                   1609:         LPCINFO lpCInfo;
                   1610:         char    szDest[DIRECTORY_STRING_SIZE];
                   1611: 
                   1612: 
                   1613:         lpCInfo = (LPCINFO)lParam;
                   1614: 
                   1615:         lstrcpy(szDest, lpCInfo->CaptionBarText);
                   1616:         lstrcat(szDest, "\\");
                   1617: 
                   1618:         SendDlgItemMessage( hDlg, SB_DEST, EM_LIMITTEXT,
                   1619:                             (WPARAM)DIRECTORY_STRING_SIZE, (LPARAM)0);
                   1620: 
                   1621:         //
                   1622:         // Place name in directory name edit control.
                   1623:         //
                   1624:         if( SendDlgItemMessage( hDlg, SB_DEST, WM_SETTEXT, NULL,
                   1625:                                 (LPARAM)szDest) == LB_ERR ){
                   1626:             ErrorMsg("Mkdir: Add Directory Name String Error");
                   1627:             return(1);
                   1628:         }
                   1629: 
                   1630:         SendDlgItemMessage( hDlg, SB_DEST, EM_SETSEL, (WPARAM)-1, (LPARAM)0);
                   1631: 
                   1632:         return(1);
                   1633:       }
                   1634:       case WM_COMMAND:{
                   1635:         switch(wParam){
                   1636:             case SB_OK:{
                   1637:                 char    szDest[DIRECTORY_STRING_SIZE];
                   1638: 
                   1639:                 if( SendDlgItemMessage( hDlg, SB_DEST, WM_GETTEXT,
                   1640:                                         DIRECTORY_STRING_SIZE,
                   1641:                                         (LPARAM)szDest) == LB_ERR ){
                   1642:                     ErrorMsg("MkDir: Get Directory Location String Error");
                   1643:                     EndDialog(hDlg, wParam);
                   1644:                     return(1);
                   1645:                 }
                   1646: 
                   1647:                 //
                   1648:                 // If loacation of subdir is invalid, leave.
                   1649:                 //
                   1650:                 if( !CreateDirectory(szDest, NULL) ){
                   1651:                     ErrorMsg("Create Directory Error.");
                   1652:                     EndDialog(hDlg, wParam);
                   1653:                     return(1);
                   1654:                 }
                   1655:             }
                   1656:             case SB_CANCEL:{
                   1657:                 EndDialog(hDlg, wParam);
                   1658:                 return(1);
                   1659:             }
                   1660:         }
                   1661:         return(1);
                   1662:       }
                   1663:     }
                   1664: 
                   1665:     return(0);
                   1666: }
                   1667: 
                   1668: 
                   1669: /***************************************************************************\
                   1670: *
                   1671: * TextWndProc()
                   1672: *
                   1673: * Text Window procedure for displaying miscellaneous messages to user.
                   1674: *
                   1675: * History:
                   1676: * 5/25/92
                   1677: *   Created.
                   1678: *
                   1679: \***************************************************************************/
                   1680: 
1.1.1.2 ! root     1681: LRESULT WINAPI TextWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
1.1       root     1682: {
                   1683: 
                   1684:     switch (message)
                   1685:     {
                   1686:     case WM_CREATE:
                   1687:         {
                   1688:            HDC        hDC;
                   1689:            HGDIOBJ    hOldFont;
                   1690:             TEXTMETRIC tm;
                   1691:            LONG       lHeight;
                   1692: 
                   1693:            hDC = GetDC(hwnd);
                   1694: 
                   1695:            hOldFont = SelectObject(hDC, ghFont);
                   1696:            GetTextMetrics(hDC, &tm);
                   1697: 
                   1698:             //
                   1699:            // base the height of the window on size of text
                   1700:             //
                   1701:            lHeight = tm.tmHeight + GetSystemMetrics(SM_CYBORDER) + 6;
                   1702: 
                   1703:             //
                   1704:            // saved the height for later reference
                   1705:             //
                   1706:            SetWindowLong(hwnd, GWL_USERDATA, lHeight);
                   1707: 
                   1708:             if(hOldFont)
                   1709:                 SelectObject(hDC, hOldFont);
                   1710:             ReleaseDC(hwnd, hDC);
                   1711:             break;
                   1712:         }
                   1713: 
                   1714:     case WM_SETTEXT:
                   1715:             DefWindowProc(hwnd, message, wParam, lParam);
                   1716:             if( !InvalidateRect(hwnd, NULL, TRUE) ){
                   1717:                 ErrorMsg("Textwindow: Set text error.");
                   1718:                 return(1);
                   1719:             }
                   1720:             UpdateWindow(hwnd);
                   1721:             return(1);
                   1722: 
                   1723:     case WM_PAINT:
                   1724:         {
                   1725:             PAINTSTRUCT ps;
                   1726:             RECT        rc;
                   1727:             char        ach[128];
                   1728:             int         len, nxBorder, nyBorder;
                   1729:             HFONT       hOldFont = NULL;
                   1730:             HBRUSH      hBrush;
                   1731: 
                   1732:             BeginPaint(hwnd, &ps);
                   1733: 
                   1734:             GetClientRect(hwnd,&rc);
                   1735: 
                   1736:             len = GetWindowText(hwnd, ach, sizeof(ach));
                   1737: 
                   1738:            SetBkMode(ps.hdc, TRANSPARENT);
                   1739: 
                   1740:             if( GetParent(hwnd) == ghActiveChild ){
                   1741:                hBrush = CreateSolidBrush( GetSysColor(COLOR_ACTIVECAPTION) );
                   1742:                SetTextColor( ps.hdc, GetSysColor(COLOR_CAPTIONTEXT) );
                   1743:             }
                   1744:             else{
                   1745:                 hBrush = CreateSolidBrush( GetSysColor(COLOR_INACTIVECAPTION) );
                   1746:                SetTextColor( ps.hdc, GetSysColor(COLOR_INACTIVECAPTIONTEXT) );
                   1747:             }
                   1748: 
                   1749:            hOldFont = SelectObject(ps.hdc, ghFont);
                   1750: 
                   1751:             FillRect(ps.hdc, &rc, hBrush);
                   1752: 
                   1753:             nxBorder = GetSystemMetrics(SM_CXBORDER);
                   1754:            rc.left  += 9*nxBorder;
                   1755:             rc.right -= 9*nxBorder;
                   1756: 
                   1757:             nyBorder = GetSystemMetrics(SM_CYBORDER);
                   1758:            rc.top    += 3*nyBorder;
                   1759:            rc.bottom -= 3*nyBorder;
                   1760: 
                   1761:            ExtTextOut(ps.hdc, rc.left+2*nxBorder, rc.top, ETO_CLIPPED,
                   1762:                        &rc, ach, len, NULL);
                   1763: 
                   1764:            SetBkMode(ps.hdc, OPAQUE);
                   1765: 
                   1766:            if (hOldFont)
                   1767:                SelectObject(ps.hdc, hOldFont);
                   1768: 
                   1769:             DeleteObject(hBrush);
                   1770: 
                   1771:             EndPaint(hwnd, &ps);
                   1772:             return(1);
                   1773:         }
                   1774:     }
                   1775:     return DefWindowProc(hwnd, message, wParam, lParam);
                   1776: }

unix.superglobalmegacorp.com

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