3
I’m trying to create a function called criar_botao()
that prints a rectangle on the screen, with the library windows.h
is printing the rectangle but not the size I want. I’m trying to pass the parameters, with the position x
and y
where the rectangle will be created, and the width and height of the rectangle.
I have this code. If anyone can help me:
void desenha_botao(int altura,int largura, int x, int y,const int cor) {
COORD posicao = { x, y };
CHAR_INFO *tela_buffer = calloc(largura * altura, sizeof(CHAR_INFO));
COORD tamanho_grid = { largura, altura };
COORD zero_zero = { 0, 0 };
SMALL_RECT retangulo = { altura, posicao.X, posicao.X + (largura - 1), posicao.Y + (altura - 1) };
HANDLE h_output = GetStdHandle(STD_OUTPUT_HANDLE);
int i, j;
for (j = 0; j < tamanho_grid.Y; j++) {
for (i = 0; i < tamanho_grid.X; i++) {
tela_buffer[i + j * largura].Char.AsciiChar = '\xDB';
tela_buffer[i + j * largura].Attributes = FOREGROUND_GREEN;
}
}
WriteConsoleOutput(h_output, tela_buffer, tamanho_grid, zero_zero, &retangulo);
}