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

1.1       root        1: /******************************Module*Header*******************************\
1.1.1.2 ! root        2: *
        !             3: *
        !             4: * Microsoft Developer Support
        !             5: * Copyright (c) 1992 Microsoft Corporation
        !             6: *
        !             7: *
1.1       root        8: * Module Name:  Filer.c
                      9: *
1.1.1.2 ! root       10: *
1.1       root       11: * Filer: SDK sample
                     12: *   +   Simple File Management program with GUI front end.
                     13: *       Demonstrates Win32 File I/O API and various User algorithms.
                     14: *
                     15: * Created: 5/05/92
                     16: * Author: Colin Stuart
                     17: *
                     18: * Copyright (c) 1990 Microsoft Corporation
                     19: *
                     20: * Dependencies:
                     21: *
                     22: *   (#defines)
                     23: *   (#includes)
                     24: *         -Enumdrv.h
                     25: *         -Walk.h
                     26: *         -Drvproc.h
                     27: *         -Filer.h
                     28: *
                     29: \**************************************************************************/
1.1.1.2 ! root       30: #define  STRICT
1.1       root       31: #include <windows.h>
                     32: #include <string.h>
                     33: #include <stdlib.h>
                     34: #include <stdarg.h>
                     35: #include "globals.h"
                     36: #include "enumdrv.h"
                     37: #include "walk.h"
                     38: #include "drvproc.h"
                     39: #include "filer.h"
                     40: 
                     41: //
                     42: // Global Handles
                     43: //
                     44: HANDLE  ghModule;                        // Process ID handle
                     45: 
                     46: HWND    ghwndMain;                       // Main window handle
                     47: HWND    ghwndDrives;                     // Drives Toolbar window handle
                     48: HWND    ghwndFunction;                   // Function Toolbar window handle
                     49: HWND    ghwndCommand;                    // Command Line window handle
                     50: HWND    ghwndDrv1,
                     51:         ghwndDrv2;
                     52: HWND    ghActiveChild = NULL;            // Handle to active drive child window
                     53: HWND    ghFocusLB;                       // Handle to last listbox with focus
                     54: 
                     55: 
                     56: HANDLE  ghHeap;                          // Application heap handle
                     57: HFONT   ghFont;
                     58: HANDLE  ghDrvThread = NULL;
                     59: 
                     60: HMENU   ghMenu;                          // App Menu variables
                     61: 
                     62: //
                     63: //   Global Data Items
                     64: //
                     65: BOOL                gfDrvWndOrient = SIDE_BY_SIDE; // relative Drv child pos.
                     66: 
                     67: DRVCHILDINFO        gDrvChild1Info,
                     68:                     gDrvChild2Info;
                     69: 
                     70: LPDINFO             glpDrives = NULL;    // Root of Available Drives linked list
                     71: 
                     72: CRITICAL_SECTION    gDrvCS;              // Drive list critical section var.
                     73: CRITICAL_SECTION    gHeapCS;             // Global heap critical section.
                     74: CRITICAL_SECTION    gSetDirCS;           // SetCurrentDirectory critical sect.
                     75: 
                     76: char    gszCommandLine[DIRECTORY_STRING_SIZE * 2];
                     77: char    gszExtensions[NUM_EXTENSION_STRINGS][EXTENSION_LENGTH];
                     78: 
                     79: 
                     80: /***************************************************************************\
                     81: * WinMain
                     82: *
                     83: *
                     84: * History:
                     85: * 04-17-91
                     86: *   Created.
                     87: \***************************************************************************/
1.1.1.2 ! root       88: int WINAPI WinMain(
1.1       root       89:     HINSTANCE hInstance,
                     90:     HINSTANCE hPrevInstance,
                     91:     LPSTR lpCmdLine,
                     92:     int nCmdShow)
                     93: {
                     94:     MSG    msg;
                     95:     HANDLE hAccel;
                     96: 
                     97:     ghModule = hInstance;
                     98:     if (!InitializeApp()) {
                     99:        ErrorMsg("Filer: InitializeApp failure!");
                    100:         return 0;
                    101:     }
                    102:     ShowWindow(ghwndMain, nCmdShow);
                    103: 
                    104:     if (!(hAccel = LoadAccelerators (ghModule, MAKEINTRESOURCE(ACCEL_ID))))
                    105:        ErrorMsg("Filer: Load Accel failure!");
                    106: 
                    107: 
                    108:     while (GetMessage(&msg, NULL, 0, 0)) {
                    109:         if( !TranslateAccelerator(ghwndMain, hAccel, &msg) ) {
                    110:             TranslateMessage(&msg);
                    111:             DispatchMessage(&msg);
                    112:         }
                    113:     }
                    114: 
                    115:     return 1;
                    116: 
                    117:     UNREFERENCED_PARAMETER(lpCmdLine);
                    118:     UNREFERENCED_PARAMETER(hPrevInstance);
                    119: }
                    120: 
                    121: 
                    122: /***************************************************************************\
                    123: * InitializeApp
                    124: *
                    125: * History:
                    126: * 5/5/92
                    127: *   Created
                    128: \***************************************************************************/
                    129: 
                    130: BOOL InitializeApp(void)
                    131: {
                    132:     WNDCLASS wc;
                    133: 
                    134:     wc.style            = NULL;
                    135:     wc.lpfnWndProc      = (WNDPROC)MainWndProc;
                    136:     wc.cbClsExtra       = 0;
                    137:     wc.cbWndExtra      = 0;
                    138:     wc.hInstance        = ghModule;
                    139:     wc.hIcon            = LoadIcon(ghModule, MAKEINTRESOURCE(UI_FILERICON));
                    140:     wc.hCursor          = LoadCursor(NULL, IDC_ARROW);
                    141:     wc.hbrBackground   = (HBRUSH)(COLOR_APPWORKSPACE);
                    142:     wc.lpszMenuName     = "FilerMenu";
                    143:     wc.lpszClassName   = "FilerClass";
                    144: 
                    145:     if (!RegisterClass(&wc))
                    146:        return(FALSE);
                    147: 
                    148:     wc.lpfnWndProc     = DrvWndProc;
                    149:     wc.hIcon           = NULL;
                    150:     wc.lpszMenuName    = NULL;
                    151:     wc.lpszClassName   = "DrvClass";
                    152: 
                    153:     if (!RegisterClass(&wc))
                    154:         return(FALSE);
                    155: 
                    156:     wc.style           = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
                    157:     wc.lpfnWndProc     = DriveBarProc;
                    158:     wc.hbrBackground   = (HBRUSH)(COLOR_BTNSHADOW);
                    159:     wc.lpszClassName   = "DriveBarClass";
                    160: 
                    161:     if (!RegisterClass(&wc))
                    162:             return(FALSE);
                    163: 
                    164:     wc.style           = CS_HREDRAW | CS_VREDRAW;
                    165:     wc.lpfnWndProc     = TextWndProc;
                    166:     wc.hbrBackground   = (HBRUSH)(COLOR_INACTIVECAPTION);
                    167:     wc.lpszClassName   = "TextClass";
                    168: 
                    169:     if (!RegisterClass(&wc))
                    170:             return(FALSE);
                    171: 
                    172:     ghMenu = LoadMenu(ghModule, "FilerMenu");
                    173: 
                    174:     ghwndMain = CreateWindow("FilerClass",
                    175:                              "Filer",
                    176:                              WS_OVERLAPPEDWINDOW,
                    177:                              CW_USEDEFAULT,
                    178:                              CW_USEDEFAULT,
                    179:                              MAIN_WIDTH,
                    180:                              MAIN_HEIGHT,
                    181:                             HWND_DESKTOP,
                    182:                              ghMenu,
                    183:                              ghModule,
                    184:                              NULL);
                    185: 
                    186:     if (ghwndMain == NULL)
                    187:        return(FALSE);
                    188: 
                    189:     return(TRUE);
                    190: }
                    191: 
                    192: 
                    193: /***************************************************************************\
                    194: * MainWndProc
                    195: *
                    196: * History:
                    197: * 05-01-92     Created.
                    198: \***************************************************************************/
                    199: 
