Paint Multiple Rectangles

Hi guys, my objective is paint diferent rectangles i have this file:

rectangle.cpp:

#include <stdio.h>
#include <windows.h>

HBRUSH hBrsh;

void SelecionaCor(int cor)
{
switch (cor)
{
case 1:hBrsh = CreateSolidBrush(0x800000);break;
case 2:hBrsh = CreateSolidBrush(0x00ff00);break;
case 3:hBrsh = CreateSolidBrush(0xff0000);break;
case 4:hBrsh = CreateSolidBrush(0x000000);break;
}
}

void CriaRectangulo(int left,int right, int top, int bottom, int cor)
{
RECT rect;

HWND console = GetConsoleWindow();
HDC dc = GetDC(console);

rect.left=left;
rect.right=top;
rect.top=right;
rect.bottom=bottom;

SelecionaCor(cor);

FillRect(dc,&rect,hBrsh);

ReleaseDC(console, dc);
DeleteDC(dc);
}

And then i have this to create a new rectangle:

for (int i=18; i >= 0 ; i--)
{
for (int j=1; j < 19 ; j++)
{
if (exemploSala[i][j] == 1)
cor=1;
else if(exemploSala[i][j] == 2)
cor=2;
else
cor=4;

CriaRectangulo(left,right,top,bottom,cor);
left+=1;
right+=1;
}
printf("\n");
}

The problem is, when i run the code i see the diferent colors but it paint all rectangles with the same color, and after it run all the code it will appear just one color in all rectangles.

What is the best way to paint them with diferent colors?

I have another question, what i need to do for the rectangles don't disapear when i minimize the window?

Thanks,

Daniel Gomes
Last edited on
I just solved the 1st question, now i see the rectangles with multiple colors.
But the other question i can't solve, why it disapears when i minimize or scroll down?
You should draw at WM_PAINT message on your window procedure
Topic archived. No new replies allowed.