Nov 24, 2009 at 12:28pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
void app_size()
{
CONSOLE_SCREEN_BUFFER_INFO screensize;
COORD app_win_coord;
HANDLE ScreenBuffer;
if ((ScreenBuffer = CreateConsoleScreenBuffer (GENERIC_READ, FILE_SHARE_READ, NULL, CONSOLE_TEXTMODE_BUFFER, NULL)) == INVALID_HANDLE_VALUE)
{
cout << "Error occured at create console screen buffer: " << GetLastError() << endl;
}
if (!GetConsoleScreenBufferInfo (ScreenBuffer, &screensize))
{
cout << "Error occured at get console screen buffer: " << GetLastError() << endl;
}
app_win_coord = screensize.dwCursorPosition;
printf ("screen x coordinates: %d, screen y coordinates: %d\r" , app_win_coord.X, app_win_coord.Y );
}
my output is always 0 for both x and y.
Am i using wrong functions? if so, what should i use?
Last edited on Nov 24, 2009 at 12:29pm UTC
Nov 25, 2009 at 12:02am UTC
Because CONSOLE_SCREEN_BUFFER_INFO::dwCursorPosition member stores the cursor position, not the console window size.
CONSOLE_SCREEN_BUFFER_INFO::dwSize contains the screen buffer size.
CONSOLE_SCREEN_BUFFER_INFO::srWindow member contains the console window's rect.
Note that console window size does not need to have the same size with screen buffer size.
Console window size can be less than screen buffer size.
And you don't need to create your own screen buffer.
You can get active console screen buffer handle by calling GetStdHandle(STD_OUTPUT_HANDLE)
Nov 25, 2009 at 2:00am UTC
ok fixed that, but how do i know which window it is taking reading from? anyway i can get the values for the one that i m using?
Nov 26, 2009 at 5:32am UTC
Only one window, but screen buffers can be more than one.
Of course GetConsoleWindow() function retrieves the console window's HWND.
available environment:
Client: Included in Windows XP and Windows 2000 Professional.
Server: Included in Windows Server 2003 and Windows 2000 Server.
Only one screen buffer can be active.
Active screen buffer is shown on the screen(console window).
You can get the values for one that you're using,
if you retrieve active screen buffer handle by calling GetStdHandle(STD_OUTPUT_HANDLE).