--- mstools/samples/filer/drvproc.c 2018/08/09 18:22:15 1.1.1.2 +++ mstools/samples/filer/drvproc.c 2018/08/09 18:24:30 1.1.1.3 @@ -1,9 +1,15 @@ + +/******************************************************************************\ +* This is a part of the Microsoft Source Code Samples. +* Copyright (C) 1993 Microsoft Corporation. +* All rights reserved. +* This source code is only intended as a supplement to +* Microsoft Development Tools and/or WinHelp documentation. +* See these sources for detailed information regarding the +* Microsoft samples programs. +\******************************************************************************/ + /******************************Module*Header*******************************\ -* -* Microsoft Developer Support -* Copyright (c) 1992 Microsoft Corporation -* -* * Module Name: drvproc.c * * Filer : SDK sample @@ -14,17 +20,6 @@ * In this sample, the Drive children handle the directory * and file enumeration, as well as the file I/O operations. * -* Created: 5/05/92 -* Author: Colin Stuart[] -* -* Copyright (c) 1990 Microsoft Corporation -* -* Dependencies: -* -* (#defines) -* (#includes) -* Drvproc.h -* \**************************************************************************/ #define STRICT @@ -32,30 +27,34 @@ #include #include "globals.h" #include "filer.h" -#include "walk.h" +#include "expdir.h" #include "drvproc.h" extern HANDLE ghModule; extern HANDLE ghHeap; -extern HANDLE ghDrvThread; extern HFONT ghFont; +extern HANDLE ghDrvThread; +extern HANDLE ghMenu; extern HWND ghwndCommand; extern HWND ghwndDrives; extern HWND ghActiveChild; extern HWND ghwndDrv1; extern HWND ghwndDrv2; -extern HWND ghFocusLB; +extern HWND ghFocusWnd; extern LPDINFO glpDrives; extern CRITICAL_SECTION gHeapCS; // Global heap critical section var. extern CRITICAL_SECTION gDrvCS; // Drive list critical section var. -extern char gszEditor[DIRECTORY_STRING_SIZE]; -extern char gszCommandLine[DIRECTORY_STRING_SIZE * 2]; +extern TCHAR gszEditor[DIRECTORY_STRING_SIZE]; +extern TCHAR gszCommandLine[DIRECTORY_STRING_SIZE * 2]; + +extern TCHAR gszExtensions[NUM_EXTENSION_STRINGS][EXTENSION_LENGTH]; + +extern VKINFO gVKArray[NUM_VERSION_INFO_KEYS]; // .EXE version info array. -extern char gszExtensions[NUM_EXTENSION_STRINGS][EXTENSION_LENGTH]; /***************************************************************************\ * DrvWndProc() @@ -66,77 +65,83 @@ extern char gszExtensions[NUM_EXTENS LRESULT WINAPI DrvWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { - - static DWORD dwDirStyle = WS_BORDER | WS_CHILD | WS_VISIBLE | + DWORD dwDirStyle = WS_BORDER | WS_CHILD | WS_VISIBLE | LBS_NOINTEGRALHEIGHT | LBS_NOTIFY | LBS_HASSTRINGS | LBS_WANTKEYBOARDINPUT | LBS_DISABLENOSCROLL | WS_HSCROLL | WS_VSCROLL |LBS_USETABSTOPS; - static DWORD dwFileStyle = WS_BORDER | WS_CHILD | WS_VISIBLE | + DWORD dwFileStyle = WS_BORDER | WS_CHILD | WS_VISIBLE | LBS_NOINTEGRALHEIGHT | LBS_NOTIFY | LBS_HASSTRINGS | LBS_WANTKEYBOARDINPUT | LBS_DISABLENOSCROLL | WS_HSCROLL | LBS_EXTENDEDSEL | LBS_MULTIPLESEL | LBS_MULTICOLUMN | LBS_SORT; - switch (message) { + switch (message){ // // Creates the text and listbox windows for this Drv child and // saves its handle in the per Drv child DRVCHILDINFO data structure. // - case WM_CREATE: { + case WM_CREATE: { LPCINFO lpCInfo; - HWND hTextWnd, - hwndLL, - hwndLR; DWORD dwLoop; + LPDINFO lpWalk; LONG lTabs = LISTBOX_TAB_SIZE; + + // + // Initialize DRVCHILDINFO structure + // + lpCInfo = (LPCINFO) ((LPCREATESTRUCT) lParam)->lpCreateParams; + + lpCInfo->hwnd = hwnd; + // Create text window - hTextWnd = CreateWindow("TextClass", NULL, + lpCInfo->hTextWnd = CreateWindow(TEXT("TextClass"), NULL, SS_LEFT | WS_CHILD | WS_VISIBLE | WS_BORDER, 0, 0, 0, 0, - hwnd, + lpCInfo->hwnd, (HMENU) TEXT_WINDOW_ID, ghModule, NULL); - // Create List boxes - hwndLL = CreateWindow("LISTBOX", NULL, + // Create Directory and File List boxes + lpCInfo->hDirLB = CreateWindow(TEXT("LISTBOX"), NULL, dwDirStyle, 0, 0, 0, 0, - hwnd, - (HMENU) LISTL_ID, + lpCInfo->hwnd, + (HMENU) LISTDIR_ID, ghModule, NULL); - hwndLR = CreateWindow("LISTBOX", NULL, + lpCInfo->hFileLB = CreateWindow(TEXT("LISTBOX"), NULL, dwFileStyle, 0, 0, 0, 0, - hwnd, - (HMENU) LISTR_ID, + lpCInfo->hwnd, + (HMENU) LISTFILE_ID, ghModule, NULL); // - // Initialize DRVCHILDINFO structure + // fDirLeft indicates whether the Directory ListBox defaults to + // the left side of each of the two drive windows. + // fDirExpand indicates whether the Directory Listbox defaults + // to full expansion. // - lpCInfo = (LPCINFO) ((LPCREATESTRUCT) lParam)->lpCreateParams; - - lpCInfo->hTextWnd = hTextWnd; - lpCInfo->hwndLL = hwndLL; - lpCInfo->hwndLR = hwndLR; + lpCInfo->fDirLeft = TRUE; + lpCInfo->fDirExpand = FALSE; + lpCInfo->fSuicide = FALSE; // - // Create Critical Section associated with each list box + // Create Mutex associated with each list box // - InitializeCriticalSection(&(lpCInfo->CritSecL)); - InitializeCriticalSection(&(lpCInfo->CritSecR)); + lpCInfo->hDirMutex = CreateMutex(NULL, FALSE, NULL); + lpCInfo->hFileMutex = CreateMutex(NULL, FALSE, NULL); // // Associate window with the current directory LPDINFO structure @@ -146,7 +151,7 @@ LRESULT WINAPI DrvWndProc(HWND hwnd, UI lpCInfo->CaptionBarText ); CharUpper(lpCInfo->CaptionBarText); - WaitForSingleObject(ghDrvThread, 0xFFFFFFFF); + WaitForSingleObject(ghDrvThread, INFINITE); EnterCriticalSection(&gDrvCS); lpWalk = glpDrives; @@ -156,13 +161,13 @@ LRESULT WINAPI DrvWndProc(HWND hwnd, UI (lpCInfo->CaptionBarText)[0] ) lpWalk = lpWalk->next; if( !lpWalk ){ - ErrorMsg("Drive Child Create: Drive list error."); + ErrorMsg(TEXT("Drive Child Create: Drive list failure.")); LeaveCriticalSection(&gDrvCS); return(-1); } } else{ - ErrorMsg("Drive Child Create: GetCurrentDir error."); + ErrorMsg(TEXT("Drive Child Create: GetCurrentDir failure.")); LeaveCriticalSection(&gDrvCS); return(-1); } @@ -179,23 +184,23 @@ LRESULT WINAPI DrvWndProc(HWND hwnd, UI // // Initialize child windows // - if( !SendMessage(hwndLL, LB_SETTABSTOPS, (WPARAM)1, + if( !SendMessage(lpCInfo->hDirLB, LB_SETTABSTOPS, (WPARAM)1, (LPARAM)&lTabs) ) - ErrorMsg("Drv window Create: Error setting tab stops"); + ErrorMsg(TEXT("Drv window Create: Set tab stop failure.")); // // Set default font. // - SendMessage(hwndLL, WM_SETFONT, (WPARAM)ghFont, (LPARAM)FALSE); - SendMessage(hwndLR, WM_SETFONT, (WPARAM)ghFont, (LPARAM)FALSE); + SendMessage(lpCInfo->hDirLB, WM_SETFONT, (WPARAM)ghFont, (LPARAM)FALSE); + SendMessage(lpCInfo->hFileLB, WM_SETFONT, (WPARAM)ghFont, (LPARAM)FALSE); SendMessage(hwnd, WM_COMMAND, (WPARAM)MM_REFRESH, (LPARAM)NULL); return(1); - } + } - case WM_COMMAND: { + case WM_COMMAND: { static LPCINFO lpCInfo; static SELECTINFO Select; @@ -205,24 +210,23 @@ LRESULT WINAPI DrvWndProc(HWND hwnd, UI // lpCInfo = (LPCINFO) GetWindowLong(hwnd, GWL_USERDATA); - switch (LOWORD(wParam)) { + switch (LOWORD(wParam)){ case MM_TAB:{ HWND hFocus; hFocus = GetFocus(); - if( hFocus == lpCInfo->hwndLL ) - SetFocus(lpCInfo->hwndLR); + if( hFocus == lpCInfo->hDirLB ) + ghFocusWnd = lpCInfo->hFileLB; else - if( hFocus == lpCInfo->hwndLR ) - SetFocus(ghwndCommand); + if( hFocus == lpCInfo->hFileLB ) + ghFocusWnd = ghwndCommand; else if( hFocus == ghwndCommand) - SetFocus(lpCInfo->hwndLL); - else - SetFocus(lpCInfo->hwndLL); + ghFocusWnd = lpCInfo->hDirLB; + SetFocus( ghFocusWnd ); return(1); } @@ -232,102 +236,205 @@ LRESULT WINAPI DrvWndProc(HWND hwnd, UI // case MM_ESCAPE:{ // - // the type of the active window can be determined by querying - // on unique window style attributes. Only the file listbox - // has LBS_SORT, only the dir listbox has LBS_USETABSTOPS. + // If there is a directory expand in process, kill the + // thread, and leave the listbox in a semi-expanded state. + // Else, clear file selection, and switch to command window. // - if( IsFileLB(ghFocusLB) ) - SendMessage(ghFocusLB, LB_SETSEL, (WPARAM)0, (LPARAM)-1); + if( WaitForSingleObject( lpCInfo->hDirMutex, MUTEX_TIMEOUT) + == WAIT_TIMEOUT ){ + lpCInfo->fSuicide = TRUE; + lpCInfo->fEscape = TRUE; + } else - SendMessage(ghFocusLB, LB_SETCURSEL, (WPARAM)-1, (LPARAM)NULL); + ReleaseMutex( lpCInfo->hDirMutex ); + SendMessage(lpCInfo->hFileLB, LB_SETCURSEL, (WPARAM)-1, + (LPARAM)0); + + SetFocus( ghwndCommand ); + ghFocusWnd = ghwndCommand; + SendMessage(ghwndCommand, LB_SETCURSEL, (WPARAM)0, + (LPARAM)-1); return(1); } case MM_OPEN:{ - OpenListBoxItem(lpCInfo, ghFocusLB); + if( ghFocusWnd == lpCInfo->hFileLB ) + OpenListBoxItem(lpCInfo); + else + if( ghFocusWnd == lpCInfo->hDirLB ){ + if( !PostMessage(hwnd, WM_COMMAND, MM_FILLDIR, + (LPARAM)0) ){ + ErrorMsg(TEXT("MM_OPEN: Filldir failure.")); + return(0); + } + } + else + RunCommandItem(lpCInfo); return(1); } - case MM_COPY:{ + case MM_COPY:{ Select.hwnd = hwnd; Select.dwAction = MM_COPY; - Select.szAction = "COPYING:"; - Select.szToFrom = "TO:"; + Select.szAction = TEXT("COPYING:"); + Select.szToFrom = TEXT("TO:"); ExecuteFileAction(&Select); return(1); } - case MM_DELETE:{ + case MM_DELETE:{ Select.hwnd = hwnd; Select.dwAction = MM_DELETE; - Select.szAction = "DELETING:"; - Select.szToFrom = "FROM:"; + Select.szAction = TEXT("DELETING:"); + Select.szToFrom = TEXT("FROM:"); ExecuteFileAction(&Select); return(1); } - case MM_MOVE:{ + case MM_MOVE:{ Select.hwnd = hwnd; Select.dwAction = MM_MOVE; - Select.szAction = "MOVING:"; - Select.szToFrom = "TO:"; + Select.szAction = TEXT("MOVING:"); + Select.szToFrom = TEXT("TO:"); ExecuteFileAction(&Select); return(1); } - case MM_RENAME:{ + case MM_RENAME:{ - if( DialogBoxParam(ghModule, "RenameDlg", hwnd, + if( DialogBoxParam(ghModule, TEXT("RenameDlg"), hwnd, (DLGPROC)RenameProc, (LPARAM)lpCInfo) == -1 ){ - ErrorMsg("DriveProc: Rename Dialog Creation Error!"); + ErrorMsg(TEXT("DriveProc: Rename Dialog Creation failure.")); return(0); } return(1); } - case MM_MKDIR:{ + case MM_MKDIR:{ - if( DialogBoxParam(ghModule, "MkDirDlg", hwnd, + if( DialogBoxParam(ghModule, TEXT("MkDirDlg"), hwnd, (DLGPROC)MkDirProc, (LPARAM)lpCInfo) == -1 ){ - ErrorMsg("DriveProc: MkDir Dialog Creation Error!"); + ErrorMsg(TEXT("DriveProc: MkDir Dialog Creation failure.")); + return(0); + } + + return(1); + } + + case MM_VERSION:{ + + if( DialogBoxParam(ghModule, TEXT("VersionInfoDlg"), hwnd, + (DLGPROC)VersionProc, (LPARAM)lpCInfo) == -1 ){ + ErrorMsg(TEXT("DriveProc: Version Info Dialog Creation failure.")); return(0); } return(1); } + case MM_EXPAND:{ + + lpCInfo->fDirExpand = !lpCInfo->fDirExpand; + + if( lpCInfo->fDirExpand ) + CheckMenuItem( ghMenu, MM_EXPAND, + MF_BYCOMMAND | MF_CHECKED); + else + CheckMenuItem( ghMenu, MM_EXPAND, + MF_BYCOMMAND | MF_UNCHECKED); + + if( !SendMessage( (HWND)lpCInfo->hwnd, WM_COMMAND, + (WPARAM)MM_REFRESH, (LPARAM)0 ) ){ + ErrorMsg(TEXT("MM_EXPAND: MM_REFRESH failure.")); + return(0); + } + return(1); + } + // // refreshes contents of directory and file ListBoxes. // case MM_REFRESH:{ - if( IsFileLB(lpCInfo->hwndLL) ){ - if( !PostMessage(hwnd, WM_COMMAND, MM_FILLFILE, - (LPARAM)lpCInfo->hwndLL) ) - ErrorMsg("Refresh Drv window: Left Fillfile failed"); - if( !PostMessage(hwnd, WM_COMMAND, MM_FILLDIR, - (LPARAM)lpCInfo->hwndLR) ) - ErrorMsg("Refresh Drv window: Right Filldir failed"); + DWORD dwThreadID; + + if( WaitForSingleObject( lpCInfo->hDirMutex, MUTEX_TIMEOUT) + == WAIT_TIMEOUT ) + // + // If the full directory expand has been cancled, kill the + // existing thread. + // + if( !lpCInfo->fDirExpand && !lpCInfo->fSuicide){ + lpCInfo->fSuicide = TRUE; + return(1); + } + else{ + return(0); + } + + // if set, clear the expand dir. user abort (escape key) flag. + if( lpCInfo->fEscape ){ + lpCInfo->fEscape = FALSE; + ReleaseMutex( lpCInfo->hDirMutex ); + return(1); } - else{ - if( !PostMessage(hwnd, WM_COMMAND, MM_FILLDIR, - (LPARAM)lpCInfo->hwndLL) ) - ErrorMsg("Refresh Drv window: Left Filldir failed"); - if( !PostMessage(hwnd, WM_COMMAND, MM_FILLFILE, - (LPARAM)lpCInfo->hwndLR) ) - ErrorMsg("Refresh Drv window: Right Fillfile failed"); + + // At this point, the Dir LB mutex has been grabbed. + + // Clear directory LB. If expand flag is set, expand all + // directories. Refill File LB. + // + if( SendMessage( lpCInfo->hDirLB, LB_RESETCONTENT, + (WPARAM)0, (LPARAM)0 ) < 0 ){ + ErrorMsg(TEXT("Refresh Drv window: Reset Dir LB content failure.")); + ReleaseMutex( lpCInfo->hDirMutex ); + return(0); + } + + // + // This call puts the default root entry back into the empty + // LB. Set suicide flag to false to ensure it will complete. + // + lpCInfo->fSuicide = FALSE; + ExpDir( lpCInfo ); + + // + // All the Dir LB work is done. Release Dir LB Mutex. + // + ReleaseMutex( lpCInfo->hDirMutex ); + + if( lpCInfo->fDirExpand ){ + + CloseHandle( lpCInfo->hDirThread ); + + lpCInfo->hDirThread = CreateThread( NULL, 0, + (LPTHREAD_START_ROUTINE)FullExpand, + (LPVOID)lpCInfo, 0, &dwThreadID); + + if( !lpCInfo->hDirThread ){ + ErrorMsg(TEXT("MM_REFRESH: FullExpand CreateThread failure.")); + return(0); + } + } + else + ExpDir( lpCInfo ); + + if( !PostMessage(hwnd, WM_COMMAND, MM_FILLFILE, + (LPARAM)0) ){ + ErrorMsg(TEXT("Refresh Drv window: Fillfile failure.")); + return(0); } return(1); @@ -337,25 +444,22 @@ LRESULT WINAPI DrvWndProc(HWND hwnd, UI // Fill listbox in lParam with directory from Drv child's drive. // Sent by MM_REFRESH. // + // lParam == 0 + // case MM_FILLDIR:{ DWORD dwThreadID; - // - // If there is currently a directory enumeration thread - // running for this Drv Child, and no requests to kill it, - // leave. - // - if( WaitForSingleObject( lpCInfo->hDirThread, 0) == WAIT_TIMEOUT - && lpCInfo->fAlive ) - return(0); + lpCInfo->fSuicide = FALSE; + + CloseHandle( lpCInfo->hDirThread ); lpCInfo->hDirThread = CreateThread( NULL, 0, - (LPTHREAD_START_ROUTINE)FillDirectoryLB, - (LPVOID)lParam, 0, &dwThreadID); + (LPTHREAD_START_ROUTINE)ExpDir, + (LPVOID)lpCInfo, 0, &dwThreadID); if( !(lpCInfo->hDirThread) ){ - ErrorMsg("FILLDIR: CreateThread failed"); + ErrorMsg(TEXT("MM_FILLDIR: ExpDir CreateThread failure.")); return(0); } @@ -367,91 +471,171 @@ LRESULT WINAPI DrvWndProc(HWND hwnd, UI // Sent by MM_REFRESH & LBN_DBLCLK in DrvWndProc, as well as // DoFileIO. and HandleIOError(). // + // lParam == 0 + // case MM_FILLFILE:{ - char szFiles[DIRECTORY_STRING_SIZE + 20]; - char* lpHold; - LPCRITICAL_SECTION lpCS; + TCHAR szFiles[DIRECTORY_STRING_SIZE + 20]; + LPTSTR lpHold; - if( (HWND)lParam == lpCInfo->hwndLL) - lpCS = &(lpCInfo->CritSecL); - else - if( (HWND)lParam == lpCInfo->hwndLR) - lpCS = &(lpCInfo->CritSecR); - else{ - ErrorMsg("MM_FILLFILE: Invalid ListBox handle."); - return(0); - } + if( WaitForSingleObject( lpCInfo->hFileMutex, MUTEX_TIMEOUT) + == WAIT_TIMEOUT ){ + ErrorMsg(TEXT("MM_FILLFILE: File LB Mutex Timeout.")); + return(0); + } - EnterCriticalSection(lpCS); // // Not checking for errors here, as LB_RESETCONTENT always // returns true, and LB_DIR returns an error if the directory // is empty. // - SendMessage((HWND)lParam, LB_RESETCONTENT, (WPARAM)NULL, (LPARAM)NULL); + SendMessage(lpCInfo->hFileLB, LB_RESETCONTENT, (WPARAM)NULL, (LPARAM)NULL); lstrcpy( szFiles, lpCInfo->CaptionBarText ); - lpHold = strchr(szFiles, '\0'); + lpHold = TStrChr(szFiles, TEXT('\0')); lpHold--; - if( *lpHold != '\\') - lstrcat( szFiles, "\\"); - lstrcat( szFiles, "*.*"); + if( *lpHold != TEXT('\\') ){ + lpHold++; + *lpHold = TEXT('\\'); + } - if( SendMessage( (HWND)lParam, LB_DIR, (WPARAM)0x10, + lpHold++; + lstrcpy( lpHold, TEXT("*.*")); + + if( SendMessage( lpCInfo->hFileLB, LB_DIR, (WPARAM)0x10, (LPARAM)szFiles ) == LB_ERR ){ - ErrorMsg("MM_FILLFILE: Fill ListBox error."); + ErrorMsg(TEXT("MM_FILLFILE: Fill ListBox failure.")); + ReleaseMutex( lpCInfo->hFileMutex ); + return(0); + } + + // + // Set selection to first file. + // + if( SendMessage( lpCInfo->hFileLB, LB_SETSEL, (WPARAM)TRUE, + (LPARAM)0 ) == LB_ERR ){ + ErrorMsg(TEXT("MM_FILLFILE: Listbox selection failure.")); + ReleaseMutex( lpCInfo->hFileMutex ); return(0); } SetWindowText(lpCInfo->hTextWnd, lpCInfo->CaptionBarText); - LeaveCriticalSection(lpCS); + ReleaseMutex( lpCInfo->hFileMutex ); return(1); } + // + // Toggle active status of drive child. + // case MM_TOGGLE:{ - SendMessage(lpCInfo->hTextWnd, WM_SETTEXT, (WPARAM)NULL, - (LPARAM)lpCInfo->CaptionBarText); - + SetWindowText(lpCInfo->hTextWnd, lpCInfo->CaptionBarText); return(1); } // // The following WM_COMMAND messages are sent by the listboxes // - case LISTL_ID: - case LISTR_ID:{ + // HIWORD(wParam) = LB notification message + // lParam = LB window handle + // + case LISTFILE_ID:{ switch( HIWORD(wParam) ){ // // In case of double click on a directory, expand the file - // Listbox. if on a file, run or edit file. + // Listbox. if on a file name, run or edit file. // case LBN_DBLCLK:{ - OpenListBoxItem(lpCInfo, (HWND) lParam); + OpenListBoxItem(lpCInfo); return(1); } break; case LBN_SETFOCUS:{ - ghFocusLB = (HWND)lParam; + ghFocusWnd = lpCInfo->hFileLB; } break; default: return(1); } - } + } // LISTFILE_ID break; - default: - return(1); + // + // Notification from the Directory ListBox + // + case LISTDIR_ID:{ + switch( HIWORD(wParam) ){ + + case LBN_SETFOCUS:{ + ghFocusWnd = lpCInfo->hDirLB; + } + break; - } + // + // Expand subdirectories in dir listbox + // + case LBN_DBLCLK:{ - } + if( !PostMessage(hwnd, WM_COMMAND, MM_FILLDIR, + (LPARAM)0) ){ + ErrorMsg(TEXT("Dir ListBox Notify: Filldir failure.")); + return(0); + } + return(1); + } + break; + + case LBN_SELCHANGE:{ + // + // for the Directory LB, fill the + // corresp. File LB with items in the newly selected dir. + // + LONG lIndex; + + + if( WaitForSingleObject( lpCInfo->hDirMutex, MUTEX_TIMEOUT) + == WAIT_TIMEOUT ){ + ErrorMsg(TEXT("Dir LB Notify: Dir LB Mutex Timeout.")); + return(0); + } + + // + // Retrieve selected (careted) item. + // + lIndex = SendMessage( (HWND)lParam, LB_GETCARETINDEX, + (WPARAM)NULL, (LPARAM)NULL ); + + if( !ConstructDirName(lpCInfo, lIndex, + lpCInfo->CaptionBarText) ){ + ErrorMsg(TEXT("Dir LB Notify: ConstructDirName failure.")); + ReleaseMutex( lpCInfo->hDirMutex ); + return(0); + } + + ReleaseMutex( lpCInfo->hDirMutex ); + + if( !PostMessage(hwnd, WM_COMMAND, MM_FILLFILE, + (LPARAM)0) ){ + ErrorMsg(TEXT("Dir ListBox Notify: Fillfile failure.")); + return(0); + } + } // LBN_SELCHANGE + break; + + default: + return(1); + } + } // LISTDIR_ID + break; + + default: + return(1); + } + } break; // @@ -460,11 +644,14 @@ LRESULT WINAPI DrvWndProc(HWND hwnd, UI // contain the height of the windows queried, set in their respective // WM_CREATE cases. // - case WM_SIZE: { + case WM_SIZE: { LPCINFO lpCInfo; - int nListHeight; - int nListWidth; + int nListHeight, + nListWidth; + + HWND hLeftLB, + hRightLB; // // First, get the text window's handle from the per Drv child @@ -483,30 +670,39 @@ LRESULT WINAPI DrvWndProc(HWND hwnd, UI // Increasing sides and bottom extents by 1 to overlap border // with Drv child border // - MoveWindow(lpCInfo->hTextWnd, - -1, + MoveWindow(lpCInfo->hTextWnd, + -1, 0, - LOWORD(lParam) + 2, - GetWindowLong(lpCInfo->hTextWnd, GWL_USERDATA) + 1, + LOWORD(lParam) + 2, + GetWindowLong(lpCInfo->hTextWnd, GWL_USERDATA) + 1, TRUE); - MoveWindow(lpCInfo->hwndLL, + if( lpCInfo->fDirLeft ){ + hLeftLB = lpCInfo->hDirLB; + hRightLB = lpCInfo->hFileLB; + } + else{ + hLeftLB = lpCInfo->hFileLB; + hRightLB = lpCInfo->hDirLB; + } + + MoveWindow(hLeftLB, LIST_BORDER, - GetWindowLong(lpCInfo->hTextWnd, GWL_USERDATA) + 1 + GetWindowLong(lpCInfo->hTextWnd, GWL_USERDATA) + 1 + LIST_BORDER, nListWidth, nListHeight, TRUE); - MoveWindow(lpCInfo->hwndLR, + MoveWindow(hRightLB, (LOWORD(lParam) + LIST_BORDER) / 2, - GetWindowLong(lpCInfo->hTextWnd, GWL_USERDATA) + 1 + GetWindowLong(lpCInfo->hTextWnd, GWL_USERDATA) + 1 + LIST_BORDER, nListWidth, nListHeight, TRUE); - break; + break; } case WM_PARENTNOTIFY:{ @@ -515,14 +711,14 @@ LRESULT WINAPI DrvWndProc(HWND hwnd, UI if(wParam == WM_LBUTTONDOWN){ lpCInfo = (LPCINFO) GetWindowLong(hwnd, GWL_USERDATA); if(lpCInfo == NULL){ - ErrorMsg("Drv child: Parent notify error"); + ErrorMsg(TEXT("Drv child: Parent notify failure.")); return(1); } - if(HIWORD(wParam) == LISTL_ID) - SetFocus(lpCInfo->hwndLL); + if(HIWORD(wParam) == LISTDIR_ID) + SetFocus(lpCInfo->hDirLB); else - if(HIWORD(wParam) == LISTR_ID) - SetFocus(lpCInfo->hwndLR); + if(HIWORD(wParam) == LISTFILE_ID) + SetFocus(lpCInfo->hFileLB); else if(HIWORD(wParam) == TEXT_WINDOW_ID) SetFocus(lpCInfo->hTextWnd); @@ -556,23 +752,23 @@ LRESULT WINAPI DrvWndProc(HWND hwnd, UI // Free the DRVCHILDINFO data that associates with this window // also, reset the menu. // - case WM_CLOSE: { + case WM_CLOSE: { LPCINFO lpCInfo; - lpCInfo = (LPCINFO)GetWindowLong(hwnd, GWL_USERDATA); + lpCInfo = (LPCINFO)GetWindowLong(hwnd, GWL_USERDATA); - DeleteCriticalSection(&(lpCInfo->CritSecL)); - DeleteCriticalSection(&(lpCInfo->CritSecR)); + CloseHandle(lpCInfo->hDirMutex ); + CloseHandle(lpCInfo->hFileMutex ); EnterCriticalSection(&gHeapCS); - HeapFree(ghHeap, (LPSTR)lpCInfo); + HeapFree(ghHeap, 0, (LPVOID)lpCInfo); LeaveCriticalSection(&gHeapCS); break; - } + } - default: - return DefWindowProc(hwnd, message, wParam, lParam); + default: + return DefWindowProc(hwnd, message, wParam, lParam); } //switch return DefWindowProc(hwnd, message, wParam, lParam); @@ -581,54 +777,60 @@ LRESULT WINAPI DrvWndProc(HWND hwnd, UI /***************************************************************************\ * -* IsFileLB() +* GetLBText() +* +* Gets the text of the currently selected (careted) item in the given +* listbox. * -* Verifies that the window handle sent in is a File ListBox. Directory LBs -* are not created with the LBS_SORT class style, while file LBs are. A -* query for this value determines the type of LB. See dwDirStyle and -* dwFileStyle at the top of DrvWndProc. +* Returns: Index of selected item if successful, -1 on failure * * History: -* 6/8/92 +* 4/26/93 * Created. * \***************************************************************************/ -BOOL IsFileLB( HWND hwnd ) +LONG GetLBText(HWND hActiveLB, PTCHAR szItemBuff) { + LONG lIndex; - if( GetWindowLong(hwnd, GWL_STYLE) & LBS_SORT ) - return(TRUE); - else - return(FALSE); + // + // Retrieve selected (careted) item. + // + lIndex = SendMessage( hActiveLB, LB_GETCARETINDEX, + (WPARAM)NULL, (LPARAM)NULL ); + + if( SendMessage( hActiveLB, LB_GETTEXT, (WPARAM)lIndex, + (LPARAM)szItemBuff) == LB_ERR ){ + ErrorMsg(TEXT("LBN_DBLCLK: Text retrieval failure.")); + return(-1); + } + + return( lIndex ); } /***************************************************************************\ * -* FillDirectoryLB() +* UpdateFileLB() * -* Calls routines to walk the drive associated with the Drv Child hwnd, -* enumerating the directories. +* Updates the file listbox of the drive child given by sending an MM_FILLFILE +* message to it. +* +* input: hwnd - Handle of drive child to update file listbox of. * * History: -* 5/18/92 +* 6/3/92 * Created. * \***************************************************************************/ -void FillDirectoryLB( HWND hwnd ) +void UpdateFileLB(HWND hwnd) { LPCINFO lpCInfo; - lpCInfo = (LPCINFO) GetWindowLong(GetParent(hwnd), GWL_USERDATA); - if( !lpCInfo ) - ExitThread(0); - - if( !EnumDir(hwnd, lpCInfo) ){ - ErrorMsg("FILLDIR: Failed adding directories."); - ExitThread(0); - } + lpCInfo = (LPCINFO)GetWindowLong(hwnd, GWL_USERDATA); - ExitThread(1); + SendMessage(hwnd, WM_COMMAND, (WPARAM)MM_FILLFILE, + (LPARAM)0); } @@ -636,68 +838,45 @@ void FillDirectoryLB( HWND hwnd ) * * OpenListBoxItem() * -* Attempts to expand a selected list box directory entry into an available +* Attempts to expand a selected File list box directory entry into an available * file listbox, or spawn a selected list box file. * * input: lpCInfo - pointer to Drv child's LPCINFO structure -* hActiveLB - handle to active listbox * * History: * 5/27/92 * Created. * \***************************************************************************/ -BOOL OpenListBoxItem(LPCINFO lpCInfo, HWND hActiveLB) +BOOL OpenListBoxItem(LPCINFO lpCInfo) { - HWND hFileLB; - LONG lIndex; - char szItemBuff[DIRECTORY_STRING_SIZE]; + TCHAR szItemBuff[DIRECTORY_STRING_SIZE]; // // Retrieve selected (careted) item. // - lIndex = SendMessage( hActiveLB, LB_GETCARETINDEX, - (WPARAM)NULL, (LPARAM)NULL ); - - if( SendMessage( hActiveLB, LB_GETTEXT, (WPARAM)lIndex, - (LPARAM)szItemBuff) == LB_ERR ){ - ErrorMsg("LBN_DBLCLK: Cannot get string."); - return(0); - } + GetLBText(lpCInfo->hFileLB, szItemBuff); // - // Determine whether the item is a directory selected from a directory - // List Box, a directory selected from a file List Box, a file, or - // an invalid condition (ListBox not active). - // - if( hActiveLB == lpCInfo->hwndLL ) - if( IsFileLB(lpCInfo->hwndLL) ) - if( !IsDirectory(lpCInfo->CaptionBarText, szItemBuff) ){ - RunListBoxItem(lpCInfo, hActiveLB); - return(1); - } - else - hFileLB = hActiveLB; //it's a directory in the file list box - else - hFileLB = lpCInfo->hwndLR; - else - if( IsFileLB(lpCInfo->hwndLR) ) - if( !IsDirectory(lpCInfo->CaptionBarText, szItemBuff) ){ - RunListBoxItem(lpCInfo, hActiveLB); - return(1); - } - else - hFileLB = hActiveLB; //it's a directory in the file list box - else - hFileLB = lpCInfo->hwndLL; + // Determine whether the item is a directory or a file. + // If file, Run if possible. + // + if( !IsDirectory(lpCInfo->CaptionBarText, szItemBuff) ){ + RunListBoxItem(lpCInfo); + return(1); + } // - // Expand directory that was opened. + // It is a directory. Set the new caption text, and expand files. // lstrcpy( lpCInfo->CaptionBarText, szItemBuff); - SendMessage(GetParent(hActiveLB), WM_COMMAND, (WPARAM)MM_FILLFILE, - (LPARAM)hFileLB); + if( !PostMessage(lpCInfo->hwnd, WM_COMMAND, MM_FILLFILE, + (LPARAM)0) ){ + ErrorMsg(TEXT("OpenListBoxItem: Fillfile failure.")); + return(0); + } + return(1); } @@ -709,58 +888,59 @@ BOOL OpenListBoxItem(LPCINFO lpCInfo, HW * attempts to spawn an editor to edit the file. * * input: lpCInfo - pointer to Drv child's LPCINFO structure -* hActiveLB - handle to active listbox * * History: * 5/27/92 * Created. * +* 5/12/93 +* Modified. +* \***************************************************************************/ -BOOL RunListBoxItem(LPCINFO lpCInfo, HWND hActiveLB) +BOOL RunListBoxItem(LPCINFO lpCInfo) { LONG lIndex; - char szFileBuff[DIRECTORY_STRING_SIZE]; - char szCmdLine[DIRECTORY_STRING_SIZE * 2]; - LPSTR szHold; + TCHAR szFileBuff[DIRECTORY_STRING_SIZE]; + TCHAR szCmdLine[DIRECTORY_STRING_SIZE * 2]; + LPTSTR szHold; STARTUPINFO si; PROCESS_INFORMATION pi; lstrcpy(szCmdLine, lpCInfo->CaptionBarText); - lstrcat(szCmdLine, "\\"); + + lstrcat(szCmdLine, TEXT("\\")); // // Get file that was opened, and attempt to spawn. If fails, attempt to // edit it. // - lIndex = SendMessage( hActiveLB, LB_GETCARETINDEX, - (WPARAM)NULL, (LPARAM)NULL ); - if( SendMessage( hActiveLB, LB_GETTEXT, (WPARAM)lIndex, - (LPARAM)szFileBuff) == LB_ERR ){ - ErrorMsg("RunListBoxItem: Cannot get string."); + // + // Retrieve selected (careted) item. + // + lIndex = GetLBText(lpCInfo->hFileLB, szFileBuff); + if( !lIndex ) return(0); - } - // - // Don't assume the file has an extension. if no '.', insert one at end of - // file, so spawned editor will not assume any default extension. - // (i.e. Notepad assumes a .TXT if no extension is given.) + // Don't assume the file has an extension. if no '.', insert one at end + // of file, so spawned editor will not assume any default extension. + // (i.e. Notepad assumes a .TXT if no extension is given.) // - szHold = strchr(szFileBuff, '.'); + szHold = TStrChr(szFileBuff, TEXT('.')); if( !szHold ){ - szHold = strchr(szFileBuff, '\0'); - *szHold = '.'; - *(szHold + sizeof(char)) = '\0'; + szHold = TStrChr(szFileBuff, TEXT('\0')); + *szHold = TEXT('.'); + *(szHold + sizeof(TCHAR)) = TEXT('\0'); } si.cb = sizeof(STARTUPINFO); si.lpReserved = NULL; si.lpDesktop = NULL; si.lpTitle = NULL; - si.dwFlags = NULL; + si.dwFlags = 0; si.cbReserved2 = 0; si.lpReserved2 = NULL; @@ -783,24 +963,31 @@ BOOL RunListBoxItem(LPCINFO lpCInfo, HWN if( !CreateProcess(NULL, (LPCTSTR)szCmdLine, NULL, NULL, FALSE, CREATE_NEW_CONSOLE | NORMAL_PRIORITY_CLASS, NULL, lpCInfo->CaptionBarText, &si, &pi) ){ - ErrorMsg("Unable to spawn file."); + ErrorMsg(TEXT("RunListBoxItem: Unable to spawn file.")); return(0); } + + CloseHandle( pi.hProcess ); + CloseHandle( pi.hThread ); + return(1); } LoadString(ghModule, STR_DEF_EDITOR, szCmdLine, DIRECTORY_STRING_SIZE * 2); - lstrcat(szCmdLine, " "); + lstrcat(szCmdLine, TEXT(" ")); lstrcat(szCmdLine, szFileBuff); if( !CreateProcess(NULL, szCmdLine, NULL, NULL, FALSE, CREATE_NEW_CONSOLE | NORMAL_PRIORITY_CLASS, NULL, lpCInfo->CaptionBarText, &si, &pi) ){ - ErrorMsg("Unable to edit file."); + ErrorMsg(TEXT("RunListBoxItem: Unable to edit file.")); return(0); } + CloseHandle( pi.hProcess ); + CloseHandle( pi.hThread ); + SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_NORMAL); return(1); @@ -809,13 +996,331 @@ BOOL RunListBoxItem(LPCINFO lpCInfo, HWN /***************************************************************************\ * +* FilerGetVersion() +* +* Given an item from a File ListBox, GetVersion retrieves the version +* information from the specified file. +* +* input: lpszFileName - the name of the file. +* dwBuffSize - > 0 size of buffer to hold version info +* szBuff - buffer to hold version info +* +* returns: TRUE if successful, FALSE otherwise. +* +* comments: gVKArray would need a critical section if this function were +* to be called by more than one thread. +* +* History: +* 2/23/93 +* Created. +* +\***************************************************************************/ +BOOL FilerGetVersion(LPTSTR lpszFileName, DWORD dwBuffSize, LPTSTR szBuff) +{ + // + // NUM_VERSION_INFO_KEYS in GLOBALS.H should be set to the number of entries in + // VersionKeys[]. + // + CONST static TCHAR *VersionKeys[] = { + TEXT("ProductName"), + TEXT("ProductVersion"), + TEXT("OriginalFilename"), + TEXT("FileDescription"), + TEXT("FileVersion"), + TEXT("CompanyName"), + TEXT("LegalCopyright"), + TEXT("LegalTrademarks"), + TEXT("InternalName"), + TEXT("PrivateBuild"), + TEXT("SpecialBuild"), + TEXT("Comments") + }; + + static TCHAR szNull[1] = TEXT(""); + LPVOID lpInfo; + DWORD cch; + UINT i; + TCHAR key[80]; + + GetFileVersionInfo(lpszFileName, 0, dwBuffSize, (LPVOID)szBuff ); + + for (i = 0; i < NUM_VERSION_INFO_KEYS; i++) { + lstrcpy(key, VERSION_INFO_KEY_ROOT); + lstrcat(key, VERSION_INFO_LANG_ID); + lstrcat(key, "\\"); + lstrcat(key, VersionKeys[i]); + gVKArray[i].szKey = VersionKeys[i]; + + // + // If version info exists, and the key query is successful, add + // the value. Otherwise, the value for the key is NULL. + // + if( dwBuffSize && VerQueryValue(szBuff, key, &lpInfo, &cch) ) + gVKArray[i].szValue = lpInfo; + else + gVKArray[i].szValue = szNull; + } + + return TRUE; +} + + +/***************************************************************************\ +* VersionProc() +* +* .EXE Version Info Dialog Box +* +* History: +* 2/24/93 2am +* Created. +\***************************************************************************/ +LRESULT WINAPI VersionProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + static LPTSTR lpszBuff; + + switch (message){ + case WM_INITDIALOG:{ + + LPCINFO lpCInfo; + DWORD dwLength; + DWORD dwCount; + DWORD dwHandle; + TCHAR szFile[DIRECTORY_STRING_SIZE] = TEXT("File: "); + TCHAR szDir[DIRECTORY_STRING_SIZE] = TEXT("Directory: "); + TCHAR szFullName[DIRECTORY_STRING_SIZE]; + LPTSTR lpszHold; + + + lpCInfo = (LPCINFO)lParam; + + // + // Concatenate path to szDir text-control string. + // + lstrcat(szDir, lpCInfo->CaptionBarText); + SendDlgItemMessage( hDlg, SB_DEST, WM_SETTEXT, + (WPARAM)0, (LPARAM)szDir); + + // + // Concatenate File name to szFile text-control string. + // + dwLength = lstrlen(szFile); + + // + // Get selected (careted) ListBox item + // + GetLBText(lpCInfo->hFileLB, (PTCHAR)&szFile[dwLength]); + + SendDlgItemMessage( hDlg, SB_SOURCE, WM_SETTEXT, + (WPARAM)0, (LPARAM)szFile); + + // + // Fill Version Key and Value edit boxes. + // + lstrcpy( szFullName, lpCInfo->CaptionBarText ); + + // + // a file under some file systems may have [] characters. + // Prepend path, adding a delimiting backslash unless we're in the root. + // If the attribute check is successful, it's a file, so leave. + // + lpszHold = TStrChr(szFullName, TEXT('\0')); + + lpszHold--; + if( *lpszHold != TEXT('\\') ){ + lpszHold++; + *lpszHold = TEXT('\\'); + } + lpszHold++; + + lstrcpy(lpszHold, &szFile[dwLength]); // File name past 'File:' prefix + + dwLength = GetFileVersionInfoSize( szFullName, &dwHandle); + if( !dwLength ){ + ErrorMsg(TEXT("VersionProc: GetFileVersionInfoSize() failure.")); + return(1); + } + + // Allocate Version Info buffer + EnterCriticalSection(&gHeapCS); + lpszBuff = (LPTSTR)HeapAlloc( ghHeap, 0, dwLength * sizeof(TCHAR) ); + LeaveCriticalSection(&gHeapCS); + + FilerGetVersion( szFullName, dwLength, lpszBuff ); + + for( dwCount = 0; dwCount < NUM_VERSION_INFO_KEYS; dwCount++){ + if( SendDlgItemMessage( hDlg, SB_KEY, LB_ADDSTRING, 0, + (LPARAM)gVKArray[dwCount].szKey) + == LB_ERR ){ + ErrorMsg(TEXT("VersionProc: Add Key string failure.")); + return(0); + } + if( SendDlgItemMessage( hDlg, SB_VALUE, LB_ADDSTRING, 0, + (LPARAM)gVKArray[dwCount].szValue) + == LB_ERR ){ + ErrorMsg(TEXT("VersionProc: Add Value string failure.")); + return(0); + } + } + + // Set selection in listboxes to first item. + if( SendDlgItemMessage( hDlg, SB_KEY, LB_SETCURSEL, + (WPARAM)0, + (LPARAM)0 ) + == LB_ERR ){ + ErrorMsg(TEXT("VersionProc: Key LB Set Initial Selection failure.")); + return(0); + } + if( SendDlgItemMessage( hDlg, SB_VALUE, LB_SETCURSEL, + (WPARAM)0, + (LPARAM)0 ) + == LB_ERR ){ + ErrorMsg(TEXT("VersionProc: Value LB Set Initial Selection failure.")); + return(0); + } + + // Initialize Scroll Bar + // Check to see if a scroll bar is needed. See GLOBALS.H and FILER.DLG + if( NUM_VERSION_INFO_KEYS - VERSION_DLG_LB_HEIGHT > 0 ) + SendDlgItemMessage( hDlg, SB_SCROLL, SBM_SETRANGE, + (WPARAM)0, + (LPARAM)NUM_VERSION_INFO_KEYS -1); + SendDlgItemMessage( hDlg, SB_SCROLL, SBM_SETPOS, + (WPARAM)0, + (LPARAM)TRUE ); + + return(1); + } + + case WM_VSCROLL:{ + int nPos; + + nPos = SendDlgItemMessage( hDlg, SB_SCROLL, SBM_GETPOS, + (WPARAM)0, + (LPARAM)0 ); + + switch( LOWORD(wParam) ){ + + case SB_PAGEDOWN:{ + nPos += VERSION_DLG_LB_HEIGHT; + if( nPos > NUM_VERSION_INFO_KEYS ) + nPos = NUM_VERSION_INFO_KEYS; + break; + } + case SB_LINEDOWN:{ + nPos++; + if( nPos > NUM_VERSION_INFO_KEYS ) + nPos = NUM_VERSION_INFO_KEYS; + break; + } + case SB_PAGEUP:{ + nPos -= VERSION_DLG_LB_HEIGHT; + if( nPos < 0 ) + nPos = 0; + break; + } + case SB_LINEUP:{ + nPos--; + if( nPos < 0 ) + nPos = 0; + break; + } + default: + return(1); + } + + // Set Scroll Bar position + SendDlgItemMessage( hDlg, SB_SCROLL, SBM_SETPOS, + (WPARAM)nPos, + (LPARAM)TRUE ); + // Set selection in listboxes + if( SendDlgItemMessage( hDlg, SB_KEY, LB_SETCURSEL, + (WPARAM)nPos, + (LPARAM)0 ) + == LB_ERR ){ + ErrorMsg(TEXT("VersionProc: ListBox Set Current Selection failure.")); + return(0); + } + if( SendDlgItemMessage( hDlg, SB_VALUE, LB_SETCURSEL, + (WPARAM)nPos, + (LPARAM)0 ) + == LB_ERR ){ + ErrorMsg(TEXT("VersionProc: ListBox Set Current Selection failure.")); + return(0); + } + + return(0); + } + + case WM_COMMAND:{ + int nLBid = 0; // holds ID of listbox other than one sending LBN msg. + + switch( LOWORD(wParam) ){ + case SB_OK: + case SB_CANCEL:{ + // Free allocated buffer + EnterCriticalSection(&gHeapCS); + HeapFree( ghHeap, 0, lpszBuff); + LeaveCriticalSection(&gHeapCS); + + EndDialog(hDlg, wParam); + return(1); + } + + // SB_VALUE and SB_KEY are the ListBox IDs. Below are LB notifications. + case SB_VALUE: + nLBid = SB_KEY; + // we slip through to the SB_KEY case on purpose!! + case SB_KEY:{ + int nSelect; // Holds selected item + + if( HIWORD(wParam) == LBN_SELCHANGE ){ + + if( !nLBid ) // If nLBid wasn't set by the SB_VALUE case above... + nLBid = SB_VALUE; + + // Get current listbox selection. + nSelect = SendDlgItemMessage( hDlg, LOWORD(wParam), LB_GETCURSEL, + (WPARAM)0, + (LPARAM)0 ); + if( nSelect == LB_ERR ){ + ErrorMsg(TEXT("VersionProc: ListBox Get Selection failure.")); + return(0); + } + + // Set similar selection in corresponding listbox. + if( SendDlgItemMessage( hDlg, nLBid, LB_SETCURSEL, + (WPARAM)nSelect, + (LPARAM)0 ) + == LB_ERR ){ + ErrorMsg(TEXT("VersionProc: ListBox Get Current Selection failure.")); + return(0); + } + + + // Set Scroll Bar position + SendDlgItemMessage( hDlg, SB_SCROLL, SBM_SETPOS, + (WPARAM)nSelect, + (LPARAM)TRUE ); + } + } + } + return(1); + } + } + + return(0); +} + + +/***************************************************************************\ +* * IsDirectory() * * Given an item from a ListBox filled from an LB_DIR call, IsDirectory * verifies whether or not the item is a directory, and if so, returns * true, and places the full directory path in lpszFile. * -* input: lpszDir - Holds current directory +* input: lpszDir - Holds current directory * lpszFile - Holds item of dubious directoryness. * * History: @@ -823,71 +1328,78 @@ BOOL RunListBoxItem(LPCINFO lpCInfo, HWN * Created. * \***************************************************************************/ -BOOL IsDirectory(LPSTR lpszDir, LPSTR lpszFile) +BOOL IsDirectory(LPTSTR lpszDir, LPTSTR lpszFile) { DWORD dwAttrib; - LPSTR lpszHold; - char szItem[DIRECTORY_STRING_SIZE * 2]; + LPTSTR lpszHold; + TCHAR szItem[DIRECTORY_STRING_SIZE * 2]; + // // if it's '..', go up one directory // - if( !lstrcmp(lpszFile, "[..]") ){ + if( !lstrcmp(lpszFile, TEXT("[..]")) ){ lstrcpy(lpszFile, lpszDir); - lpszHold = strchr(lpszFile, '\0'); - while( (lpszHold > lpszFile) && (*lpszHold != '\\') ) + lpszHold = TStrChr(lpszFile, TEXT('\0')); + while( (lpszHold > lpszFile) && (*lpszHold != TEXT('\\')) ) lpszHold--; if(lpszHold <= lpszFile){ - ErrorMsg("IsDirectory: String parse error."); + ErrorMsg(TEXT("IsDirectory: String parse failure.")); return(0); } else{ - if( strchr(lpszFile, '\\') == lpszHold ) + if( TStrChr(lpszFile, TEXT('\\')) == lpszHold ) lpszHold++; - *lpszHold = '\0'; + *lpszHold = TEXT('\0'); return(1); } } // - // a directory will have [] around it in the listbox. Check for it. + // A directory will have [] around it in the listbox. Check for it. // - if( *lpszFile != '[' ) + if( *lpszFile != TEXT('[') ) return(0); // - // a file under some file systems may have [] characters. + // A file under some file systems may have [] characters. // Prepend path, adding a delimiting backslash unless we're in the root. // If the attribute check is successful, it's a file, so leave. // + // NOTE: This is a hack. If there is a file called '[foo]' and a + // Directory called 'foo', they will appear identical in the listbox. + // Rather than check for this rare case, if it happens, Filer will + // assume it is a file first, as the directory may be changed from + // the Directory Listbox. + // lstrcpy(szItem, lpszDir); - lpszHold = strchr(szItem, '\0'); + lpszHold = TStrChr(szItem, TEXT('\0')); + lpszHold--; - if( *lpszHold != '\\' ){ - lpszHold++; - *lpszHold = '\\'; + if( *lpszHold != TEXT('\\') ){ lpszHold++; + *lpszHold = TEXT('\\'); } - else - lpszHold++; + lpszHold++; lstrcpy(lpszHold, lpszFile); dwAttrib = GetFileAttributes(szItem); - if( dwAttrib != 0xFFFFFFFF ) - return(0); + if( dwAttrib != 0xFFFFFFFF ) // there really is a file called + return(0); // '[foo]'. Exit. // // remove the [], and check if valid directory. // if it fails, or it's not a directory, leave. // lstrcpy(lpszHold, &lpszFile[1]); - lpszHold = strchr(lpszHold, '\0'); + lpszHold = TStrChr(lpszHold, TEXT('\0')); + lpszHold--; - if( *lpszHold != ']' ) + if( *lpszHold != TEXT(']') ) return(0); - *lpszHold = '\0'; + *lpszHold = TEXT('\0'); dwAttrib = GetFileAttributes(szItem); @@ -922,9 +1434,9 @@ BOOL IsDirectory(LPSTR lpszDir, LPSTR lp BOOL ExecuteFileAction(LPSINFO lpSelect) { - if( DialogBoxParam(ghModule, "SelectDlg", lpSelect->hwnd, + if( DialogBoxParam(ghModule, TEXT("SelectDlg"), lpSelect->hwnd, (DLGPROC)SelectProc, (LPARAM)lpSelect) == -1 ){ - ErrorMsg("ExecuteFileAction: File I/O Dialog Creation Error!"); + ErrorMsg(TEXT("ExecuteFileAction: File I/O Dialog Creation failure.")); return(0); } return(1); @@ -940,7 +1452,7 @@ BOOL ExecuteFileAction(LPSINFO lpSelect) * 5/28/92 * Created. \***************************************************************************/ -LRESULT SelectProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +LRESULT WINAPI SelectProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { static LPSINFO lpSelect; @@ -958,19 +1470,19 @@ LRESULT SelectProc(HWND hDlg, UINT messa } // - // Set the 'action' text (i.e. "COPYING:", "MOVING:", etc.) + // Set the TEXT('action') text (i.e. TEXT("COPYING:"), TEXT("MOVING:"), etc.) // if( !SetDlgItemText(hDlg, SB_ACTION, lpSelect->szAction) ){ - ErrorMsg("SelectProc: Set Action Text Error."); + ErrorMsg(TEXT("SelectProc: Set Action Text failure.")); EndDialog(hDlg, wParam); return(1); } // - // Set the "TO:" or "FROM:" text. + // Set the TEXT("TO:") or TEXT("FROM:") text. // if( !SetDlgItemText(hDlg, SB_TOFROM, lpSelect->szToFrom) ){ - ErrorMsg("SelectProc: Set Action Text Error."); + ErrorMsg(TEXT("SelectProc: Set Action Text failure.")); EndDialog(hDlg, wParam); return(1); } @@ -978,7 +1490,7 @@ LRESULT SelectProc(HWND hDlg, UINT messa break; } case WM_COMMAND:{ - switch(wParam){ + switch(LOWORD(wParam)){ case SB_OK:{ DoFileIO(hDlg, lpSelect); EndDialog(hDlg, wParam); @@ -1022,24 +1534,18 @@ BOOL FillSelectDlg(HWND hDlg, LPSINFO lp int i; // counter LPCINFO lpCInfo; - HWND hActiveLB; // handle to Drv child's dir or file list box HWND hDest; // dir of files if delete, else inactive Drv dir. HDC hDC; TEXTMETRIC Metrics; - LPSTR lpszHold; // marks end of directory path in szName. - char szName[DIRECTORY_STRING_SIZE * 2]; // holds ListBox strings. + LPTSTR lpszHold; // marks end of directory path in szName. + TCHAR szName[DIRECTORY_STRING_SIZE * 2]; // holds ListBox strings. lpCInfo = (LPCINFO)GetWindowLong(lpSelect->hwnd, GWL_USERDATA); - if( IsFileLB(lpCInfo->hwndLR) ) - hActiveLB = lpCInfo->hwndLR; - else - hActiveLB = lpCInfo->hwndLL; - - lCount = SendMessage( hActiveLB, LB_GETSELCOUNT, + lCount = SendMessage( lpCInfo->hFileLB, LB_GETSELCOUNT, (WPARAM)NULL, (LPARAM)NULL ); // @@ -1052,39 +1558,50 @@ BOOL FillSelectDlg(HWND hDlg, LPSINFO lp // Allocate array of lCount listbox indexes, and fill it. // EnterCriticalSection(&gHeapCS); - lpnIndex = (UINT*)HeapAlloc( ghHeap, lCount * sizeof(UINT) ); + lpnIndex = (UINT*)HeapAlloc( ghHeap, 0, lCount * sizeof(UINT) ); LeaveCriticalSection(&gHeapCS); if( !lpnIndex ){ - ErrorMsg("FillSelectDlg: Item list allocation Error"); + ErrorMsg(TEXT("FillSelectDlg: Item list allocation failure.")); return(0); } - if( SendMessage( hActiveLB, LB_GETSELITEMS, (WPARAM)lCount, + if( SendMessage( lpCInfo->hFileLB, LB_GETSELITEMS, (WPARAM)lCount, (LPARAM)lpnIndex) != lCount ){ - ErrorMsg("FillSelectDlg: Get Selections Error"); + ErrorMsg(TEXT("FillSelectDlg: Get Selections failure.")); return(0); } // // Check if each selected entry is a valid file. - // Fill Dlg ListBox with selected strings from Drv child's ListBox, - // noting size of largest entry. // - + // Check to see if there is a terminating backslash, by decrementing + // pointer, checking, adding a '\' if necessary, then re-incrementing + // the pointer. + // lstrcpy(szName, lpCInfo->CaptionBarText); - lpszHold = strchr(szName, '\0'); - *lpszHold = '\\'; + + lpszHold = TStrChr(szName, TEXT('\0')); + + lpszHold--; + if( *lpszHold != TEXT('\\') ){ + lpszHold++; + *lpszHold = TEXT('\\'); + } lpszHold++; + // + // Fill Dlg ListBox with selected strings from Drv child's ListBox, + // noting size of largest entry. + // for( i = 0; i < lCount; i++){ - if( SendMessage( hActiveLB, LB_GETTEXT, (WPARAM)lpnIndex[i], + if( SendMessage( lpCInfo->hFileLB, LB_GETTEXT, (WPARAM)lpnIndex[i], (LPARAM)lpszHold) == LB_ERR ){ - ErrorMsg("FillSelectDlg: Get source string Error"); + ErrorMsg(TEXT("FillSelectDlg: Get source string failure.")); return(0); } - if( GetFileAttributes(szName) == 0xFFFFFFFF ){ - lstrcat(lpszHold, ": Access Denied."); + if( GetFileAttributes(szName) == 0xFFFFFFFF ){ //Error + lstrcat(lpszHold, TEXT(": Access Denied.")); ErrorMsg(lpszHold); } else{ @@ -1092,9 +1609,9 @@ BOOL FillSelectDlg(HWND hDlg, LPSINFO lp if( lSize > lLargest ) lLargest = lSize; - if( SendDlgItemMessage( hDlg, SB_SOURCE, LB_ADDSTRING, NULL, + if( SendDlgItemMessage( hDlg, SB_SOURCE, LB_ADDSTRING, 0, (LPARAM)lpszHold) == LB_ERR ){ - ErrorMsg("FillSelectDlg: Add source string Error"); + ErrorMsg(TEXT("FillSelectDlg: Add source string failure.")); return(0); } } @@ -1107,7 +1624,7 @@ BOOL FillSelectDlg(HWND hDlg, LPSINFO lp // hDC = GetDC(lpSelect->hwnd); if( !GetTextMetrics(hDC, &Metrics) ){ - ErrorMsg("FillSelectDlg: GetTextMetrics Error"); + ErrorMsg(TEXT("FillSelectDlg: GetTextMetrics failure.")); return(0); } @@ -1118,7 +1635,7 @@ BOOL FillSelectDlg(HWND hDlg, LPSINFO lp (LPARAM)NULL ); EnterCriticalSection(&gHeapCS); - HeapFree( ghHeap, (LPSTR)lpnIndex); + HeapFree( ghHeap, 0, (LPVOID)lpnIndex); LeaveCriticalSection(&gHeapCS); @@ -1142,9 +1659,9 @@ BOOL FillSelectDlg(HWND hDlg, LPSINFO lp SendDlgItemMessage( hDlg, SB_DEST, EM_LIMITTEXT, (WPARAM)DIRECTORY_STRING_SIZE, (LPARAM)0); - if( SendDlgItemMessage( hDlg, SB_DEST, WM_SETTEXT, NULL, + if( SendDlgItemMessage( hDlg, SB_DEST, WM_SETTEXT, 0, (LPARAM)lpCInfo->CaptionBarText) == CB_ERR ){ - ErrorMsg("FillSelectDlg: Set Destination text Error"); + ErrorMsg(TEXT("FillSelectDlg: Set Destination text failure.")); return(0); } @@ -1174,12 +1691,12 @@ BOOL DoFileIO( HWND hDlg, LPSINFO lpSele LONG lCount; LONG lFile; LPCINFO lpCInfo; - LPSTR lpEndDest; - LPSTR lpEndSource; + LPTSTR lpEndDest; + LPTSTR lpEndSource; BOOL fError = FALSE; - char szSource[DIRECTORY_STRING_SIZE]; - char szDest[DIRECTORY_STRING_SIZE * 2]; + TCHAR szSource[DIRECTORY_STRING_SIZE]; + TCHAR szDest[DIRECTORY_STRING_SIZE * 2]; // @@ -1189,7 +1706,7 @@ BOOL DoFileIO( HWND hDlg, LPSINFO lpSele (LPARAM)NULL); if( (lCount == LB_ERR) || (lCount == 0) ){ - ErrorMsg("Unable to get file selection."); + ErrorMsg(TEXT("DoFileIO: file selection failure.")); return(0); } @@ -1200,20 +1717,20 @@ BOOL DoFileIO( HWND hDlg, LPSINFO lpSele lstrcpy(szSource, lpCInfo->CaptionBarText); - lpEndSource = strchr(szSource, '\0'); - *lpEndSource++ = '\\'; + lpEndSource = TStrChr(szSource, TEXT('\0')); + *lpEndSource++ = TEXT('\\'); // // Get destination directory path. Add a \ to the end, set pointer to end. // if( SendDlgItemMessage( hDlg, SB_DEST, WM_GETTEXT, (WPARAM)DIRECTORY_STRING_SIZE * 2, (LPARAM)szDest) == CB_ERR ){ - ErrorMsg("Do I/O: Get Destination error."); + ErrorMsg(TEXT("Do I/O: Get Destination failure.")); return(0); } - lpEndDest = strchr(szDest, '\0'); - *lpEndDest++ = '\\'; + lpEndDest = TStrChr(szDest, TEXT('\0')); + *lpEndDest++ = TEXT('\\'); // // for each file, do appropriate I/O. @@ -1225,7 +1742,7 @@ BOOL DoFileIO( HWND hDlg, LPSINFO lpSele lFile = SendDlgItemMessage( hDlg, SB_SOURCE, LB_GETTEXT, (WPARAM)0, (LPARAM)lpEndSource); if( lFile == LB_ERR){ - ErrorMsg("DoFileIO: Unable to get file item."); + ErrorMsg(TEXT("DoFileIO: file string retrieval failure.")); fError = TRUE; } @@ -1269,7 +1786,7 @@ BOOL DoFileIO( HWND hDlg, LPSINFO lpSele } // - // Update appropriate file listboxes. + // Update file listboxes. // if( fError ) return(0); @@ -1284,37 +1801,6 @@ BOOL DoFileIO( HWND hDlg, LPSINFO lpSele /***************************************************************************\ * -* UpdateFileLB() -* -* Updates the file listbox of the drive child given by sending an MM_FILLFILE -* message to it. -* -* input: hwnd - Handle of drive child to update file listbox of. -* -* History: -* 6/3/92 -* Created. -* -\***************************************************************************/ -void UpdateFileLB(HWND hwnd) -{ - LPCINFO lpCInfo; - HWND hFileLB; - - lpCInfo = (LPCINFO)GetWindowLong(hwnd, GWL_USERDATA); - - if( IsFileLB(lpCInfo->hwndLL) ) - hFileLB = lpCInfo->hwndLL; - else - hFileLB = lpCInfo->hwndLR; - - SendMessage(hwnd, WM_COMMAND, (WPARAM)MM_FILLFILE, - (LPARAM)hFileLB); -} - - -/***************************************************************************\ -* * HandleIOError() * * Called by DoFileIO. Handles errors arising from File IO operations @@ -1332,12 +1818,12 @@ void UpdateFileLB(HWND hwnd) * Created. * \***************************************************************************/ -BOOL HandleIOError(HWND hwnd, DWORD dwAction, LPSTR szSource, LPSTR szDest) +BOOL HandleIOError(HWND hwnd, DWORD dwAction, LPTSTR szSource, LPTSTR szDest) { DWORD dwError; int nReply; LPCINFO lpCInfo; - char buff[50]; + TCHAR buff[50]; dwError = GetLastError(); @@ -1350,7 +1836,7 @@ BOOL HandleIOError(HWND hwnd, DWORD dwAc // MoveFile file already exists. We can CopyFile & DeleteFile source. // nReply = MessageBox(hwnd, - "File Already Exists! Overwrite file?", + TEXT("File Already Exists! Overwrite file?"), szDest, MB_YESNOCANCEL); switch( nReply ){ case IDYES:{ @@ -1388,7 +1874,7 @@ BOOL HandleIOError(HWND hwnd, DWORD dwAc case ERROR_FILE_NOT_FOUND: case ERROR_INVALID_PARAMETER:{ wsprintf(buff, - "Access Denied. Check file name or security. Error %ld", + TEXT("Access Denied. Check file name or security. Error %ld"), dwError); MessageBox( hwnd, buff, szDest, MB_OK); @@ -1397,7 +1883,7 @@ BOOL HandleIOError(HWND hwnd, DWORD dwAc case ERROR_DISK_FULL:{ MessageBox( hwnd, - "ERROR: The disk is full. Unable to continue.", + TEXT("ERROR: The disk is full. Unable to continue."), szDest, MB_OK); return(0); } @@ -1406,13 +1892,13 @@ BOOL HandleIOError(HWND hwnd, DWORD dwAc case ERROR_DIRECTORY: case ERROR_PATH_NOT_FOUND:{ MessageBox( hwnd, - "ERROR: The path or file does not exist. Unable to continue.", + TEXT("ERROR: The path or file does not exist. Unable to continue."), szDest, MB_OK); return(0); } default:{ - wsprintf(buff, "File I/O failed. Error %ld", dwError); + wsprintf(buff, TEXT("File I/O failure. Error %ld"), dwError); ErrorMsg(buff); return(1); } @@ -1431,52 +1917,43 @@ BOOL HandleIOError(HWND hwnd, DWORD dwAc * 6/5/92 2am * Created. \***************************************************************************/ -LRESULT RenameProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +LRESULT WINAPI RenameProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { - static char szName[DIRECTORY_STRING_SIZE]; - static LPSTR lpszHold; - static HWND hActiveLB; + static TCHAR szName[DIRECTORY_STRING_SIZE]; + static LPTSTR lpszHold; + static LPCINFO lpCInfo; switch (message){ case WM_INITDIALOG:{ LONG lIndex; - LPCINFO lpCInfo; - lpCInfo = (LPCINFO)lParam; - if( IsFileLB(lpCInfo->hwndLR) ) - hActiveLB = lpCInfo->hwndLR; - else - hActiveLB = lpCInfo->hwndLL; - - lIndex = SendMessage( hActiveLB, LB_GETCARETINDEX, - (WPARAM)NULL, (LPARAM)NULL); - if( lIndex == LB_ERR ){ - ErrorMsg("Rename: Invalid Selection"); - return(1); - } - // - // Check if selected entry is a valid file. + // Check to see if there is a terminating backslash, by decrementing + // pointer, checking, adding a '\' if necessary, then re-incrementing + // the pointer. // lstrcpy(szName, lpCInfo->CaptionBarText); - lpszHold = strchr(szName, '\0'); - *lpszHold = '\\'; + lpszHold = TStrChr(szName, TEXT('\0')); + + lpszHold--; + if( *lpszHold != TEXT('\\') ){ + lpszHold++; + *lpszHold = TEXT('\\'); + } lpszHold++; - if( SendMessage( hActiveLB, LB_GETTEXT, (WPARAM)lIndex, - (LPARAM)lpszHold) == LB_ERR ){ - ErrorMsg("Rename: Get Text Error"); + lIndex = GetLBText(lpCInfo->hFileLB, lpszHold); + if( lIndex == -1 ) return(1); - } // // if not a valid file (i.e. listbox directory entry in []s), fail. // - if( GetFileAttributes(szName) == 0xFFFFFFFF ){ - lstrcat(lpszHold, ": Access Denied."); + if( GetFileAttributes(szName) == 0xFFFFFFFF ){ //Error + lstrcat(lpszHold, TEXT(": Access Denied.")); ErrorMsg(lpszHold); return(1); } @@ -1492,36 +1969,36 @@ LRESULT RenameProc(HWND hDlg, UINT messa SendDlgItemMessage( hDlg, SB_DEST, EM_LIMITTEXT, (WPARAM)DIRECTORY_STRING_SIZE, (LPARAM)0); - if( SendDlgItemMessage( hDlg, SB_SOURCE, WM_SETTEXT, NULL, + if( SendDlgItemMessage( hDlg, SB_SOURCE, WM_SETTEXT, 0, (LPARAM)lpszHold) == LB_ERR ){ - ErrorMsg("Rename: Add Source String Error"); + ErrorMsg(TEXT("Rename: Add Source String failure.")); return(1); } - if( SendDlgItemMessage( hDlg, SB_DEST, WM_SETTEXT, NULL, + if( SendDlgItemMessage( hDlg, SB_DEST, WM_SETTEXT, 0, (LPARAM)lpszHold) == LB_ERR ){ - ErrorMsg("Rename: Add Destination String Error"); + ErrorMsg(TEXT("Rename: Add Destination String failure.")); return(1); } return(1); } case WM_COMMAND:{ - switch(wParam){ + switch(LOWORD(wParam)){ case SB_OK:{ - char szDest[DIRECTORY_STRING_SIZE]; - LPSTR lpszCheck; + TCHAR szDest[DIRECTORY_STRING_SIZE]; + LPTSTR lpszCheck; // // the entire source dir\file is still in static szName. // static lpszHold points to the end of the dir // - *lpszHold = '\0'; + *lpszHold = TEXT('\0'); lstrcpy(szDest, szName); if( SendDlgItemMessage( hDlg, SB_SOURCE, WM_GETTEXT, DIRECTORY_STRING_SIZE, (LPARAM)lpszHold) == LB_ERR ){ - ErrorMsg("Rename: Get Source String Error"); + ErrorMsg(TEXT("Rename: Get Source String failure.")); EndDialog(hDlg, wParam); return(1); } @@ -1529,53 +2006,55 @@ LRESULT RenameProc(HWND hDlg, UINT messa // // If there are any \s in the new filename, fail. // - lpszCheck = strchr(lpszHold, '\\'); + lpszCheck = TStrChr(lpszHold, TEXT('\\')); if( lpszCheck ){ - ErrorMsg("Rename works only in current directory."); + MessageBox(lpCInfo->hwnd, + TEXT("Rename works only in current directory."), + TEXT("Filer Notification"), MB_OK ); return(1); } - lpszHold = strchr(szDest, '\0'); + lpszHold = TStrChr(szDest, TEXT('\0')); if( SendDlgItemMessage( hDlg, SB_DEST, WM_GETTEXT, DIRECTORY_STRING_SIZE, (LPARAM)lpszHold) == LB_ERR ){ - ErrorMsg("Rename: Get Destination String Error"); + ErrorMsg(TEXT("Rename: Get Destination String failure.")); EndDialog(hDlg, wParam); return(1); } // - // If there are any \s in the new filename, fail. + // If there are any \s in the destination filename, fail. // - lpszCheck = strchr(lpszHold, '\\'); + lpszCheck = TStrChr(lpszHold, TEXT('\\')); if( lpszCheck ){ - ErrorMsg("Rename works only in current directory."); + MessageBox(lpCInfo->hwnd, + TEXT("Rename works only in current directory."), + TEXT("Filer Notification"), MB_OK ); return(1); } // // if strings are identical, leave. // - if( !stricmp(szName, szDest) ){ + if( !lstrcmpi(szName, szDest) ){ EndDialog(hDlg, wParam); return(1); } if( !MoveFile( szName, szDest) ) - if( !HandleIOError(GetParent(hActiveLB), + if( !HandleIOError(lpCInfo->hwnd, (DWORD)MM_RENAME, szName, szDest) ){ EndDialog(hDlg, wParam); return(1); } - // - // Update files listbox. - // - SendMessage(GetParent(hActiveLB), WM_COMMAND, (WPARAM)MM_FILLFILE, - (LPARAM)hActiveLB); + if( !PostMessage(lpCInfo->hwnd, WM_COMMAND, MM_FILLFILE, + (LPARAM)0) ) + ErrorMsg(TEXT("RenameProc: Fillfile failure.")); EndDialog(hDlg, wParam); return(1); @@ -1602,18 +2081,31 @@ LRESULT RenameProc(HWND hDlg, UINT messa * 6/5/92 2am * Created. \***************************************************************************/ -LRESULT MkDirProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +LRESULT WINAPI MkDirProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message){ case WM_INITDIALOG:{ LPCINFO lpCInfo; - char szDest[DIRECTORY_STRING_SIZE]; + TCHAR szDest[DIRECTORY_STRING_SIZE]; + LPTSTR lpszHold; lpCInfo = (LPCINFO)lParam; + // + // Check to see if there is a terminating backslash, by decrementing + // pointer, checking, adding a '\' if necessary. + // lstrcpy(szDest, lpCInfo->CaptionBarText); - lstrcat(szDest, "\\"); + lpszHold = TStrChr(szDest, TEXT('\0')); + + lpszHold--; + if( *lpszHold != TEXT('\\') ){ + lpszHold++; + *lpszHold = TEXT('\\'); + lpszHold++; + *lpszHold = TEXT('\0'); + } SendDlgItemMessage( hDlg, SB_DEST, EM_LIMITTEXT, (WPARAM)DIRECTORY_STRING_SIZE, (LPARAM)0); @@ -1621,9 +2113,9 @@ LRESULT MkDirProc(HWND hDlg, UINT messag // // Place name in directory name edit control. // - if( SendDlgItemMessage( hDlg, SB_DEST, WM_SETTEXT, NULL, + if( SendDlgItemMessage( hDlg, SB_DEST, WM_SETTEXT, 0, (LPARAM)szDest) == LB_ERR ){ - ErrorMsg("Mkdir: Add Directory Name String Error"); + ErrorMsg(TEXT("Mkdir: Add Directory Name String failure.")); return(1); } @@ -1634,12 +2126,12 @@ LRESULT MkDirProc(HWND hDlg, UINT messag case WM_COMMAND:{ switch(wParam){ case SB_OK:{ - char szDest[DIRECTORY_STRING_SIZE]; + TCHAR szDest[DIRECTORY_STRING_SIZE]; if( SendDlgItemMessage( hDlg, SB_DEST, WM_GETTEXT, DIRECTORY_STRING_SIZE, (LPARAM)szDest) == LB_ERR ){ - ErrorMsg("MkDir: Get Directory Location String Error"); + ErrorMsg(TEXT("MkDir: Get Directory Location String failure.")); EndDialog(hDlg, wParam); return(1); } @@ -1648,10 +2140,13 @@ LRESULT MkDirProc(HWND hDlg, UINT messag // If loacation of subdir is invalid, leave. // if( !CreateDirectory(szDest, NULL) ){ - ErrorMsg("Create Directory Error."); + ErrorMsg(TEXT("MkDir: Create Directory failure.")); EndDialog(hDlg, wParam); return(1); } + + SendMessage( ghwndDrv1, WM_COMMAND, MM_REFRESH, (LPARAM)0); + SendMessage( ghwndDrv2, WM_COMMAND, MM_REFRESH, (LPARAM)0); } case SB_CANCEL:{ EndDialog(hDlg, wParam); @@ -1685,28 +2180,29 @@ LRESULT WINAPI TextWndProc (HWND hwnd, U { case WM_CREATE: { - HDC hDC; - HGDIOBJ hOldFont; - TEXTMETRIC tm; - LONG lHeight; + HDC hDC; + HGDIOBJ hOldFont; + TEXTMETRIC tm; + LONG lHeight; - hDC = GetDC(hwnd); + hDC = GetDC(hwnd); - hOldFont = SelectObject(hDC, ghFont); - GetTextMetrics(hDC, &tm); + hOldFont = SelectObject(hDC, ghFont); + GetTextMetrics(hDC, &tm); - // - // base the height of the window on size of text - // - lHeight = tm.tmHeight + GetSystemMetrics(SM_CYBORDER) + 6; + // + // base the height of the window on size of text + // + lHeight = tm.tmHeight + GetSystemMetrics(SM_CYBORDER) + 6; - // - // saved the height for later reference - // - SetWindowLong(hwnd, GWL_USERDATA, lHeight); + // + // saved the height for later reference + // + SetWindowLong(hwnd, GWL_USERDATA, lHeight); if(hOldFont) SelectObject(hDC, hOldFont); + ReleaseDC(hwnd, hDC); break; } @@ -1714,7 +2210,7 @@ LRESULT WINAPI TextWndProc (HWND hwnd, U case WM_SETTEXT: DefWindowProc(hwnd, message, wParam, lParam); if( !InvalidateRect(hwnd, NULL, TRUE) ){ - ErrorMsg("Textwindow: Set text error."); + ErrorMsg(TEXT("Textwindow: Set text failure.")); return(1); } UpdateWindow(hwnd); @@ -1724,7 +2220,7 @@ LRESULT WINAPI TextWndProc (HWND hwnd, U { PAINTSTRUCT ps; RECT rc; - char ach[128]; + TCHAR ach[128]; int len, nxBorder, nyBorder; HFONT hOldFont = NULL; HBRUSH hBrush; @@ -1735,36 +2231,36 @@ LRESULT WINAPI TextWndProc (HWND hwnd, U len = GetWindowText(hwnd, ach, sizeof(ach)); - SetBkMode(ps.hdc, TRANSPARENT); + SetBkMode(ps.hdc, TRANSPARENT); if( GetParent(hwnd) == ghActiveChild ){ - hBrush = CreateSolidBrush( GetSysColor(COLOR_ACTIVECAPTION) ); - SetTextColor( ps.hdc, GetSysColor(COLOR_CAPTIONTEXT) ); + hBrush = CreateSolidBrush( GetSysColor(COLOR_ACTIVECAPTION) ); + SetTextColor( ps.hdc, GetSysColor(COLOR_CAPTIONTEXT) ); } else{ hBrush = CreateSolidBrush( GetSysColor(COLOR_INACTIVECAPTION) ); - SetTextColor( ps.hdc, GetSysColor(COLOR_INACTIVECAPTIONTEXT) ); + SetTextColor( ps.hdc, GetSysColor(COLOR_INACTIVECAPTIONTEXT) ); } - hOldFont = SelectObject(ps.hdc, ghFont); + hOldFont = SelectObject(ps.hdc, ghFont); FillRect(ps.hdc, &rc, hBrush); nxBorder = GetSystemMetrics(SM_CXBORDER); - rc.left += 9*nxBorder; + rc.left += 9*nxBorder; rc.right -= 9*nxBorder; nyBorder = GetSystemMetrics(SM_CYBORDER); - rc.top += 3*nyBorder; - rc.bottom -= 3*nyBorder; + rc.top += 3*nyBorder; + rc.bottom -= 3*nyBorder; - ExtTextOut(ps.hdc, rc.left+2*nxBorder, rc.top, ETO_CLIPPED, - &rc, ach, len, NULL); + ExtTextOut(ps.hdc, rc.left+2*nxBorder, rc.top, ETO_CLIPPED, + &rc, ach, len, NULL); - SetBkMode(ps.hdc, OPAQUE); + SetBkMode(ps.hdc, OPAQUE); - if (hOldFont) - SelectObject(ps.hdc, hOldFont); + if (hOldFont) + SelectObject(ps.hdc, hOldFont); DeleteObject(hBrush); @@ -1774,3 +2270,23 @@ LRESULT WINAPI TextWndProc (HWND hwnd, U } return DefWindowProc(hwnd, message, wParam, lParam); } + +/***************************************************************************\ +* +* TStrChr() +* +* A strchr() function which is ASCII or UNICODE. +* +* History: +* 2/25/93 +* Created. +* +\***************************************************************************/ +PTCHAR TStrChr(const PTCHAR string, UINT c) +{ +#ifdef UNICODE + return wcschr((wchar_t*)string, (wchar_t)c); +#else + return strchr(string, c); +#endif +}