I want to use cin or cout after activating the buffer. What should I do

2

I am trying to use double beffering
but I haven't made it yet
please ignore it

Can I take input after activating the first buffer?
I get an error if I get input after activating the first buffer (0xc0000142)
I want to use cout or cin after calling SetConsoleActiveScreenBuffer function. How do I do this?

#include <iostream>


using namespace std;

int main()
{
    

    HANDLE mhBuffer[2];
    int mCurrentBufferIndex = 0;
    COORD mSize;

    mSize.X = 120;
    mSize.Y = 30;

    CONSOLE_CURSOR_INFO cci;
    SMALL_RECT rect;
    rect.Left = 0;
    rect.Right = mSize.X - 1;
    rect.Top = 0;
    rect.Bottom = mSize.Y - 1;

    //CreateBuffer

    mhBuffer[0] = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
    SetConsoleScreenBufferSize(mhBuffer[0], mSize);
    SetConsoleWindowInfo(mhBuffer[0], TRUE, &rect);

    mhBuffer[1] = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
    SetConsoleScreenBufferSize(mhBuffer[1], mSize);
    SetConsoleWindowInfo(mhBuffer[1], TRUE, &rect);

    cci.dwSize = 1;
    cci.bVisible = FALSE;
    SetConsoleCursorInfo(mhBuffer[0], &cci);
    SetConsoleCursorInfo(mhBuffer[1], &cci);


    //Write to Buffer
    DWORD dw;
    COORD CursorPosition = { 0,0 };
    SetConsoleCursorPosition(mhBuffer[mCurrentBufferIndex], CursorPosition);

    char str[] = "buffer";
    WriteFile(mhBuffer[mCurrentBufferIndex], str, strlen(str), &dw, NULL);
    Sleep(33);

    SetConsoleActiveScreenBuffer(mhBuffer[mCurrentBufferIndex]);


    int b = 0;
    cin >> b;


}
c++
console
asked on Stack Overflow Aug 9, 2020 by HariboHaribo • edited Aug 9, 2020 by klutt

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0