Jump to content
  • Advertisement
Sign in to follow this  
cambalinho

c++ - How resize window Console?

This topic is 1075 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

how can i resize window Console?

i did these code:

void SetWindowSize(COORD newsize)
    {
        PCONSOLE_SCREEN_BUFFER_INFOEX consolesize;
        GetConsoleScreenBufferInfoEx(hConsole,consolesize);

        COORD c;
        consolesize->srWindow.Right  = newsize.X+ consolesize->srWindow.Left;
        consolesize->srWindow.Bottom = newsize.Y+ consolesize->srWindow.Top;
        SetConsoleWindowInfo(hConsole, TRUE, &consolesize->srWindow);
        PCONSOLE_FONT_INFO consolefont;
        GetCurrentConsoleFont(hConsole, FALSE,consolefont);
        GetConsoleFontSize(hConsole,consolefont->nFont);
        c.X =(consolesize->srWindow.Right-consolesize->srWindow.Left)/consolefont->dwFontSize.X;
        c.Y =(consolesize->srWindow.Bottom-consolesize->srWindow.Top)/consolefont->dwFontSize.Y;
        DebugText("hello size " + to_string(c.X) + "  " + to_string(c.Y));
        SetConsoleScreenBufferSize( hConsole, c );
    }

but i get a memory leak, or i see the scrollbars.

what i'm doing wrong?

Share this post


Link to post
Share on other sites
Advertisement
According to the MSDN documentation for SetConsoleWindowInfo:
 
"The function fails if the specified window rectangle extends beyond the boundaries of the console screen buffer. This means that the Top and Left members of the lpConsoleWindow rectangle (or the calculated top and left coordinates, if bAbsolute is FALSE) cannot be less than zero. Similarly, the Bottom and Right members (or the calculated bottom and right coordinates) cannot be greater than (screen buffer height – 1) and (screen buffer width – 1), respectively. The function also fails if the Right member (or calculated right coordinate) is less than or equal to the Left member (or calculated left coordinate) or if the Bottom member (or calculated bottom coordinate) is less than or equal to the Top member (or calculated top coordinate)."
 
This, to me, seems to state that you must first increase the screen buffer size and then set the window size. Are you checking the return values? Which function is failing, if any? Edited by MarkS

Share this post


Link to post
Share on other sites

ok.. now no memory leak:

void SetWindowSize(COORD newsize)
    {
        CONSOLE_SCREEN_BUFFER_INFOEX consolesize;//see these type name
        consolesize.cbSize=sizeof(consolesize);//i forgot these
        GetConsoleScreenBufferInfoEx(hConsole,&consolesize);
        COORD c;
        consolesize.srWindow.Right  = newsize.X-1;
        consolesize.srWindow.Bottom = newsize.Y-1;
        CONSOLE_FONT_INFO consolefont={0} ;//see these type name
        GetCurrentConsoleFont(hConsole, FALSE,&consolefont);
        GetConsoleFontSize(hConsole,consolefont.nFont);
        c.X =(consolesize.srWindow.Right)/consolefont.dwFontSize.X;
        c.Y =(consolesize.srWindow.Bottom)/consolefont.dwFontSize.Y;
        SetConsoleScreenBufferSize( hConsole, c );
        SetConsoleWindowInfo(hConsole, FALSE, &consolesize.srWindow);
    }

i have 1 problem on c.X and c.Y calculations, because the vertical scrollbar continues visible :(

can you advice me?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!