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