Subj : OOP, using color To : borland.public.cpp.borlandcpp From : "Rob C." Date : Thu Oct 09 2003 06:29 pm EasyWin windows Here is my first truly OOP program (and it works great!), if you care to look at it (I’d appreciate some comments how I could make it better). At this point I’m stuck, though. I want to print this stuff with color, but the color functions I’m familiar with (textcolor, textbackgroundcolor, cprintf, etc.), are not available on this platform, and the program won’t work on other platforms. Do you have any ideas? Are there other functions I’m not aware of? If you tell me the generic code to write a color function, I could write my own color-class. #include #include #include #include #include #include #include int dsub=0; class base { //6 public: base() { //cout << "constructing\n"; } ~base( ) { }//cout << "destructing\n"; } char *data[100]; char *directories[100]; //void * operator new(size_t, void * buf) { return buf; } struct dirent *readdir(DIR *dirp); void scandir(char *dirname, base *pb ); //int strlen(const char *s); int SaveName( char *line1, base *pb ); }; //6 class derived1 : public base { }; void scandir(char *dirname, base *pb ) { DIR *dir; struct dirent *ent; int len; char line1[100]; derived1 ddd; if ((dir = opendir(dirname)) == NULL) { perror("Unable to open directory"); exit(1); } while ((ent = readdir(dir)) != NULL) { len = strlen( ent->d_name ); if( ent->d_name[len-3] == 'e' || ent->d_name[len-3] == 'E' && ent->d_name[len-2] == 'x' || ent->d_name[len-2] == 'X' && ent->d_name[len-1] == 'e' || ent->d_name[len-1] == 'E' ) { sprintf( line1, "%s %s", dirname, ent->d_name ); ddd.SaveName( line1, pb ); } } if (closedir(dir) != 0) perror("Unable to close directory"); } int base::SaveName( char *line1, base *pb ) { pb->data[dsub] = (char *) malloc( 30 ); strcpy( pb->data[dsub], line1 ); dsub++; return 0; } int main() { //77 int sub, csub; base abc, *pb; char *dosdata[100], *pdos; csub=0; while( csub <= 100 ) { abc.data[csub] = '\0'; abc.directories[csub] = '\0'; dosdata[csub] = '\0'; csub++; } pb = &abc; //first, read all *.exe's in specified directories abc.directories[0]= "\\learn\\moclips"; abc.directories[1]= "\\learn\\wsv"; abc.directories[2]= "\\learn\\library"; abc.directories[3]= "\\learn\\books"; abc.directories[4]= "\\learn\\reserv"; abc.directories[5]= "\\learn\\wizard"; abc.directories[6]= "\\learn\\dms"; sub=0; while(sub < 8) { scandir(abc.directories[ sub ], pb ); sub++; if( abc.directories[ sub ] == '\0' ) break; } sub=0; while(1) { if( pb->data[ sub ] == '\0' )break; dosdata[sub] = pb->data[sub]; sub++; } //second, list all *.exe's and their paths in color sub=0; while(1) { if( pb->data[ sub ] == '\0' ) { break; } gotoxy( 15,5+sub); printf( "%s", pb->data[ sub ]); sub++; } //operator selects an *.exe's and path //save *.exe and path and delete data array //shell-out cd\ and execute *.exe return 0; } //77 .