1.1.1.2 ! root      200: LRESULT WINAPI MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
1.1       root      201: {
                    202:     switch (message) {
                    203: 
                    204:       case WM_CREATE:{
                    205:         LOGFONT    lf;
                    206:         HDC        hDC;
                    207:         HGDIOBJ    hOldFont;
                    208:         TEXTMETRIC tm;
                    209: 
                    210:         DWORD dwThreadID;
                    211: 
                    212:         //
                    213:         // Initialize drive list and Set Directory critical sections.
                    214:         //
                    215:         InitializeCriticalSection(&gDrvCS);
                    216:         InitializeCriticalSection(&gHeapCS);
                    217:         InitializeCriticalSection(&gSetDirCS);
                    218: 
                    219:         ghDrvThread = CreateThread(NULL, 0,
                    220:                                    (LPTHREAD_START_ROUTINE)EnumDrives,
                    221:                                    (LPVOID)&glpDrives,
                    222:                                    0, &dwThreadID);
                    223: 
                    224:         //
                    225:         // Create the application's heap
                    226:         //
                    227:         ghHeap = HeapCreate( 0, (DWORD)sizeof(DRVCHILDINFO), 0);
                    228:         if( ghHeap == NULL )
                    229:             ErrorMsg("Main Create: Failed in Creating Heap");
                    230: 
                    231:         //
                    232:         // Compute default application font by creating a bold version
                    233:         //   of the system default icon font.
                    234:         //
                    235:         SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(lf),
                    236:                              (PVOID) &lf, FALSE);
                    237: 
                    238:         hDC = GetDC(hwnd);
                    239: 
                    240:         //
                    241:         // this is the height for 8 point size font in pixels.
                    242:         //  (1 point = 1/72 in.)
                    243:         //
                    244:        lf.lfHeight = 8 * GetDeviceCaps(hDC, LOGPIXELSY) / 72;
                    245:        lf.lfWeight = BOLD_FONT;
                    246: 
                    247:        ghFont = CreateFontIndirect(&lf);
                    248:        hOldFont = SelectObject(hDC, ghFont);
                    249:        GetTextMetrics(hDC, &tm);
                    250:         if(hOldFont)
                    251:             SelectObject(hDC, hOldFont);
                    252:         ReleaseDC(hwnd, hDC);
                    253: 
                    254:         //
                    255:         // Create Drive windows
                    256:         //
                    257:         gDrvChild1Info.hParent = hwnd;
                    258:         gDrvChild2Info.hParent = hwnd;
                    259: 
                    260:        ghwndDrv1 = CreateWindow("DrvClass", NULL,
                    261:                                    WS_CHILD |
                    262:                                     WS_CLIPSIBLINGS | WS_VISIBLE,
                    263:                                    0, 0, 0, 0,
                    264:                                    hwnd, (HMENU) 1, ghModule,
                    265:                                     (LPVOID)&gDrvChild1Info);
                    266: 
                    267:         ghActiveChild = ghwndDrv1;
                    268: 
                    269:        ghwndDrv2 = CreateWindow("DrvClass", NULL,
                    270:                                    WS_CHILD |
                    271:                                     WS_CLIPSIBLINGS | WS_VISIBLE,
                    272:                                    0, 0, 0, 0,
                    273:                                    hwnd, (HMENU) 2, ghModule,
                    274:                                     (LPVOID)&gDrvChild2Info);
                    275: 
                    276:         //
                    277:         // Create DriveBar, FunctionBar and Command windows
                    278:         //
                    279:         ghwndDrives = CreateWindow("DriveBarClass", NULL,
                    280:                                    WS_CHILD | WS_VISIBLE | WS_BORDER,
                    281:                                    0, 0, 0, 0,
                    282:                                    hwnd, (HMENU) 3, ghModule,
                    283:                                    (LPVOID)NULL);
                    284: 
                    285:         ghwndFunction = CreateDialog(ghModule,
                    286:                                     "FunctionBar",
                    287:                                     hwnd,
1.1.1.2 ! root      288:                                     (DLGPROC)FunctionBarProc);
1.1       root      289: 
                    290:         ghwndCommand = CreateWindow("EDIT", NULL,
                    291:                                    ES_AUTOHSCROLL | ES_LEFT | WS_BORDER |
                    292:                                    ES_NOHIDESEL | WS_CHILD | WS_VISIBLE,
                    293:                                    0, 0, 0, 0,
                    294:                                    hwnd,
                    295:                                    (HMENU) 3,
                    296:                                    ghModule,
                    297:                                    NULL);
                    298: 
                    299:         //
                    300:         // Compute height of command window from font; store in window info.
                    301:         // Set command window to default font.
                    302:         //
                    303:         SetWindowLong( ghwndCommand, GWL_USERDATA,
                    304:                        tm.tmHeight + GetSystemMetrics(SM_CYBORDER) + 6);
                    305:         SendMessage(ghwndCommand, WM_SETFONT, (WPARAM)ghFont, (LPARAM)FALSE);
                    306: 
                    307:         //
                    308:         // Load String table entries
                    309:         //
                    310:         LoadString( ghModule, STR_EXE, &gszExtensions[0][0], EXTENSION_LENGTH);
                    311:         LoadString( ghModule, STR_COM, &gszExtensions[1][0], EXTENSION_LENGTH);
                    312:         LoadString( ghModule, STR_CMD, &gszExtensions[2][0], EXTENSION_LENGTH);
                    313:         LoadString( ghModule, STR_BAT, &gszExtensions[3][0], EXTENSION_LENGTH);
                    314: 
                    315:         UpdateDrivesMenu(ghMenu, ghDrvThread);
                    316: 
                    317:        return(1);
                    318:       }
                    319: 
                    320:       case WM_COMMAND:{
                    321: 
                    322:         //
                    323:         // The menu Identifiers for the drives are (potentially)
                    324:         // MM_DRIVE_NUM + 0 thru MM_DRIVE_NUM + 25. They all go to the
                    325:         // same case, so we will put the Menu ID in lParam, and
                    326:         // MM_DRIVE_NUM in LOWORD(wParam).
                    327:         //
                    328:         if( (LOWORD(wParam) - MM_DRIVE_NUM) <= 25 &&
                    329:             (LOWORD(wParam) - MM_DRIVE_NUM) >= 0 ){
                    330:             lParam = LOWORD(wParam);
                    331:             wParam = MM_DRIVE_NUM;
                    332:         }
                    333: 
                    334:        switch (LOWORD(wParam)) {
                    335:             //
                    336:             // If a drive is selected from the Drives menu, or clicked
                    337:             //  on the drives toolbar, the currently active child will
                    338:             //  switch to this drive. Message 'unconverted' (see top of
                    339:             //  WM_COMMAND case), and sent to DriveBarProc
                    340:             //
                    341:             case MM_DRIVE_NUM:{
                    342: 
                    343:                 SendMessage(ghwndDrives, WM_COMMAND,
                    344:                             (WPARAM)lParam, (LPARAM)NULL);
                    345:                 return(1);
                    346:             }
                    347: 
                    348:             //
                    349:             // Passes these WM_COMMAND messages to the appropriate active child
                    350:             //  window proc for processing
                    351:             //
                    352:             case MM_TAB:
                    353:             case MM_ESCAPE:
                    354:            case MM_OPEN:
                    355:            case MM_COPY:
                    356:            case MM_DELETE:
                    357:             case MM_MOVE:
                    358:            case MM_RENAME:
                    359:            case MM_MKDIR:{
                    360: 
                    361:                 SendMessage(ghActiveChild, WM_COMMAND, wParam, lParam);
                    362:                return(1);
                    363:            }
                    364: 
                    365:             //
                    366:             // Creates the drive enumeration thread to re-enumerate the
                    367:             //   available drives in the main menu.  Also sends a refresh
                    368:             //   to the active drive child, and repaints the window.
                    369:             //
                    370:            case MM_REFRESH: {
                    371:                 DWORD   dwThreadID;
                    372:                 DWORD   dwExitCode = 0;
                    373: 
                    374:                 //
                    375:                 // Initialize/Refresh Drives linked list
                    376:                 //
                    377:                 GetExitCodeThread( ghDrvThread, &dwExitCode);
                    378: 
                    379:                 if( dwExitCode != STILL_ACTIVE ){
                    380: 
                    381:                     ghDrvThread = CreateThread(NULL, 0,
                    382:                                            (LPTHREAD_START_ROUTINE)EnumDrives,
                    383:                                            (LPVOID)&glpDrives,
                    384:                                            0, &dwThreadID);
                    385: 
                    386:                     //
                    387:                     // Refresh active child, drive toolbar, and drives menu
                    388:                     //
                    389:                    SendMessage(ghActiveChild, WM_COMMAND, wParam, lParam);
                    390:                    SendMessage(ghwndDrives, WM_COMMAND, wParam, lParam);
                    391:                     UpdateDrivesMenu(ghMenu, ghDrvThread);
                    392: 
                    393:                     //
                    394:                     // Mark all for repaint
                    395:                     //
                    396:                     InvalidateRect(hwnd,NULL,TRUE);
                    397: 
                    398:                 }
                    399:                 else
                    400:                     MessageBeep(MB_ICONASTERISK);
                    401:                 return(1);
                    402:             }
                    403: 
                    404:             //
                    405:             // Swaps the directory and file list boxes of the active drv child.
                    406:             //
                    407:             case MM_SWAP:{
                    408:                 HWND    hHold;
                    409:                 LPCINFO lpCInfo;
                    410:                 RECT    rect;
                    411: 
                    412:                 lpCInfo = (LPCINFO)GetWindowLong(ghActiveChild, GWL_USERDATA);
                    413:                 hHold = lpCInfo->hwndLL;
                    414:                 lpCInfo->hwndLL = lpCInfo->hwndLR;
                    415:                 lpCInfo->hwndLR = hHold;
                    416: 
                    417:                 //
                    418:                 // Send size message with current size to active child,
                    419:                 //   in order to redraw the listboxes.
                    420:                 //
                    421:                 if( !GetClientRect( ghActiveChild, &rect ) )
                    422:                     return(0);
                    423: 
                    424:                 SendMessage( ghActiveChild, WM_SIZE, SIZENORMAL,
                    425:                              MAKELONG( rect.right - rect.left,
                    426:                                        rect.bottom - rect.top) );
                    427:                 return(1);
                    428:             }
                    429: 
                    430:             //
                    431:             // Toggles the relative Drive Child orientaion between
                    432:             // Over/under and side/side.  gfDrvWndOrient is a flag checked
                    433:             // by WM_SIZE to size Drv children
                    434:             //
                    435:             case MM_ORIENT:{
                    436:                 RECT    rect;
                    437: 
                    438:                 if( gfDrvWndOrient == OVER_UNDER )
                    439:                     gfDrvWndOrient = SIDE_BY_SIDE;
                    440:                 else
                    441:                     gfDrvWndOrient = OVER_UNDER;
                    442: 
                    443:                 //
                    444:                 // Send size message with current size to self (main window),
                    445:                 //   in order to redraw the Drv children.
                    446:                 //
                    447:                 if( !GetClientRect( hwnd, &rect ) )
                    448:                     return(0);
                    449: 
                    450:                 SendMessage( hwnd, WM_SIZE, SIZENORMAL,
                    451:                              MAKELONG( rect.right - rect.left,
                    452:                                        rect.bottom - rect.top) );
                    453: 
                    454:                 InvalidateRect(ghwndDrv1,NULL,TRUE);
                    455:                 InvalidateRect(ghwndDrv2,NULL,TRUE);
                    456: 
                    457:                 return(1);
                    458:             }
                    459: 
                    460:             //
                    461:             // Toggles the active drive child.  Sent from menu.
                    462:             // This behaves the same as a WM_MOUSEACTIVATE in one of the
                    463:             //   Drive children.  The PostMessage is so the current Active
                    464:             //   child will not process the MM_TOGGLE message until after it
                    465:             //   is no longer active.
                    466:             //
                    467:             case MM_ACTIVEDRV:{
                    468: 
                    469:                 PostMessage(ghActiveChild, WM_COMMAND, (WPARAM)MM_TOGGLE,
                    470:                             (LPARAM)NULL);
                    471: 
                    472:                 if( ghActiveChild == ghwndDrv1 )
                    473:                     ghActiveChild = ghwndDrv2;
                    474:                 else
                    475:                     ghActiveChild = ghwndDrv1;
                    476: 
                    477:                 SendMessage(ghActiveChild, WM_COMMAND, (WPARAM)MM_TOGGLE,
                    478:                             (LPARAM)NULL);
                    479: 
                    480:                 return(1);
                    481:             }
                    482: 
                    483:             //
                    484:             // Launches the About DialogBox.
                    485:             //
                    486:            case MM_ABOUT:{
                    487:                if (DialogBox(ghModule, "AboutBox", ghwndMain, (DLGPROC)AboutProc) == -1)
                    488:                        ErrorMsg("Main: About Dialog Creation Error!");
                    489:                return(1);
                    490:             }
                    491: 
                    492:            default:
                    493:                return( DefWindowProc(hwnd, message, wParam, lParam) );
                    494:         }
                    495:         return(1);
                    496:       }
                    497:       //
                    498:       // Whenever the window is resized, its children have to be
                    499:       //  resized accordingly.  The GetWindowLong values are the height
                    500:       //  of the windows queried by this function, and are set in the
                    501:       //  WM_CREATE cases of their respective WNDPROCs.
                    502:       //
                    503:       case WM_SIZE:{
                    504:         int DrvWndHeight;
                    505: 
                    506:         //
                    507:         // Always put the command window at the bottom of the frame window
                    508:         //
                    509:         MoveWindow(ghwndCommand,
                    510:               0,
                    511:               HIWORD(lParam) - GetWindowLong(ghwndCommand, GWL_USERDATA),
                    512:               LOWORD(lParam),
                    513:               GetWindowLong(ghwndCommand, GWL_USERDATA),
                    514:                TRUE);
                    515:         //
                    516:         // Always put the drives toolbar at the top of the frame window
                    517:         //
                    518:         MoveWindow(ghwndDrives,
                    519:               0,
                    520:               0,
                    521:               LOWORD(lParam),
                    522:               GetWindowLong(ghwndDrives, GWL_USERDATA),
                    523:                TRUE);
                    524: 
                    525:         //
                    526:         // Always put the Function window just below the drives toolbar.
                    527:         //
                    528:         MoveWindow(ghwndFunction,
                    529:                    0,
                    530:                    GetWindowLong(ghwndDrives, GWL_USERDATA),
                    531:                    LOWORD(lParam),
                    532:                    GetWindowLong(ghwndFunction, GWL_USERDATA),
                    533:                    TRUE);
                    534: 
                    535:         //
                    536:         // Always size the Drive Children between the Drives and Command
                    537:         // windows. The width is set so that borders overlap.
                    538:         //
                    539: 
                    540:         if( gfDrvWndOrient == OVER_UNDER ){
                    541: 
                    542:             DrvWndHeight = ( HIWORD(lParam) -
                    543:                            GetWindowLong(ghwndDrives, GWL_USERDATA) -
                    544:                            GetWindowLong(ghwndFunction, GWL_USERDATA) -
                    545:                            GetWindowLong(ghwndCommand, GWL_USERDATA) ) / 2;
                    546: 
                    547:             MoveWindow(ghwndDrv1,
                    548:                    -1,
                    549:                   GetWindowLong(ghwndDrives, GWL_USERDATA)+
                    550:                      GetWindowLong(ghwndFunction, GWL_USERDATA),
                    551:                   LOWORD(lParam) + 2,
                    552:                    DrvWndHeight,
                    553:                    TRUE);
                    554: 
                    555:             MoveWindow(ghwndDrv2,
                    556:                   -1,
                    557:                   GetWindowLong(ghwndDrives, GWL_USERDATA)+
                    558:                      GetWindowLong(ghwndFunction, GWL_USERDATA) + DrvWndHeight,
                    559:                   LOWORD(lParam) + 2,
                    560:                    DrvWndHeight,
                    561:                    TRUE);
                    562:         }
                    563:         else{
                    564: 
                    565:             DrvWndHeight = HIWORD(lParam) -
                    566:                            GetWindowLong(ghwndDrives, GWL_USERDATA) -
                    567:                            GetWindowLong(ghwndFunction, GWL_USERDATA) -
                    568:                            GetWindowLong(ghwndCommand, GWL_USERDATA);
                    569: 
                    570:             MoveWindow(ghwndDrv1,
                    571:                    -1,
                    572:                   GetWindowLong(ghwndDrives, GWL_USERDATA)+
                    573:                      GetWindowLong(ghwndFunction, GWL_USERDATA),
                    574:                   LOWORD(lParam)/2 + 1,
                    575:                    DrvWndHeight,
                    576:                    TRUE);
                    577: 
                    578:             MoveWindow(ghwndDrv2,
                    579:                   LOWORD(lParam)/2,
                    580:                   GetWindowLong(ghwndDrives, GWL_USERDATA)+
                    581:                      GetWindowLong(ghwndFunction, GWL_USERDATA),
                    582:                   LOWORD(lParam)/2 + 1,
                    583:                    DrvWndHeight,
                    584:                    TRUE);
                    585:         }
                    586: 
                    587:        return(1);
                    588:       }
                    589: 
                    590:       case WM_DESTROY: {
                    591:         EnterCriticalSection(&gHeapCS);
                    592:         HeapDestroy(ghHeap);
                    593:         LeaveCriticalSection(&gHeapCS);
                    594: 
                    595:         DeleteObject(ghFont);
                    596: 
                    597:         DeleteCriticalSection(&gDrvCS);
                    598:         DeleteCriticalSection(&gSetDirCS);
                    599: 
                    600:        PostQuitMessage(0);
                    601:        return(1);
                    602:       }
                    603: 
                    604:       default:
                    605:         return DefWindowProc(hwnd, message, wParam, lParam);
                    606:     }
                    607: }
                    608: 
                    609: /***************************************************************************\
                    610: * AboutProc
                    611: *
                    612: * About dialog proc.
                    613: *
                    614: * History:
                    615: *   05-13-92      Created.
                    616: \***************************************************************************/
                    617: 
