Skip to content

Instantly share code, notes, and snippets.

@LasseSkogland
Created March 30, 2017 21:23
Show Gist options
  • Save LasseSkogland/2133c66005c62f3f2e82e08c76ade15c to your computer and use it in GitHub Desktop.
Save LasseSkogland/2133c66005c62f3f2e82e08c76ade15c to your computer and use it in GitHub Desktop.
Skid Simulator 2017
#pragma once
#include <consoleapi.h>
#include <string>
#include <memory>
class Console {
public:
Console() {
hConsole = GetConsoleWindow();
hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
}
~Console() {
}
void clear() {
COORD coordScreen = { 0, 0 };
BOOL bSuccess;
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
GetConsoleScreenBufferInfo(hConsoleOut, &csbi);
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
FillConsoleOutputCharacter(hConsoleOut, (TCHAR) ' ', dwConSize, coordScreen, &cCharsWritten);
GetConsoleScreenBufferInfo(hConsoleOut, &csbi);
FillConsoleOutputAttribute(hConsoleOut, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
SetConsoleCursorPosition(hConsoleOut, coordScreen);
}
void setCursorPosition(int x, int y) {
COORD coords = {x, y};
SetConsoleCursorPosition(hConsoleOut, coords);
}
void center() {
RECT consoleSize;
int desktopW = GetSystemMetrics(SM_CXFULLSCREEN);
int desktopH = GetSystemMetrics(SM_CYFULLSCREEN);
GetWindowRect(hConsole, &consoleSize);
int x = (desktopW / 2) - (consoleSize.right / 2);
int y = (desktopH / 2) - (consoleSize.bottom / 2);
MoveWindow(hConsole, x, y, consoleSize.right, consoleSize.bottom, TRUE);
}
void setSize(int w, int h) {
RECT consoleSize;
GetWindowRect(hConsole, &consoleSize);
MoveWindow(hConsole, consoleSize.left, consoleSize.top, w, h, TRUE);
}
void write(std::string str) {
WriteConsoleA(hConsoleOut, str.c_str(), str.length(), NULL, NULL);
}
private:
HWND hConsole;
HANDLE hConsoleOut;
HANDLE hConsoleIn;
};
#include <Windows.h>
#include "Console.h"
int main() {
Console console = Console();
console.setSize(946, 400);
console.center();
console.setCursorPosition(0, 0);
console.write("Downloading source code...\n");
Sleep(2000);
console.write("Trying to figure out how a compiler works...\n");
Sleep(5000);
console.write("Considering buying cheat instead...\n");
Sleep(1000);
console.write("Buying cheat...\n");
return -1337;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment