Problem with Console resizeing

Hey there,

I've got a problem with the following code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  void set_console()
{
	//Define size
	short hight = 10;
	short width = 10;

	HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
	SMALL_RECT size;
	COORD b_size;

	size.Left = 0;
	size.Top = 0;
	size.Right = width;
	size.Bottom = hight;
	b_size.X = width + 1; //width+1 
	b_size.Y = hight + 1; //hight+1 

	SetConsoleWindowInfo(hCon, true, &size);
	SetConsoleScreenBufferSize(hCon, b_size);

	// Prepare Window Settings
	SetConsoleTitleA("- DATALOGGER -");
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
	CloseHandle;
}


It just tells me that the Membername for "Left" and "Right" is missing.

Can anybody give me a little hint?

Cheers.
Last edited on
Try putting this structure somewhere before your set_console function
1
2
3
4
5
6
struct SMALL_RECT {
    SHORT Left;
    SHORT Top;
    SHORT Right;
    SHORT Bottom;
};

Most of the examples show that structure in their code.
It compiles without issue for me.
I thought the "SMALL_RECT"-structure is already included in windows.h.
But I tried it anyway and it even highlight "Left" and "Right" in struct as before.

I'm using Visual Studio 2013 and Left and Right is also coloured purple if this helps.

Using following headers:
1
2
3
4
5
6
#include "stdafx.h"
#include <windows.h>
#include <stdlib.h>"
#include <iomanip>

using namespace std;
Last edited on
closed account (E0p9LyTq)
SMALL_RECT is defined in <wincon.h>, automatically added by <windows.h> (per MSDN). https://msdn.microsoft.com/en-us/library/windows/desktop/ms686311%28v=vs.85%29.aspx

Trying explicitly including <wincon.h> after your <windows.h> include. A big reach, but worth a try.

Are you adding any 3rd party libraries that might redefine SMALL_RECT?

I don't use VS2013 so I'm stumped why you are getting this error.
Tried to include wincon but didn't work. I really don't have a clue what's going wrong.

Edit: Tried the code in a new project and it worked just fine. Any ideas how this can happen? :-(
Last edited on
Possibly your project was missing a setting to include the folder that had wincon.h
Topic archived. No new replies allowed.