1.1.1.2 ! root      618: LRESULT WINAPI AboutProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1.1       root      619: {
                    620:     switch (message) {
                    621:       case WM_INITDIALOG:{
                    622:         return TRUE;
                    623:       }
                    624: 
                    625:       case WM_COMMAND:{
                    626:         if (wParam == IDOK)
                    627:             EndDialog(hDlg, wParam);
                    628:         break;
                    629:       }
                    630:     }
                    631: 
                    632:     return FALSE;
                    633: 
                    634:     UNREFERENCED_PARAMETER(lParam);
                    635:     UNREFERENCED_PARAMETER(hDlg);
                    636: }
                    637: 
                    638: 
                    639: /***************************************************************************\
                    640: *
                    641: * DriveBarProc()
                    642: *
                    643: * Drive Toolbar procedure for displaying available drive Icons.
                    644: *  A bitmap button is displayed corresponding to the drive type of the
                    645: *  given drive, with the drive letter alongside.
                    646: *  ghwndDrives is the global handle assoc. w/ this window procedure.
                    647: *
                    648: *
                    649: * History:
                    650: * 6/9/92
                    651: *   Created.
                    652: *
                    653: \***************************************************************************/
                    654: 
1.1.1.2 ! root      655: LRESULT WINAPI DriveBarProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
1.1       root      656: {
                    657:     static HBITMAP  hDrvBmp[NUM_BITMAPS];
                    658:     static HBRUSH   hBrush;         // background brush
                    659:     static int      nDrvEntryWidth; // width of button/letter entry
                    660:     static int      yVal;           // y value in toolbar for top left of bmp
                    661:     static LPBINFO  lpDrvButtonRoot;
                    662:     static int      nActiveDrvIndex;
                    663: 
                    664:     switch (message)
                    665:     {
                    666:         case WM_CREATE:{
                    667:             HDC        hDC;
                    668:             HGDIOBJ    hOldFont;
                    669:             TEXTMETRIC tm;
                    670:            LONG       lHeight;
                    671: 
                    672: 
                    673:             lpDrvButtonRoot = NULL;
                    674: 
                    675:             //
                    676:             // Load drive button bitmaps.
                    677:             //
                    678:             for(yVal = 0; yVal < NUM_BITMAPS; yVal++)
                    679:                 hDrvBmp[yVal] = LoadBitmap( ghModule,
                    680:                                       MAKEINTRESOURCE(UB_BMP_MARKER + yVal) );
                    681: 
                    682:             //
                    683:             // Sets background color of Toolbar non-modal dialog children.
                    684:             //
                    685:             hBrush = CreateSolidBrush(GetSysColor(COLOR_BTNSHADOW));
                    686: 
                    687:             hDC = GetDC(hwnd);
                    688: 
                    689:            hOldFont = SelectObject(hDC, ghFont);
                    690:            GetTextMetrics(hDC, &tm);
                    691: 
                    692:             //
                    693:            // base the height of the window on size of text
                    694:             //
                    695:            lHeight = tm.tmHeight + GetSystemMetrics(SM_CYBORDER) + 6;
                    696: 
                    697:             //
                    698:            // saved the window height, drive button entry width
                    699:             //   and button y starting value for later reference
                    700:             //
                    701:            SetWindowLong(hwnd, GWL_USERDATA, lHeight);
                    702: 
                    703:             //
                    704:             // Width of one button entry = spacing, button, sm. space,
                    705:             //   drive letter, spacing.
                    706:             //
                    707:             nDrvEntryWidth = DRIVE_BITMAP_SPACING + DRIVE_BITMAP_WIDTH +
                    708:                              DRIVE_LETTER_SPACING + tm.tmAveCharWidth +
                    709:                              DRIVE_BITMAP_SPACING;
                    710: 
                    711:             //
                    712:             // Center bitmaps (by height) in drive toolbar.
                    713:             //
                    714:             yVal = (lHeight - DRIVE_BITMAP_HEIGHT)/2;
                    715: 
                    716:             SelectObject(hDC, hOldFont);
                    717:             ReleaseDC(hwnd, hDC);
                    718: 
                    719:             SendMessage(hwnd, WM_COMMAND, (WPARAM)MM_REFRESH, (LPARAM)NULL);
                    720: 
                    721:            break;
                    722:         }
                    723: 
                    724:         case WM_COMMAND:{
                    725:             //
                    726:             // The button Identifiers for the drives are (potentially)
                    727:             // MM_DRIVE_NUM + 0 thru MM_DRIVE_NUM + 25. They all go to the
                    728:             // same case, so we will put the Menu ID in lParam, and
                    729:             // MM_DRIVE_NUM in LOWORD(wParam).
                    730:             //
                    731:             if( (LOWORD(wParam) - MM_DRIVE_NUM) <= 25 &&
                    732:                 (LOWORD(wParam) - MM_DRIVE_NUM) >= 0 ){
                    733:                 lParam = LOWORD(wParam);
                    734:                 wParam = MM_DRIVE_NUM;
                    735:             }
                    736: 
                    737:             switch( LOWORD(wParam) ){
                    738:               case MM_REFRESH:{
                    739: 
                    740:                 LPDINFO lpWalk;
                    741:                 LPBINFO lpBWalk, lpBHold;
                    742:                 LPCINFO lpCInfo;
                    743:                 int     xVal = 0;
                    744:                 int     nCount = MM_DRIVE_NUM;
                    745: 
                    746:                 lpCInfo = (LPCINFO)GetWindowLong(ghActiveChild, GWL_USERDATA);
                    747: 
                    748:                 //
                    749:                 // Traverse DRVINFO linked list, creating drive buttons and
                    750:                 //   allocating corresp. structures as necessary.
                    751:                 //
                    752:                 EnterCriticalSection(&gDrvCS);
                    753:                 lpWalk = glpDrives;
                    754:                 lpBWalk = lpDrvButtonRoot;
                    755: 
                    756:                 while( lpWalk != NULL ){
                    757:                     if( lpBWalk == NULL ){
                    758: 
                    759:                         EnterCriticalSection(&gHeapCS);
                    760:                         lpBWalk = (LPBINFO)HeapAlloc(ghHeap, sizeof(BINFO));
                    761:                         LeaveCriticalSection(&gHeapCS);
                    762: 
                    763:                         lpBWalk->lpDrive = lpWalk;
                    764:                         lpBWalk->fButtonDown = FALSE;
                    765:                         if( lpDrvButtonRoot == NULL)
                    766:                             lpDrvButtonRoot = lpBHold = lpBWalk;
                    767:                         else{
                    768:                             lpBHold->next = lpBWalk;
                    769:                             lpBWalk->next = NULL;
                    770:                         }
                    771:                     }
                    772:                     if( lpCInfo->lpDriveInfo == lpWalk ){
                    773:                         nActiveDrvIndex = nCount;
                    774:                         lpBWalk->fButtonDown = TRUE;
                    775:                     }
                    776:                     else
                    777:                         lpBWalk->fButtonDown = FALSE;
                    778: 
                    779:                     lpBWalk->lpDrive = lpWalk;
                    780: 
                    781:                     lpBWalk->hButton = (HANDLE)CreateWindow("BUTTON",
                    782:                                              lpWalk->DriveName,
                    783:                                              WS_CHILD | WS_VISIBLE |
                    784:                                              BS_OWNERDRAW,
                    785:                                              xVal + DRIVE_BITMAP_SPACING,
                    786:                                              yVal,
                    787:                                              DRIVE_BITMAP_WIDTH,
                    788:                                              DRIVE_BITMAP_HEIGHT,
                    789:                                              hwnd,
                    790:                                              (HMENU)nCount,
                    791:                                              ghModule,
                    792:                                              NULL);
                    793: 
                    794:                     nCount++;
                    795:                     xVal += nDrvEntryWidth;
                    796:                     lpBHold = lpBWalk;
                    797:                     lpBWalk = lpBWalk->next;
                    798: 
                    799:                     lpWalk = lpWalk->next;
                    800:                 }
                    801: 
                    802:                 LeaveCriticalSection(&gDrvCS);
                    803: 
                    804:                 //
                    805:                 // Free any remaining button windows.
                    806:                 //
                    807:                 while( lpBWalk != NULL ){
                    808:                     lpBHold = lpBWalk;
                    809:                     lpBWalk = lpBWalk->next;
                    810:                     if( !DestroyWindow(lpBHold->hButton) )
                    811:                         ErrorMsg("DriveBarProc: Drive Button Destroy Error");
                    812: 
                    813:                     EnterCriticalSection(&gHeapCS);
                    814:                     HeapFree(ghHeap, (LPSTR)lpBHold);
                    815:                     LeaveCriticalSection(&gHeapCS);
                    816:                 }
                    817: 
                    818:                 SendMessage(hwnd, WM_PAINT, (WPARAM)NULL, (LPARAM)NULL);
                    819:                 break;
                    820:               }
                    821: 
                    822: 
                    823:               //
                    824:               // switches the drive button to the newly active drv child's
                    825:               //   current drive.  Called by WM_MOUSEACTIVATE in DrvWndProc,
                    826:               //   as well as ChangeDrive.
                    827:               //   lParam contains the drive linked list pointer of the active
                    828:               //   drv child's LPCINFO struct.
                    829:               //
                    830:               case MM_ACTIVEDRV:{
                    831:                 LPBINFO lpBWalk = lpDrvButtonRoot;
                    832:                 int     nCount = 0;
                    833: 
                    834:                 //
                    835:                 // 'unpush' old active button
                    836:                 //
                    837:                 for( nCount = MM_DRIVE_NUM; nCount < nActiveDrvIndex; nCount++)
                    838:                     lpBWalk = lpBWalk->next;
                    839:                 lpBWalk->fButtonDown = FALSE;
                    840: 
                    841:                 InvalidateRect(lpBWalk->hButton, NULL, FALSE);
                    842: 
                    843:                 //
                    844:                 // change active drive to new before redrawing old.
                    845:                 //   'push' new active button
                    846:                 //
                    847:                 lpBWalk = lpDrvButtonRoot;
                    848:                 nCount = MM_DRIVE_NUM;
                    849:                 while( lpBWalk->lpDrive != (LPDINFO)lParam){
                    850:                     lpBWalk = lpBWalk->next;
                    851:                     nCount++;
                    852:                 }
                    853: 
                    854:                 nActiveDrvIndex = nCount;
                    855: 
                    856:                 lpBWalk->fButtonDown = TRUE;
                    857: 
                    858:                 InvalidateRect(lpBWalk->hButton, NULL, FALSE);
                    859: 
                    860:                 break;
                    861:               }
                    862: 
                    863:               //
                    864:               // Changes drive of active child.  ButtonID in lParam.
                    865:               //
                    866:               case MM_DRIVE_NUM:{
                    867: 
                    868:                 LPBINFO lpBWalk = lpDrvButtonRoot;
                    869:                 int     nCount = 0;
                    870:                 CHAR    szDrvBuff[DIRECTORY_STRING_SIZE];
                    871: 
                    872:                 //
                    873:                 // if drive chosen is already current drive, leave.
                    874:                 //
                    875:                 if( nActiveDrvIndex == (int)lParam )
                    876:                     break;
                    877: 
                    878:                 //
                    879:                 // 'unpush' old active button
                    880:                 //
                    881:                 for( nCount = MM_DRIVE_NUM; nCount < nActiveDrvIndex; nCount++)
                    882:                     lpBWalk = lpBWalk->next;
                    883:                 lpBWalk->fButtonDown = FALSE;
                    884: 
                    885:                 //
                    886:                 // change active drive to new before redrawing old.
                    887:                 //
                    888:                 nActiveDrvIndex = (int)lParam;
                    889: 
                    890:                 InvalidateRect(lpBWalk->hButton, NULL, FALSE);
                    891: 
                    892:                 //
                    893:                 // 'push' new active button
                    894:                 //
                    895:                 lpBWalk = lpDrvButtonRoot;
                    896: 
                    897:                 for( nCount = MM_DRIVE_NUM; nCount < nActiveDrvIndex; nCount++)
                    898:                     lpBWalk = lpBWalk->next;
                    899:                 lpBWalk->fButtonDown = TRUE;
                    900: 
                    901:                 InvalidateRect(lpBWalk->hButton, NULL, FALSE);
                    902: 
                    903:                 GetWindowText(lpBWalk->hButton, szDrvBuff,
                    904:                               DIRECTORY_STRING_SIZE);
                    905: 
                    906:                 if( !ChangeDrive(szDrvBuff, (DWORD)nActiveDrvIndex) ){
                    907:                     ErrorMsg("Error changing Drives.");
                    908:                     return(0);
                    909:                 }
                    910: 
                    911:                 break;
                    912:               }
                    913:             }
                    914:             return(1);
                    915:         }
                    916: 
                    917:         //
                    918:         // Sent by all created buttons for initialization purposes.
                    919:         //
                    920:         case WM_MEASUREITEM:{
                    921:             LPMEASUREITEMSTRUCT lpMIS;
                    922: 
                    923:             lpMIS = (LPMEASUREITEMSTRUCT)lParam;
                    924: 
                    925:             lpMIS->CtlType = ODT_BUTTON;
                    926:             lpMIS->CtlID = (UINT)wParam;
                    927:             lpMIS->itemWidth = DRIVE_BITMAP_WIDTH;
                    928:             lpMIS->itemHeight = DRIVE_BITMAP_HEIGHT;
                    929: 
                    930:             return(1);
                    931:         }
                    932: 
                    933:         //
                    934:         // Sent by owner draw drive buttons when needing redrawing.
                    935:         //
                    936:         case WM_DRAWITEM:{
                    937:             LPBINFO lpBWalk = lpDrvButtonRoot;
                    938:             int     nCount;
                    939:             int     nBmpIndex;
                    940:             HDC     hDC;
                    941:             HDC     hCompatDC;
                    942:             HGDIOBJ hOldBitmap;
                    943:             CHAR    szDrvBuff[DIRECTORY_STRING_SIZE];
                    944:             LPDRAWITEMSTRUCT    lpDIS;
                    945: 
                    946:             lpDIS = (LPDRAWITEMSTRUCT)lParam;
                    947: 
                    948:             for( nCount = MM_DRIVE_NUM; nCount < (int)wParam; nCount++)
                    949:                 lpBWalk = lpBWalk->next;
                    950: 
                    951:             //
                    952:             // If not the current selected button, handle button stuff.
                    953:             //
                    954:             if( (int)wParam != nActiveDrvIndex ){
                    955:                 //
                    956:                 // mousebutton is down...
                    957:                 //
                    958:                 if( lpDIS->itemAction & ODA_SELECT ){
                    959:                     //
                    960:                     // left button region, 'unpush' button
                    961:                     //
                    962:                     if( lpDIS->itemState == (UINT)ODS_FOCUS )
                    963:                         lpBWalk->fButtonDown = FALSE;
                    964:                     //
                    965:                     // clicked on a button, draw 'pushed' button
                    966:                     //
                    967:                     if( lpDIS->itemState == (UINT)(ODS_SELECTED | ODS_FOCUS))
                    968:                         lpBWalk->fButtonDown = TRUE;
                    969:                 }
                    970:             }
                    971: 
                    972:             //
                    973:             // draw current state of button.
                    974:             //
                    975:             GetWindowText(lpDIS->hwndItem, szDrvBuff,
                    976:                           DIRECTORY_STRING_SIZE);
                    977: 
                    978:             szDrvBuff[1] = '\0';
                    979: 
                    980:             hCompatDC = CreateCompatibleDC(lpDIS->hDC);
                    981:             hOldBitmap = CreateCompatibleBitmap(hCompatDC,
                    982:                                                 DRIVE_BITMAP_WIDTH,
                    983:                                                 DRIVE_BITMAP_HEIGHT);
                    984: 
                    985:             nBmpIndex = GetDriveBitmap(lpBWalk);
                    986: 
                    987:             SelectObject( hCompatDC, hDrvBmp[nBmpIndex] );
                    988: 
                    989:             if( !hOldBitmap )
                    990:                 OutputDebugString("WM_DRAWITEM: SelectObject error\n");
                    991: 
                    992:             if( !BitBlt(lpDIS->hDC, lpDIS->rcItem.left, lpDIS->rcItem.top,
                    993:                    DRIVE_BITMAP_WIDTH,
                    994:                    DRIVE_BITMAP_HEIGHT,
                    995:                    hCompatDC, 0, 0, SRCCOPY) )
                    996:                 OutputDebugString("WM_DRAWITEM: BitBlt error\n");
                    997: 
                    998: 
                    999:             SelectObject( hCompatDC, hOldBitmap);
                   1000:             DeleteDC(hCompatDC);
                   1001: 
                   1002:             hDC = GetDC(hwnd);
                   1003:             SetBkMode(hDC, TRANSPARENT);
                   1004:             SetTextColor(hDC, GetSysColor(COLOR_BTNTEXT) );
                   1005:             SetBkColor(hDC, GetSysColor(COLOR_BTNSHADOW) );
                   1006: 
                   1007:             TextOut(hDC,
                   1008:                     ((int)(wParam - MM_DRIVE_NUM) * nDrvEntryWidth) +
                   1009:                         DRIVE_BITMAP_SPACING + DRIVE_BITMAP_WIDTH +
                   1010:                         DRIVE_LETTER_SPACING,
                   1011:                     (GetSystemMetrics(SM_CYBORDER) + 6)/2,
                   1012:                     szDrvBuff, 1);
                   1013: 
                   1014:            SetBkMode(hDC, OPAQUE);
                   1015: 
                   1016:             ReleaseDC(hwnd, hDC);
                   1017: 
                   1018:             break;
                   1019:         }
                   1020: 
                   1021: 
                   1022:         case WM_PAINT:{
                   1023:             HDC     hCompatDC;
                   1024:             RECT     rc;
                   1025:             PAINTSTRUCT ps;
                   1026: 
                   1027:             //
                   1028:             // Paint btnshadow background.
                   1029:             //
                   1030:             GetClientRect(hwnd, &rc);
                   1031: 
                   1032:             BeginPaint(hwnd, &ps);
                   1033: 
                   1034:             hCompatDC = CreateCompatibleDC(ps.hdc);
                   1035:             FillRect(ps.hdc, &rc, hBrush);
                   1036: 
                   1037:             EndPaint(hwnd, &ps);
                   1038: 
                   1039:             return(TRUE);
                   1040:         }
                   1041: 
                   1042:         case WM_DESTROY:{
                   1043:             DeleteObject(hBrush);
                   1044: 
                   1045:             for(yVal = 0; yVal < NUM_BITMAPS; yVal++)
                   1046:                 DeleteObject(hDrvBmp[yVal]);
                   1047: 
                   1048:             break;
                   1049:         }
                   1050:     }
                   1051:     return DefWindowProc(hwnd, message, wParam, lParam);
                   1052: }
                   1053: 
                   1054: 
                   1055: /***************************************************************************\
                   1056: *
                   1057: * GetDriveBitmap()
                   1058: *
                   1059: * Determines the appropriate index into the drive button bitmap array
                   1060: *   (hDrvBmp[]), given a pointer to a drive info structure (LPDINFO)
                   1061: *
                   1062: *   lpWalk          -   pointer to LPDINFO structure.
                   1063: *   lpCurrentDrv    -   pointer to current drive of active child.
                   1064: *
                   1065: *
                   1066: * History:
                   1067: * 6/16/92
                   1068: *   Created.
                   1069: *
                   1070: \***************************************************************************/
                   1071: int GetDriveBitmap(LPBINFO lpBWalk)
                   1072: {
                   1073:     int nBmpIndex;
                   1074: 
                   1075:     EnterCriticalSection(&gDrvCS);
                   1076: 
                   1077:     switch( lpBWalk->lpDrive->DriveType ){
                   1078:         case DRIVE_REMOVABLE:{
                   1079:           nBmpIndex = UB_FLOPPY1 - UB_BMP_MARKER;
                   1080:           break;
                   1081:         }
                   1082: 
                   1083:         case DRIVE_REMOTE:{
                   1084:           nBmpIndex = UB_REMOTE1 - UB_BMP_MARKER;
                   1085:             break;
                   1086:         }
                   1087: 
                   1088:         case DRIVE_CDROM:{
                   1089:           nBmpIndex = UB_CD1 - UB_BMP_MARKER;
                   1090:             break;
                   1091:         }
                   1092: 
                   1093:         case DRIVE_FIXED:
                   1094:         default:{
                   1095:           nBmpIndex = UB_FIXED1 - UB_BMP_MARKER;
                   1096:             break;
                   1097:         }
                   1098:     }
                   1099: 
                   1100:     LeaveCriticalSection(&gDrvCS);
                   1101: 
                   1102:     if( lpBWalk->fButtonDown == TRUE )
                   1103:         nBmpIndex++;
                   1104: 
                   1105:     return(nBmpIndex);
                   1106: }
                   1107: 
                   1108: 
                   1109: /***************************************************************************\
                   1110: *
                   1111: * ChangeDrive()
                   1112: *
                   1113: *   Changes the current drive of the active child.  Called by the MM_DRIVE_NUM
                   1114: *     cases in MainWndProc and DriveBarProc.  This is caused by choosing a
                   1115: *     Drive menu item or selecting a drive button from the drive toolbar.
                   1116: *
                   1117: *     lpszDriveName -   points to a buffer containing the name of the drive
                   1118: *     DriveID       -   points to the ID of the Menu item or button, which
                   1119: *                         corresponds to the index into the drives linked list
                   1120: *                         of the new drive.
                   1121: *
                   1122: * History:
                   1123: * 6/20/92
                   1124: *   Created.
                   1125: *
                   1126: \***************************************************************************/
                   1127: BOOL ChangeDrive(LPSTR lpszDriveName, DWORD DriveIndex)
                   1128: {
                   1129:     LPCINFO     lpCInfo;
                   1130:     LPDINFO     lpWalk;
                   1131:     DWORD       dwLoop;
                   1132: 
                   1133:     //
                   1134:     // Retrieve active child handle.
                   1135:     //
                   1136:     if( (ghActiveChild != ghwndDrv1) &&
                   1137:         (ghActiveChild != ghwndDrv2) ){
                   1138:         ErrorMsg("A Drive Window Must be Active.");
                   1139:         return(0);
                   1140:     }
                   1141: 
                   1142:     //
                   1143:     // Retrieving the child window's DRVCHILDINFO data
                   1144:     //
                   1145:     lpCInfo = (LPCINFO)GetWindowLong(ghActiveChild, GWL_USERDATA);
                   1146: 
                   1147:     //
                   1148:     // Enter Drive list critical section
                   1149:     //
                   1150:     EnterCriticalSection(&gDrvCS);
                   1151: 
                   1152:     //
                   1153:     // if removable drive, check for existing media.
                   1154:     //
                   1155:     if( GetDriveType(lpszDriveName) == DRIVE_REMOVABLE ){
                   1156:         dwLoop = (DWORD)IDOK;
                   1157: 
                   1158:         while( !CheckRM(lpszDriveName) && (dwLoop == (DWORD)IDOK) ){
                   1159: 
                   1160:            dwLoop = (DWORD)MessageBox(ghwndMain,
                   1161:                            "Filer: Insert some media in drive",
                   1162:                            lpszDriveName, MB_OKCANCEL);
                   1163:         }
                   1164: 
                   1165:         if( dwLoop == (DWORD)IDCANCEL ){
                   1166:             SendMessage(ghwndDrives, WM_COMMAND, MM_ACTIVEDRV,
                   1167:                         (LPARAM)lpCInfo->lpDriveInfo);
                   1168:             return(0);
                   1169:         }
                   1170:     }
                   1171: 
                   1172:     //
                   1173:     // Kill any current dir refresh thread.
                   1174:     //
                   1175:     if( WaitForSingleObject(lpCInfo->hDirThread, 0) == WAIT_TIMEOUT )
                   1176:         lpCInfo->fAlive = FALSE;
                   1177: 
                   1178:     //
                   1179:     // set lpDriveInfo member to associated drive struct.
                   1180:     //
                   1181:     lpWalk = glpDrives;
                   1182:     for( dwLoop = 0; dwLoop < DriveIndex - MM_DRIVE_NUM;
                   1183:          dwLoop++)
                   1184:          lpWalk = lpWalk->next;
                   1185: 
                   1186:     lpCInfo->lpDriveInfo = lpWalk;
                   1187: 
                   1188:     strcpy(lpCInfo->CaptionBarText, lpWalk->DriveName);
                   1189: 
                   1190:     LeaveCriticalSection(&gDrvCS);
                   1191: 
                   1192:     SendMessage(ghActiveChild, WM_COMMAND, MM_REFRESH, (LPARAM)NULL);
                   1193: 
                   1194:     return(1);
                   1195: }
                   1196: 
                   1197: 
                   1198: /***************************************************************************\
                   1199: *
                   1200: * FunctionBarProc
                   1201: *
                   1202: * ToolBar Window procedure for displaying File I/O functions.
                   1203: *   ghwndFunction is the global handle assoc. w/ this Dlg procedure.
                   1204: *
                   1205: * History:
                   1206: * 6/8/92
                   1207: *   Created.
                   1208: *
                   1209: \***************************************************************************/
                   1210: 
