I am trying to create some sort of progress indicator for file copying.
In this program, I had to update the progress bar with the symbols after each file copy VIA a gotoxy statement. This got extremely confusing while writting the source code albeit the program turned out fine.
Now I am working on this route:
Now, I ran this, and copied a 15mb ( or so ) file, and the little cursor animates perfectly, and the copied message displays perfectly, etc. With one simple file, this does great.Code:#include <stdio.h> #include <stdlib.h> #include <windows.h> int FileCopy( char * Fromt, char * To, char * Display ); int gotoxy(int x, int y); int clrscr(); int kill_cursor(void); int main() { clrscr(0, 0); kill_cursor(); FileCopy("d:\\roms\\mameb16\\mk2.zip", "c:\\mk2.zip", "MK2"); return 0; } int FileCopy( char * From, char * To, char * Display ) { size_t len; char buf[BUFSIZ]; FILE * in, * out; FILE * Tmp; if ( ( Tmp = fopen ( From, "r" ) ) == 0 ) { printf("%s not found, skipping.\n", Display); Sleep(200); } else { fclose(Tmp); if ( ( in = fopen ( From, "rb" ) ) != NULL ) { if ( ( out = fopen ( To, "wb" ) ) != NULL ) { gotoxy(0, 0); printf("Copying.."); do { len = fread ( buf, 1, sizeof buf, in ); if ( len != 0 ) { fwrite ( buf, 1, len, out ); } gotoxy(0, 1); printf("\\"); gotoxy(0, 1); printf("|"); gotoxy(0, 1); printf("/"); gotoxy(0 ,1); printf("-"); } while ( len == sizeof buf ); { fclose ( out ); gotoxy(0, 1); printf("Copied: %s\n", Display); } } else { printf("File copy output error: %s\n", Display); } fclose ( in ); } else { printf("File copy input error: %s\n", Display); } } return EXIT_SUCCESS; } int gotoxy(int x, int y) { COORD coord; coord.X = x; coord.Y = y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); return 0; } int kill_cursor(void) { CONSOLE_CURSOR_INFO cci; cci.dwSize = 1; cci.bVisible = FALSE; SetConsoleCursorInfo( GetStdHandle( STD_OUTPUT_HANDLE ), &cci ); return 0; } int clrscr() { COORD coordScreen = { 0, 0}; DWORD cCharsWritten; CONSOLE_SCREEN_BUFFER_INFO csbi; DWORD dwConSize; HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); GetConsoleScreenBufferInfo(hConsole, &csbi); dwConSize = csbi.dwSize.X * csbi.dwSize.Y; FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten); GetConsoleScreenBufferInfo(hConsole, &csbi); FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten); SetConsoleCursorPosition(hConsole, coordScreen); return 0; }
How would I be able to do something similar to this, or the previous example, with half of the screen already filled with output.
I was thinking...maybe some fancy, or clever loop or something?
I want to designate a location on the screen someplace, for a progress indicator throughout the whole program. Yet, in the main section of the screen, I want to be able to display the catagory of files that are being copied, and a confirmation as each individual file is copied.



LinkBack URL
About LinkBacks


