Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- #include <strsafe.h>
- using namespace std;
- SHORT nScreenWidth=100, nScreenHeight=80;
- const SMALL_RECT windowRect = { 0,0,nScreenWidth,nScreenHeight };
- void ErrorExit(LPTSTR lpszFunction)
- {
- // Retrieve the system error message for the last-error code
- LPVOID lpMsgBuf;
- LPVOID lpDisplayBuf;
- DWORD dw = GetLastError();
- FormatMessage(
- FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- dw,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPTSTR)&lpMsgBuf,
- 0, NULL);
- // Display the error message and exit the process
- lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT,
- (lstrlen((LPCTSTR)lpMsgBuf) + lstrlen((LPCTSTR)lpszFunction) + 40) * sizeof(TCHAR));
- StringCchPrintf((LPTSTR)lpDisplayBuf,
- LocalSize(lpDisplayBuf) / sizeof(TCHAR),
- TEXT("%s failed with error %d: %s"),
- lpszFunction, dw, lpMsgBuf);
- MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK);
- LocalFree(lpMsgBuf);
- LocalFree(lpDisplayBuf);
- ExitProcess(dw);
- }
- int main() {
- wchar_t *screen = new wchar_t[nScreenWidth*nScreenHeight];
- HANDLE hConsole = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
- SetConsoleActiveScreenBuffer(hConsole);
- DWORD dwBytesWritten = 0;
- for (int x = 0; x < nScreenWidth; x++) {
- for (int y = 0; y < nScreenHeight; y++) {
- screen[x + y*nScreenHeight] = 'p';
- }
- }
- while (1) {
- screen[nScreenWidth * nScreenHeight - 1] = '\0';
- if (SetConsoleWindowInfo(hConsole, TRUE, &windowRect) == 0) {
- cout << GetLastError()<< endl;
- LPTSTR string = L"text";
- ErrorExit(string);
- break;
- }
- WriteConsoleOutputCharacter(hConsole, screen, nScreenWidth * nScreenHeight, { 0,0 }, &dwBytesWritten);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement