int main()
{
SetConsoleTitle( "Progress messages demo!" );
// First Linux style progress message
void LinuxStyleProgressMessage( const char* Msg );
LinuxStyleProgressMessage( "This is a linux style progress message..." );
// Read in read character from stream to avoid _kbhit from exiting
_getch();
// Now it's the turn for Windows 2000 style progress message
std::cout << "/n/n/nA Windows 2000 style progress message/n/n";
void Windows2000StyleProgressMessage( const char* Msg );
Windows2000StyleProgressMessage( "Installing Windows Vista.../n" );
return 0;
}
void LinuxStyleProgressMessage( const char* Msg )
{
std::cout << Msg;
HANDLE hOutputHandle = GetStdHandle( STD_OUTPUT_HANDLE );
CONSOLE_SCREEN_BUFFER_INFO ScrBuffInfo = { 0 };
GetConsoleScreenBufferInfo( hOutputHandle, &ScrBuffInfo );
//const char Sticks[] = { '//',char(179),'/',char(196) };
const char Sticks[] = { '//','|','/','-' };
int Index = 0;
while( !_kbhit() )
{
std::cout << Sticks[Index];
++Index;
Index %= sizeof(Sticks);
Sleep(100);
SetConsoleCursorPosition(hOutputHandle,ScrBuffInfo.dwCursorPosition);
}// End while
}// LinuxStyleProgressMessage
void Windows2000StyleProgressMessage( const char* Msg )
{
std::cout << Msg;
HANDLE hOutputHandle = GetStdHandle( STD_OUTPUT_HANDLE );
CONSOLE_SCREEN_BUFFER_INFO ProgressPos = { 0 };
GetConsoleScreenBufferInfo( hOutputHandle, &ProgressPos );
CONSOLE_SCREEN_BUFFER_INFO MsgPos = ProgressPos;
int PercentComplete = 0;
int MsgLength = 0;
while( !_kbhit() )
{
SetConsoleCursorPosition( hOutputHandle, ProgressPos.dwCursorPosition );
for( int MsgIndex = 0; MsgIndex < MsgLength; ++MsgIndex )
{
// Insert spaces to delete previous "percentage complete message"
std::cout << " ";
}
SetConsoleCursorPosition( hOutputHandle, ProgressPos.dwCursorPosition );
//std::cout << char( 219 );
std::cout << "|";
GetConsoleScreenBufferInfo( hOutputHandle, &ProgressPos );
std::stringstream sstream;
sstream << " " << PercentComplete++ << "%";
MsgLength = (int)sstream.str().length();
std::cout << sstream.str();
GetConsoleScreenBufferInfo( hOutputHandle, &MsgPos );
Sleep( rand() % 1000 );
}// End while
}// End ShowWin2000StyleProgress