Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- //make vertical white bar(s) across an 80x50 console
- void vbar(CHAR_INFO buff[4000], int pos){
- if (pos < 0 || pos > 79) {return;}
- const CHAR_INFO white = { ' ', BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY };
- const CHAR_INFO black = { ' ', 0 };
- for (int i = 0; i < 80; i++) { buff[i] = black;}
- buff[pos] = white;
- buff[(pos + 1) % 80] = white;
- buff[(pos + 3) % 80] = white;
- buff[(pos + 5) % 80] = white;
- CHAR_INFO* firstLine = buff;
- for (CHAR_INFO* curLine = &buff[80]; curLine < &buff[80 * 49 + 1]; curLine += 80)
- { memcpy_s((void*)curLine, sizeof(CHAR_INFO) * 80, (void*)firstLine, sizeof(CHAR_INFO)*80);}
- }
- int _tmain(int argc, _TCHAR* argv[]){
- HANDLE hdl = GetStdHandle(STD_OUTPUT_HANDLE);
- CHAR_INFO buff[80 * 50];
- SetConsoleScreenBufferSize(hdl, { 80, 50 });
- SMALL_RECT recv = { 0, 0, 80, 50 };
- DWORD oldTime = GetTickCount();
- int pos = 0;
- SHORT yPos = 0;
- bool done = false;
- while (!done){
- CONST DWORD newTime = GetTickCount();
- if (newTime != oldTime)
- { vbar(buff, pos);
- DWORD diffTime = newTime - oldTime;
- oldTime = newTime;
- pos = (pos + 1) % 80;
- WriteConsoleOutput(hdl, buff, { 80, 50 }, { 5, 0 }, &recv);
- yPos = (yPos + 1) % 50;
- printf_s("%04d", diffTime);
- SetConsoleCursorPosition(hdl, { 75, yPos });
- }
- if (_kbhit())
- {done = (_getch() == 27);}
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement