Cant get the active window's size.

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
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)
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?
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).
Did not solve the problem with getting same values.

but i have found a function in msdn GetClientRect() which retrieves client window coordinates as well, so i've been trying with that now.

and a new problem with it. question is in:
http://www.cplusplus.com/forum/windows/16775/
Topic archived. No new replies allowed.