the console have 2 types of size, right?
i belive that is the window size and the container size. the window size i can do it, but how can i change the container(i think that you call it buffer or something) size?
Printable View
the console have 2 types of size, right?
i belive that is the window size and the container size. the window size i can do it, but how can i change the container(i think that you call it buffer or something) size?
There are 2 sizes associated with a console. The size of the window and the size of the buffer. The buffer can be greater than the size of the window, but the window cannot be greater than the buffer. Basically you write to the buffer and the window displays that portion of the buffer over which it is placed.
To set buffer size, use SetConsoleScreenBufferSize(...)
To get buffer size, use something like
To get windows size, you need something like thisCode:DWORD GetBufferSize(HANDLE sout, COORD& size)
{
CONSOLE_SCREEN_BUFFER_INFO info;
if (!GetConsoleScreenBufferInfo(sout, &info)) {
return (GetLastError());
}
size.X = info.dwSize.X;
size.Y = info.dwSize.Y;
return (0);
}
Code:DWORD GetConsoleSize(HANDLE sout, COORD& size)
{
CONSOLE_FONT_INFO cfinfo;
COORD fsize;
WINDOWINFO winfo;
if (!GetCurrentConsoleFont(sout, FALSE, &cfinfo)) {
return (GetLastError());
}
fsize = GetConsoleFontSize(sout, cfinfo.nFont);
if (!fsize.X && !fsize.Y) {
return (GetLastError());
}
winfo.cbSize = sizeof(WINDOWINFO);
if (!GetWindowInfo(GetConsoleWindow(), &winfo)) {
return (GetLastError());
}
size.Y = (SHORT)((winfo.rcClient.bottom - winfo.rcClient.top) / fsize.Y);
size.X = (SHORT)((winfo.rcClient.right - winfo.rcClient.left) / fsize.X);
return (0);
}
To set window size use something like this
Code:DWORD SetConSize(HANDLE sout, COORD size)
{
CONSOLE_SCREEN_BUFFER_INFO info;
if (!GetConsoleScreenBufferInfo(sout, &info)) {
return (GetLastError());
}
info.srWindow.Top = 0;
info.srWindow.Bottom = size.Y - 1;
info.srWindow.Left = 0;
info.srWindow.Right = size.X - 1;
return (!SetConsoleWindowInfo(sout, TRUE, &info.srWindow) ? GetLastError() : 0);
}
Yes, the window just shows a part of the buffer if the size of the buffer is greater than the size of the window. Depending upon how the sizes of the buffer and window have been set, you can get a horizontal scrollbar as well. If you don't want scroll bars then set the window size and the buffer size to be the same.
Note when setting buffer sizes that the rules apply! You cannot set a window greater than the buffer size and then set the buffer! The buffer needs to be set first and then the window size. Also if you are reducing the buffer size to be less than the current window size, then reduce the window size first and then the buffer size.
why the scrollbar isn't hided?
seems that these code is ignored:(Code:CONSOLE_SCREEN_BUFFER_INFO info;
RECT WindowRect;
GetWindowRect(ConsoleHandle,&WindowRect);
info.srWindow.Top =WindowRect.top;
info.srWindow.Left= WindowRect.left;
info.srWindow.Bottom = WindowRect.bottom;
info.srWindow.Right = WindowRect.right ;
SetConsoleWindowInfo(ConsoleDC, TRUE, &info.srWindow);
What does this GetWindowRect return? TRUE or FALSE?
The same question - about GetWindowRect.
sorry about that.. you shared. but if the windows and buffer sizes are the same, why the scrollbar stills there?
Then go to the Win32 Error Codes adn look for the code with "number 6". It is
Quote:
ERROR_INVALID_HANDLEThe handle is invalid
yes i mistake it lol
see the sub:
Code:struct Window
{
HWND WindowHandle;
HDC WindowDC;
};
HWND ConsoleHandle;
HDC ConsoleDC;
Window b;
void GetConsoleHwnd(Window &console)
{
#define MY_BUFSIZE 1024 // Buffer size for console window titles.
HWND hwndFound; // This is what is returned to the caller.
char pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated
// WindowTitle.
char pszOldWindowTitle[MY_BUFSIZE]; // Contains original
// WindowTitle.
// Fetch current window title.
GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);
// Format a "unique" NewWindowTitle.
wsprintf(pszNewWindowTitle,"%d/%d",
GetTickCount(),
GetCurrentProcessId());
// Change current window title.
SetConsoleTitle(pszNewWindowTitle);
// Ensure window title has been updated.
Sleep(10);
// Look for NewWindowTitle.
hwndFound=FindWindow(NULL, pszNewWindowTitle);
// Restore original window title.
SetConsoleTitle(pszOldWindowTitle);
console.WindowHandle =hwndFound;
console.WindowDC =GetDC( hwndFound);
ConsoleDC=console.WindowDC;
ConsoleHandle=console.WindowHandle;
COORD consize;
GetConsoleSize(ConsoleHandle, consize);
SetConsoleScreenBufferSize(ConsoleHandle, consize);
cout << GetLastError ();
}
As explained, error 6 means that the value of the handle passed to the function SetConsoleWindowInfo as first parameter is not valid. As I asked before, how do you obtain this value? You have it named ConsoleDC but a console handle is nothing at all to do with a Device Context in the sense used in Windows gui programming!
The program below when run from a console will set the buffer to be the same size as the console window and will therefore remove the scroll bars.
Note you should always test for errors after calling a function! - omitted in main here for clarityCode:#define WINVER 0x0501
#define _WIN32_WINNT WINVER
#include <windows.h>
DWORD GetConsoleSize(HANDLE sout, COORD& size)
{
CONSOLE_FONT_INFO cfinfo;
COORD fsize;
WINDOWINFO winfo;
if (!GetCurrentConsoleFont(sout, FALSE, &cfinfo)) {
return (GetLastError());
}
fsize = GetConsoleFontSize(sout, cfinfo.nFont);
if (!fsize.X && !fsize.Y) {
return (GetLastError());
}
winfo.cbSize = sizeof(WINDOWINFO);
if (!GetWindowInfo(GetConsoleWindow(), &winfo)) {
return (GetLastError());
}
size.Y = (SHORT)((winfo.rcClient.bottom - winfo.rcClient.top) / fsize.Y);
size.X = (SHORT)((winfo.rcClient.right - winfo.rcClient.left) / fsize.X);
return (0);
}
int main()
{
HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
COORD csize;
GetConsoleSize(hcon, csize);
SetConsoleScreenBufferSize(hcon, csize);
return 0;
}
Windows/console programming is fairly complicated. That's why you need to learn how to do these things. You can't just sit down and write these kinds of programs 'on the hoof'! There are about 70 api functions alone just referring to console programming!Quote:
why they complicate so many in C++ with API functions
NO!! A console handle is not a window handle or a device context. DC is not used in console programming.Code:console.WindowHandle =hwndFound;
console.WindowDC =GetDC( hwndFound);
ConsoleDC=console.WindowDC;
ConsoleHandle=console.WindowHandle;
COORD consize;
GetConsoleSize(ConsoleHandle, consize);
SetConsoleScreenBufferSize(ConsoleHandle, consize);
To get a handle to the console being used, use GetStdHandle as per my example.
Good luck! You don't normally do graphics (except character graphics) in a console window - thats why its called a console and is just text! If you want graphics, I suggest you create a normal windows program.Quote:
if you don't use DC, you can't use graphics lol
i build a game in console heheheheh
In console terms, a lot! They are very different things. A HANDLE is a handle to either the input, output or error buffers whereas HWND is a handle to the console window itself. All the console api functions need a console handle (HANDLE) as opposed to a windows handle (HWND). To get console handles use GetStdHandle(...).Quote:
what is the diference between HWND and HANDLE?
sorry to both but i can't rate you again... thanks for all.. thanks
Why go through all the above if all you want is the HWND of the console? Just useCode:#define MY_BUFSIZE 1024 // Buffer size for console window titles.
HWND hwndFound; // This is what is returned to the caller.
char pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated WindowTitle.
char pszOldWindowTitle[MY_BUFSIZE]; // Contains original WindowTitle.
// Fetch current window title.
GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);
// Format a "unique" NewWindowTitle.
wsprintf(pszNewWindowTitle,"%d/%d", GetTickCount(), GetCurrentProcessId());
// Change current window title.
SetConsoleTitle(pszNewWindowTitle);
// Ensure window title has been updated.
Sleep(10);
// Look for NewWindowTitle.
hwndFound=FindWindow(NULL, pszNewWindowTitle);
// Restore original window title.
SetConsoleTitle(pszOldWindowTitle);
console.WindowHandle =hwndFound;
Simples!:DCode:console.WindowHandle = GetConsoleWindow();
No - English. Simples is from a famous TV commercial featuring Meerkats!Quote:
are you portuguese?
http://www.google.co.uk/search?q=com...w=1244&bih=862