#include #include #include #include #include #include #define BUFFERSIZE 80 * 25 using namespace std; /** * Improved scrolly routine! Uses 80 columns by 25 rows * in a Windows console, written in Code::Blocks, tested * on Windows 7 Professional SP1 * * @Author: Shaun B * @Version: 1.0.0.2 - 2012-09-05 * **/ int main(); void ClrScr (short, short, short, short, signed char, char); void Print (short, short, signed char, char *, ...); void hideCursor(); void scroll(); void exchangeToDisplay(); static unsigned short counter; static unsigned short i; static char Erase[BUFFERSIZE]; // Sets variables for: // Scrolly message - static char scrolly [] = "....................This is a scrolly text....................Nah nah nah nah nahhhh....................Like a BAWS....................#\0"; // Display string - static char display [80]; // Keyboard input - static char character; // Running boolean - static char run = 1; // Sleep time - static signed int sleep = 100; // Char buffer for scroll function - static char buffer[1]; static HANDLE hStdout, hNewScreenBuffer; static SMALL_RECT srctReadRect; static SMALL_RECT srctWriteRect; static CHAR_INFO chiBuffer[BUFFERSIZE]; static COORD coordBufSize = {0}; static COORD coordBufCoord = {0}; static BOOL fSuccess; static va_list List; static unsigned short FormattedStringLength; int main () { // Sets default console size, colours and title: system("mode CON: COLS=80 LINES=25"); system("title Scrolly started at %TIME% on %DATE%"); // Switches off blinking cursor: SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), ENABLE_INSERT_MODE); hideCursor(); // Clears screen from x, y to x1, y1, setting default colours and sending a space ClrScr (0, 0, 25, 80, 0x12, 32); // Sets up display string: exchangeToDisplay(); // Main loop: while(run) { // Printing the display string at 0, 0 with colours E and 3 Print (0, 0, 0xe3, display); // Does the same for the bottom row of the console: Print (24, 0, 0x90, display); if (_kbhit()) { character=_getch(); } // Checks for space... if(character==32) { // If so, stops main loop: run=0; } // Checks for left arrow and arrow down... if((character==75 || character==80) && sleep<255) { // Increases sleep call (higher is slower): sleep+=10; } // Checks for other arrow keys... if((character==72 || character==77) && sleep>0) { // Decreases sleep call: sleep-=10; } // Clears character buffer if set: if(character) { character=0; } // Checks if time exceeds longest sleep time: if(sleep>254) { sleep=255; } // Checks if time exceeds shortest sleep time: if(sleep<1) { sleep=0; } // Calls scroll function: scroll(); // Calls sleep function: Sleep(sleep+1); } system("cls"); std::cout<<"Goodbye!"<