CStringz & CStringz::Lower(void) { // char *p=str; Refresh(); AnsiLower(str); // for ( ; *p ; p++) *p=tolower(*p); return *this; }
char * MakeCanonicalFileName (const char * fileName) { char buffer [_MAX_PATH]; char * result = StrDup (_tfullpath (buffer, fileName, _MAX_PATH)); if (result != 0) { AnsiLower (result); slashToBackSlash (result); } return (result); }
int TFileOpen::canClose() { WORD pathLen; GetDlgItemText(hWindow, id_FName, fileSpec, fsPathName + 1); fnmerge(pathName,"","",fileSpec,""); pathLen = strlen(pathName); if (hasWildCards(pathName) || (GetFocus() == GetDlgItem( hWindow, id_DList) || ( pathLen && (pathName[pathLen - 1] == '\\') ) )) { if (pathName[pathLen - 1] == '\\') strncat(pathName, fileSpec, fsPathName); if (!updateListBoxes()) { MessageBeep(0); selectFileName(); } return 0; } strncat(strncat(pathName, "\\", fsPathName), fileSpec, fsPathName); if (updateListBoxes()) return 0; pathName[pathLen] = '\0'; if (getExtension(pathName)[0] == '\0') strncat(pathName, extension, fsPathName); AnsiLower((LPSTR) strcpy(filePath, pathName)); updateButtons(); if (IsDlgButtonChecked(hWindow, id_Text) == 1) *fileType = FileWindow; else if (IsDlgButtonChecked(hWindow, id_Scribble) == 1) *fileType = ScribbleWindow; else if (IsDlgButtonChecked(hWindow, id_Graph) == 1) *fileType = GraphWindow; else return 0; return 1; }
HDDEDATA FAR PASCAL _export PowDdeServerProc (UINT type,UINT fmt,HCONV hconv,HSZ hsz1,HSZ hsz2,HDDEDATA hdata,DWORD dwData1,DWORD dwData2) { LPSTR exec; HWND hWnd; DWORD size; HDDEDATA hDat; switch (type) { case XTYP_CONNECT: return (HDDEDATA)IsTopic(hsz1); case XTYP_EXECUTE: { char buf[1000]; if (IsTopic(hsz1)) { DdeGetData(hdata,buf,sizeof(buf),0); exec=GetExecData(buf); if (IsCommand(buf,"openfile")) { if (*exec && (hWnd=AlreadyOpen(exec))) BringWindowToTop(hWnd); else { #ifndef _WIN32 DownStr(exec); #endif AddFile(exec); } return (HDDEDATA)DDE_FACK; } else if (IsCommand(buf,"newfile")) { hWnd=AddFile(0); if (hWnd && *exec) { HWND old; if (old=AlreadyOpen(exec)) SendMessage (hwndMDIClient,WM_MDIDESTROY,(WPARAM)old,0L); #ifndef _WIN32 DownStr(exec); #endif SetWindowText(hWnd,exec); SetWindowWord(hWnd,GWW_UNTITLED,0); } return (HDDEDATA)DDE_FACK; } else if (IsCommand(buf,"savefile")) { if (GetActiveEditWindow(hwndMDIClient)) { if (*exec) { #ifndef _WIN32 AnsiLower(exec); #endif SetWindowText(GetActiveEditWindow(hwndMDIClient),exec); SetWindowWord(GetActiveEditWindow(hwndMDIClient),GWW_UNTITLED,0); } SendMessage(hwndFrame,WM_COMMAND,IDM_FILESAVE,0); } return (HDDEDATA)DDE_FACK; } else if (IsCommand(buf,"activate")) { if (*exec && (hWnd=AlreadyOpen(exec))) BringWindowToTop(hWnd); return (HDDEDATA)DDE_FACK; } else if (IsCommand(buf,"appendtext") || IsCommand(buf,"addtext")) { if (*exec && GetActiveEditWindow(hwndMDIClient) && IsEditWindow(GetActiveEditWindow(hwndMDIClient))) EditAddText(GetActiveEditWindow(hwndMDIClient),exec); return (HDDEDATA)DDE_FACK; } else if (IsCommand(buf,"inserttext")) { if (*exec && GetActiveEditWindow(hwndMDIClient) && IsEditWindow(GetActiveEditWindow(hwndMDIClient))) EditInsertText(GetActiveEditWindow(hwndMDIClient),exec); return (HDDEDATA)DDE_FACK; } else if (IsCommand(buf,"appendfile") || IsCommand(buf,"addtext")) { if (*exec && GetActiveEditWindow(hwndMDIClient) && IsEditWindow(GetActiveEditWindow(hwndMDIClient))) { EditGotoPos(GetActiveEditWindow(hwndMDIClient),-1,-1); InsertFile(exec); } return (HDDEDATA)DDE_FACK; } else if (IsCommand(buf,"insertfile")) { if (*exec && GetActiveEditWindow(hwndMDIClient) && IsEditWindow(GetActiveEditWindow(hwndMDIClient))) InsertFile(exec); return (HDDEDATA)DDE_FACK; } else if (IsCommand(buf,"showposition")) { /* go to line/col of a given file (open if necessary) */ if (*exec) { char *file,*sline,*scol; int line=-1,col=-1; file=strtok(exec," "); if (file) { /* read position */ sline=strtok(NULL," "); if (sline) { line=atoi(sline); scol=strtok(NULL," "); if (scol) col=atoi(scol); } /* display the file */ if (hWnd=AlreadyOpen(file)) BringWindowToTop(hWnd); else { #ifndef _WIN32 DownStr(file); #endif AddFile(file); } /* set caret to given position */ EditGotoPos(GetActiveEditWindow(hwndMDIClient),line,col); } } return (HDDEDATA)DDE_FACK; } else if (IsCommand(buf,"addtool")) { /* create a new tool */ if (*exec) { LPSTR lp; char *name,*cmd,*dir,*options; BOOL menu,askArg,toTop; int buttonId; name=cmd=dir=options=NULL; menu=askArg=toTop=FALSE; buttonId=0; /* read tool name */ name=strtok(exec,","); if (name) { cmd=strtok(NULL,","); if (cmd) { dir=strtok(NULL,","); if (dir) { options=strtok(NULL,","); if (options) { lp=strtok(NULL,","); if (lp) { menu=(BOOL)atoi(lp); lp=strtok(NULL,","); if (lp) { buttonId=atoi(lp); lp=strtok(NULL,","); if (lp) { toTop=(BOOL)atoi(lp); lp=strtok(NULL,","); if (lp) { askArg=(BOOL)atoi(lp); } } } } } } } } if (strcmp(dir," ")==0) dir=""; if (strcmp(options," ")==0) options=""; if (name && cmd && *name && *cmd && (menu || buttonId)) ToolAdd(name,cmd,dir,options,menu,buttonId,toTop,askArg); } return (HDDEDATA)DDE_FACK; } else if (IsCommand(buf,"deletetool")) { /* remove an external tool */ if (*exec) ToolDelete(exec); return (HDDEDATA)DDE_FACK; } } return (HDDEDATA)DDE_FNOTPROCESSED; } case XTYP_POKE: { if (IsTopic(hsz1)) { if (IsEqualString(hsz2,"editbuffer")) { if (GetActiveEditWindow(hwndMDIClient) && IsEditWindow(GetActiveEditWindow(hwndMDIClient))) { LPSTR lBuf; if (lBuf=DdeAccessData(hdata,(LPDWORD)&size)) { EditResetContent(GetActiveEditWindow(hwndMDIClient)); EditAddText(GetActiveEditWindow(hwndMDIClient),lBuf); DdeUnaccessData(hdata); } } return (HDDEDATA)DDE_FACK; } } return (HDDEDATA)DDE_FNOTPROCESSED; } case XTYP_REQUEST: { if (IsTopic(hsz1)) { if (IsEqualString(hsz2,"activefile")) { if (GetActiveEditWindow(hwndMDIClient) && IsEditWindow(GetActiveEditWindow(hwndMDIClient))) { long len; char name[100]; HSZ hitem; hitem=DdeCreateStringHandle(ddeInstId,(LPSTR)"activefile",CP_WINANSI); len=GetWindowText(GetActiveEditWindow(hwndMDIClient),(LPSTR)name,sizeof(name)); return DdeCreateDataHandle(ddeInstId,(LPSTR)name,len+1,0,hitem,CF_TEXT,0); } } else if (IsEqualString(hsz2,"editbuffer")) { if (GetActiveEditWindow(hwndMDIClient) && IsEditWindow(GetActiveEditWindow(hwndMDIClient))) { LPSTR lp; HGLOBAL h; if (h=EditGetText(GetActiveEditWindow(hwndMDIClient))) { HSZ hitem; hitem=DdeCreateStringHandle(ddeInstId,(LPSTR)"editbuffer",CP_WINANSI); lp=GlobalLock(h); hDat=DdeCreateDataHandle(ddeInstId,lp,GlobalSize(h),0,hitem,CF_TEXT,0); GlobalUnlock(h); GlobalFree(h); } else hDat=0; return hDat; } } else if (IsEqualString(hsz2,"compiler")) { /* return name of active compiler interface dll */ char name[100]; HSZ hitem; hitem=DdeCreateStringHandle(ddeInstId,(LPSTR)"compiler",CP_WINANSI); strcpy(name,actConfig.compiler); return DdeCreateDataHandle(ddeInstId,(LPSTR)name,strlen(name)+1,0,hitem,CF_TEXT,0); } else if (IsEqualString(hsz2,"executable")) { /* return name of target executale */ BOOL isExecutable; //FARPROC lpfn; char name[500]; HSZ hitem; if (IsCompilerInterfaceLoaded()) { if (!*actPrj) { RemoveMessageWindow(); if (GetActiveEditWindow(hwndMDIClient) && IsEditWindow(GetActiveEditWindow(hwndMDIClient)) && !GetWindowWord(GetActiveEditWindow(hwndMDIClient),GWW_UNTITLED)) { SetDefaultProjectName(); isExecutable=(*compGetTarget)(hCompData,(LPSTR)name); if (*name && *RunArgs) { /* append run arguments (as string included in "") */ strcat(name," \""); strcat(name,RunArgs); strcat(name,"\""); } } else *name=0; } else isExecutable=(*compGetTarget)(hCompData,(LPSTR)name); } else *name=0; hitem=DdeCreateStringHandle(ddeInstId,(LPSTR)"executable",CP_WINANSI); return DdeCreateDataHandle(ddeInstId,(LPSTR)name,strlen(name)+1,0,hitem,CF_TEXT,0); } } return (HDDEDATA) NULL; } } if (type&XCLASS_FLAGS) return (HDDEDATA)DDE_FNOTPROCESSED; else return (HDDEDATA)NULL; }
void TFileOpen::updateFileName() { SetDlgItemText(hWindow, id_FName, AnsiLower(pathName)); SendDlgItemMessage(hWindow, id_FName, CB_SETEDITSEL, 0, MAKELONG( 0, -1)); updateButtons(); }
/* Resets and fills the given combobox with a list of current * drives. The type of drive is stored with the item data. */ void FASTCALL DriveListInitialize(HWND hList, HWND hTempList, UINT iCurDrive ) { UINT i, iItem; UINT cch; UINT cItems; UINT iDrive, iType; char szDrive[ 10 ]; char szNet[ 64 ]; char szItem[ 68 ]; if( NULL == hList ) return; /* Clear out all the lists. */ ComboBox_ResetContent( hList ); ListBox_ResetContent( hTempList ); /* Get available drive letters in the temp list */ ListBox_Dir( hTempList, DDL_DRIVES | DDL_EXCLUSIVE, "*" ); iCurDrive -= 1; /* Fix for zero-based drive indexing */ /* Walk through the list of drives, parsing off the "[-" and "-]" * For each drive letter parsed, add a string to the combobox * composed of the drive letter and the volume label. We then * determine the drive type and add that information as the item data. */ cItems = ListBox_GetCount( hTempList ); for( i = 0; i < cItems; i++ ) { ListBox_GetText( hTempList, i, szDrive ); /* Ensure lowercase drive letters */ AnsiLower(szDrive); iDrive = szDrive[ 2 ] - 'a'; iType = AmDriveType( szDrive ); /* See Below */ if( iType < 2 ) /* Skip non-existent drive B's */ continue; /* Start the item string with the drive letter, color, and two spaces */ wsprintf( szItem, "%c%s", szDrive[ 2 ], (LPSTR)": " ); /* For fixed or ram disks, append the volume label which we find * using _dos_findfirst and attribute _A_VOLID. */ if( DRIVE_FIXED == iType || DRIVE_RAMDISK == iType ) { #ifdef WIN32 wsprintf( szDrive, "%c:\\", szDrive[ 2 ] ); GetVolumeInformation( szDrive, szItem + strlen( szItem ), 20, NULL, NULL, NULL, NULL, 0 ); #else FINDDATA fi; HFIND hFind; char ch; wsprintf( szDrive, "%c:\\*.*", szDrive[ 2 ] ); if( ( hFind = Amuser_FindFirst( szDrive, _A_VOLID, &fi ) ) != -1 ) { /* Convert volume to lowercase and strip any '.' in the name. */ AnsiLower( fi.name ); /* If a period exists, it has to be in position 8, so clear it. */ ch = fi.name[ 8 ]; fi.name[ 8 ] = 0; strcat( szItem, fi.name ); /* If we did have a broken volume name, append the last 3 chars */ if( '.' == ch ) strcat( szItem, &fi.name[ 9 ] ); } Amuser_FindClose( hFind ); #endif } /* For network drives, go grab the \\server\share for it. */ if( DRIVE_REMOTE == iType ) { szNet[ 0 ] = 0; cch = sizeof( szNet ); wsprintf( szDrive, "%c:", szDrive[ 2 ] ); AnsiUpper(szDrive); // if( WNetGetConnection( (LPSTR)szDrive, (LPSTR)szNet, &cch ) == NO_ERROR ) // { // AnsiLower(szNet); // strcat( szItem, szNet ); // } } iItem = ComboBox_AddString( hList, szItem ); ComboBox_SetItemData( hList, iItem, MAKELONG( iDrive, iType ) ); if( iDrive == iCurDrive ) ComboBox_SetCurSel( hList, iItem ); } }
/* This function handles the WM_COMMAND message. */ void FASTCALL ChangeDir_OnCommand( HWND hwnd, int id, HWND hwndCtl, UINT codeNotify ) { static BOOL fListHasFocus = FALSE; switch( id ) { case IDD_NETWORK: if( WNetConnectionDialog( hwnd, WNTYPE_DRIVE ) == WN_SUCCESS ) { #ifndef WIN32 HINSTANCE hinstNetDriver; int iDrive; hinstNetDriver = (HINSTANCE)WNetGetCaps( 0xFFFF ); if( hinstNetDriver ) { LPWNETGETLASTCONNECTION lpDialogAPI; lpDialogAPI = (LPWNETGETLASTCONNECTION)GetProcAddress( hinstNetDriver, (LPSTR)ORD_WNETGETLASTCONNECTION); if( lpDialogAPI != NULL ) if( lpDialogAPI( WNTYPE_DRIVE, &iDrive ) == WN_SUCCESS ) { ++iDrive; DriveListInitialize( GetDlgItem( hwnd, IDD_DRIVELIST ), GetDlgItem( hwnd, IDD_TEMPLIST ), iDrive ); // SendDlgCommand( hwnd, IDD_DRIVELIST, CBN_SELCHANGE ); } } #endif } break; case IDD_DIRECTORYLIST: if( codeNotify == LBN_SETFOCUS ) fListHasFocus = TRUE; else if( codeNotify == LBN_KILLFOCUS ) fListHasFocus = FALSE; else if( codeNotify == LBN_DBLCLK ) { UINT i; DWORD dw; char szDir[_MAX_PATH]; char szCurDir[_MAX_PATH]; LPSTR lpsz; /* On double-click, change directory and reinit the * listbox. But all we stored in the string was * the directory's single name, so we use the bitmap * type to tell if we're below the current directory * (in which case we just chdir to our name) or above * (in which case we prepend "..\"'s as necessary. */ i = ListBox_GetCurSel( hwndCtl ); dw = ListBox_GetItemData( hwndCtl, i ); /* If out bitmap is IDB_FOLDERCLOSED or the root, * then just . If we're IDB_FOLDEROPENSELECT, * don't do anything. If we're IDB_FOLDEROPEN then * we get the full current path and truncate it * after the directory to which we're switching. */ if( IDB_FOLDEROPENSELECT == HIWORD( dw ) ) { id = IDOK; goto CloseDialog; } /* Get get the directory for sub-directory changes. */ ListBox_GetText( hwndCtl, i, szCurDir ); if( IDB_FOLDEROPEN == HIWORD( dw ) && 0 != i ) { /* Get the current path and find us in this path */ GetWindowText( hwndCtl, szDir, sizeof( szDir ) ); lpsz=_fstrstr( szDir, szCurDir ); /* Null terminate right after us. */ *( lpsz + strlen( szCurDir ) ) = '\0'; /* Get this new directory in the right place */ strcpy( szCurDir, szDir ); } /* chdir has a nice way of validating for us. */ if( 0 == _chdir( szCurDir ) ) { /* Get the new full path. */ Amdir_GetCurrentDirectory( szCurDir, _MAX_PATH ); DirectoryListInitialize( hwndCtl, GetDlgItem( hwnd, IDD_TEMPLIST ), szCurDir ); //???? YH18/04/96 AnsiLower( szCurDir ); SetDlgItemText( hwnd, IDD_EDIT, szCurDir ); } } break; case IDD_DRIVELIST: if( codeNotify == CBN_SELCHANGE ) { UINT i, iCurDrive; char szCurDir[ _MAX_PATH ]; char szDrive[ _MAX_PATH ]; /* Enough for drive:volume */ /* Get the first letter in the current selection */ i = ComboBox_GetCurSel( hwndCtl ); ComboBox_GetLBText( hwndCtl, i, szDrive ); iCurDrive = _getdrive(); /* Save in case of restore */ /* Attempt to set the drive and get the current * directory on it. Both must work for the change * to be certain. If we are certain, reinitialize * the directories. Note that we depend on drives * stored as lower case in the combobox. */ if( _chdrive( (int)( szDrive[ 0 ] - 'a' + 1 ) ) == 0 && ( Amdir_GetCurrentDirectory( szCurDir, _MAX_PATH ) != 0 ) ) { DirectoryListInitialize( GetDlgItem( hwnd, IDD_DIRECTORYLIST ), GetDlgItem( hwnd, IDD_TEMPLIST ), szCurDir ); /* Insure that the root is visible (UI guideline) */ SendDlgItemMessage( hwnd, IDD_DIRECTORYLIST, LB_SETTOPINDEX, 0, 0L ); AnsiLower( szCurDir ); SetDlgItemText( hwnd, IDD_EDIT, szCurDir ); break; } /* Changing drives failed so restore drive and selection */ _chdrive( (int)iCurDrive ); wsprintf( szDrive, "%c:", (char)( iCurDrive + 'a' - 1 ) ); ComboBox_SelectString( hwndCtl, -1, szDrive ); } break; case IDD_EDIT: if( codeNotify == EN_UPDATE ) EnableControl( hwnd, IDOK, Edit_GetTextLength( hwndCtl ) > 0 ); break; case IDOK: { LPCHGDIR lpChgDir; if( fListHasFocus ) { // PostDlgCommand( hwnd, IDD_DIRECTORYLIST, LBN_DBLCLK ); break; } CloseDialog: lpChgDir = (LPCHGDIR)GetWindowLong( hwnd, DWL_USER ); Edit_GetText( GetDlgItem( hwnd, IDD_EDIT ), lpChgDir->szPath, sizeof( lpChgDir->szPath ) ); } case IDCANCEL: { register int i; for( i = IDB_DRIVEMIN; i <= IDB_DRIVEMAX; i++ ) DeleteBitmap( rghBmpDrives[ i - IDB_DRIVEMIN ] ); for( i = IDB_FOLDERMIN; i <= IDB_FOLDERMAX; i++ ) DeleteBitmap( rghBmpFolders[ i - IDB_FOLDERMIN ] ); fBitmapsLoaded = FALSE; _chdrive( iCurDrive ); _chdir( szDefDir ); EndDialog( hwnd, id == IDOK ); break; } } }
/* This function handles the WM_INITDIALOG message. */ BOOL FASTCALL ChangeDir_OnInitDialog( HWND hwnd, HWND hwndFocus, LPARAM lParam ) { #ifndef WIN32 HINSTANCE hinstNetDriver; #endif LPCHGDIR lpChgDir; int iDrive; /* Set the current directory value */ lpChgDir = (LPCHGDIR)lParam; if( *lpChgDir->szPath ) { Edit_SetText( GetDlgItem( hwnd, IDD_EDIT ), lpChgDir->szPath ); lstrcpy( szCurDir, lpChgDir->szPath ); if( szCurDir[ 1 ] == ':' ) iDrive = ( toupper( *szCurDir ) - 'A' ) + 1; else iDrive = _getdrive(); } else { Amdir_GetCurrentDirectory( szCurDir, _MAX_PATH ); iDrive = _getdrive(); } /* Show the Network button if we're running WorkGroups * or a similiar networking O/S. */ #ifdef WIN32 ShowWindow( GetDlgItem( hwnd, IDD_NETWORK ), SW_SHOW ); #else hinstNetDriver = (HINSTANCE)WNetGetCaps( 0xFFFF ); if( hinstNetDriver ) { LPWNETSERVERBROWSEDIALOG lpDialogAPI; lpDialogAPI = (LPWNETSERVERBROWSEDIALOG)GetProcAddress( hinstNetDriver, (LPSTR)ORD_WNETSERVERBROWSEDIALOG); if( lpDialogAPI != NULL ) ShowWindow( GetDlgItem( hwnd, IDD_NETWORK ), SW_SHOW ); } #endif /* Set window title */ if( *lpChgDir->szTitle ) SetWindowText( hwnd, lpChgDir->szTitle ); /* Set the prompt title */ if( *lpChgDir->szPrompt ) SetWindowText( GetDlgItem( hwnd, IDD_PROMPT ), lpChgDir->szPrompt ); /* Initialise the drive and directory lists */ DriveListInitialize( GetDlgItem( hwnd, IDD_DRIVELIST ), GetDlgItem( hwnd, IDD_TEMPLIST ), iDrive ); DirectoryListInitialize( GetDlgItem( hwnd, IDD_DIRECTORYLIST ), GetDlgItem( hwnd, IDD_TEMPLIST), szCurDir ); AnsiLower( szCurDir ); /* Remember the current drive and directory */ Amdir_GetCurrentDirectory( szDefDir, _MAX_PATH ); iCurDrive = _getdrive(); if( iDrive != iCurDrive ) _chdrive( iDrive ); if( strcmp( szDefDir, szCurDir ) != 0 ) _chdir( szCurDir ); /* Disable OK if directory blank */ EnableControl( hwnd, IDOK, Edit_GetTextLength( GetDlgItem( hwnd, IDD_EDIT ) ) > 0 ); /* Remember pointer to directory */ SetWindowLong( hwnd, DWL_USER, lParam ); return( TRUE ); }