1.1.1.2 ! root     1211: LRESULT WINAPI FunctionBarProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1.1       root     1212: {
                   1213:     static HBRUSH   hBrush;
                   1214: 
                   1215:     switch (message){
                   1216:       case WM_INITDIALOG:{
                   1217:         HWND    hButton;
                   1218:         RECT     rc;
                   1219: 
                   1220:         hButton = GetDlgItem(hDlg, MM_COPY);
                   1221: 
                   1222:         GetWindowRect(hButton, &rc);
                   1223: 
                   1224:         SetWindowLong(hDlg, GWL_USERDATA, rc.bottom - rc.top);
                   1225: 
                   1226:         //
                   1227:         // Sets background color of Toolbar non-modal dialog children.
                   1228:         //
                   1229:         hBrush = CreateSolidBrush(GetSysColor(COLOR_BTNSHADOW));
                   1230: 
                   1231:         return(FALSE);
                   1232:       }
                   1233: 
                   1234:       case WM_PAINT:{
                   1235:         RECT     rc;
                   1236:         PAINTSTRUCT ps;
                   1237: 
                   1238:         //
                   1239:         // Paint btnshadow background.
                   1240:         //
                   1241:         GetClientRect(hDlg, &rc);
                   1242:         InvalidateRect(hDlg, &rc, FALSE);
                   1243: 
                   1244:         BeginPaint(hDlg, &ps);
                   1245: 
                   1246:         FillRect(ps.hdc, &rc, hBrush);
                   1247: 
                   1248:         EndPaint(hDlg, &ps);
                   1249: 
                   1250:         return(TRUE);
                   1251:       }
                   1252: 
                   1253:       //
                   1254:       // Passes button messages ( = file I/O function messages )
                   1255:       //   to active Drv child.
                   1256:       //
                   1257:       case WM_COMMAND:{
                   1258:         switch(wParam){
                   1259:           case MM_COPY:
                   1260:           case MM_MOVE:
                   1261:           case MM_DELETE:
                   1262:           case MM_RENAME:
                   1263:           case MM_MKDIR:{
                   1264:             SendMessage(ghActiveChild, message, wParam, lParam);
                   1265:             return(TRUE);
                   1266:           }
                   1267:         }
                   1268:       }
                   1269: 
                   1270:       case WM_DESTROY:{
                   1271:           DeleteObject(hBrush);
                   1272:           break;
                   1273:       }
                   1274:     }
                   1275: 
                   1276:     return(FALSE);
                   1277: }
                   1278: 
                   1279: 
                   1280: /***************************************************************************\
                   1281: *
                   1282: * UpdateDrivesMenu()
                   1283: *
                   1284: * Adds current drives from the glpDrives linked list to the 'Drives' menu
                   1285: *
                   1286: * Input: hDrivesMenu - handle to 'Drives' Menu
                   1287: *        hThread    - used to wait for drives thread to terminate
                   1288: *
                   1289: * History:
                   1290: * 5/14/92
                   1291: *   Created.
                   1292: *
                   1293: \***************************************************************************/
                   1294: 
                   1295: BOOL UpdateDrivesMenu(HMENU hMenu, HANDLE hThread)
                   1296: {
                   1297:     HMENU   hDrivesMenu;
                   1298:     int     NumMenuItems;
                   1299:     DWORD   dwLoop;
                   1300:     LPDINFO lpWalk;
                   1301: 
                   1302:     //
                   1303:     // Remove list of drive menu items from Drive menu, if any.
                   1304:     //
                   1305:     hDrivesMenu = GetSubMenu( hMenu, DRIVE_MENU_NUM);
                   1306:     if( !hDrivesMenu ){
                   1307:         ErrorMsg("UpdateDrivesMenu: GetSubMenu error.");
                   1308:         return(FALSE);
                   1309:     }
                   1310: 
                   1311:     if( (NumMenuItems = GetMenuItemCount(hDrivesMenu)) == -1)
                   1312:         ErrorMsg("Main Refresh: Menu Item Count Error.");
                   1313: 
                   1314:     //
                   1315:     // Delete previous menu items.
                   1316:     //
                   1317:     for( dwLoop = 0; dwLoop < (DWORD)NumMenuItems; dwLoop++)
                   1318:         if( !DeleteMenu( hDrivesMenu, 0,
                   1319:                          MF_BYPOSITION) ){
                   1320:             ErrorMsg("Main Refresh: Menu Item Delete Error.");
                   1321:             return(FALSE);
                   1322:         }
                   1323: 
                   1324:     //
                   1325:     // Wait for Enumdrv Thread to terminate, and
                   1326:     //   enter drive list critical section
                   1327:     //
                   1328:     WaitForSingleObject(hThread, (DWORD)0xFFFFFFFF);
                   1329:     EnterCriticalSection(&gDrvCS);
                   1330: 
                   1331:     //
                   1332:     // Fill drive menu from glpDrives linked list
                   1333:     //
                   1334:     NumMenuItems = 0;
                   1335:     lpWalk = glpDrives;
                   1336: 
                   1337:     while(lpWalk != NULL){
                   1338:         if( !InsertMenu( hDrivesMenu, NumMenuItems, MF_STRING |
                   1339:             MF_BYPOSITION | MF_ENABLED, MM_DRIVE_NUM + NumMenuItems,
                   1340:             lpWalk->DriveName) )
                   1341:             ErrorMsg("Main Refresh: Menu Item Insert Error.");
                   1342: 
                   1343:         NumMenuItems++;
                   1344:         lpWalk = lpWalk->next;
                   1345:     }
                   1346: 
                   1347:     LeaveCriticalSection(&gDrvCS);
                   1348: 
                   1349:     return(TRUE);
                   1350: }
                   1351: 
                   1352: 
                   1353: /***************************************************************************\
                   1354: *
                   1355: * ErrorMsg()
                   1356: *
                   1357: *   Displays a Message Box with a given error message.
                   1358: *
                   1359: * History:
                   1360: * 5/28/92
                   1361: *   Created.
                   1362: *
                   1363: \***************************************************************************/
                   1364: void ErrorMsg(LPSTR szMsg)
                   1365: {
                   1366:     MessageBox(ghwndMain, szMsg, "FILER Error.", MB_OK);
                   1367: }

unix.superglobalmegacorp.com

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