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