Advertisement
Guest User

Untitled

a guest
May 27th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <strsafe.h>
  4.  
  5. using namespace std;
  6.  
  7. SHORT nScreenWidth=100, nScreenHeight=80;
  8. const SMALL_RECT windowRect = { 0,0,nScreenWidth,nScreenHeight };
  9.  
  10.  
  11. void ErrorExit(LPTSTR lpszFunction)
  12. {
  13.     // Retrieve the system error message for the last-error code
  14.  
  15.     LPVOID lpMsgBuf;
  16.     LPVOID lpDisplayBuf;
  17.     DWORD dw = GetLastError();
  18.  
  19.     FormatMessage(
  20.         FORMAT_MESSAGE_ALLOCATE_BUFFER |
  21.         FORMAT_MESSAGE_FROM_SYSTEM |
  22.         FORMAT_MESSAGE_IGNORE_INSERTS,
  23.         NULL,
  24.         dw,
  25.         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  26.         (LPTSTR)&lpMsgBuf,
  27.         0, NULL);
  28.  
  29.     // Display the error message and exit the process
  30.  
  31.     lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT,
  32.         (lstrlen((LPCTSTR)lpMsgBuf) + lstrlen((LPCTSTR)lpszFunction) + 40) * sizeof(TCHAR));
  33.     StringCchPrintf((LPTSTR)lpDisplayBuf,
  34.         LocalSize(lpDisplayBuf) / sizeof(TCHAR),
  35.         TEXT("%s failed with error %d: %s"),
  36.         lpszFunction, dw, lpMsgBuf);
  37.     MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK);
  38.  
  39.     LocalFree(lpMsgBuf);
  40.     LocalFree(lpDisplayBuf);
  41.     ExitProcess(dw);
  42. }
  43.  
  44. int main() {
  45.     wchar_t *screen = new wchar_t[nScreenWidth*nScreenHeight];
  46.     HANDLE hConsole = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
  47.     SetConsoleActiveScreenBuffer(hConsole);
  48.     DWORD dwBytesWritten = 0;
  49.  
  50.     for (int x = 0; x < nScreenWidth; x++) {
  51.         for (int y = 0; y < nScreenHeight; y++) {
  52.             screen[x + y*nScreenHeight] = 'p';
  53.         }
  54.     }
  55.  
  56.     while (1) {
  57.         screen[nScreenWidth * nScreenHeight - 1] = '\0';
  58.         if (SetConsoleWindowInfo(hConsole, TRUE, &windowRect) == 0) {
  59.             cout << GetLastError()<< endl;
  60.             LPTSTR string = L"text";
  61.             ErrorExit(string);
  62.             break;
  63.         }
  64.         WriteConsoleOutputCharacter(hConsole, screen, nScreenWidth * nScreenHeight, { 0,0 }, &dwBytesWritten);
  65.     }
  66.    
  67.  
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement