creating rectangles with array of structures.

Hi all,
I have been struggling with a program and any help would be appreciated. I'm working with C++ in visual studios using the win32 api. I am trying to create an array of structures for a rectangle and when the program runs it needs to create 5 rectangles on the screen. I am able to create the one, but not sure how to get 5 created in different locations using the structure. Here is the code:


#include <windows.h>
#include <math.h>

const wchar_t g_szClassName[] = L"myWindowClass";


struct Die
{
static int value;
static int colorOfForeground;
static int colorOfBackground;
static double centerx;
static double centery;
static int Size;
};

void applyScale(double r[],double s)
{
for(int i=0;i<4;i++)
{
r[i]=r[i]*s;
}
}

void shift(double x[],double y[],double cx,double cy)
{
for(int i=0;i<4;i++)
{
x[i]+=cx;
y[i]+=cy;
}
}

void setup(double x[],double y[])
{
x[0]=20.0;
y[0]=20.0;

x[1]=-20.0;
y[1]=20.0;

x[2]=-20.0;
y[2]=-20.0;

x[3]=20.0;
y[3]=-20.0;

}

// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HDC hDC;
PAINTSTRUCT Ps;
HBRUSH hBrush;
RECT rect;

Die rectangle[4]; //An array of 4 Rectangles in the Die structure.

static bool isEllipse=true;
static int red =128;
static int blue =128;
static int green = 128;
static int x=50;
static int y=50;

double xx[4];
double yy[4];
double rr[4];
double aa[4];

static double scale=1.0;
double cx = 100.0;
double cy = 100.0;


bool bTemp;

switch(msg)
{
case WM_PAINT:
hDC=BeginPaint(hwnd,&Ps);
hBrush = CreateSolidBrush(RGB(red, green, blue));

setup(xx,yy);
applyScale(rr,scale);
shift(xx,yy,cx,cy);

SelectObject(hDC, hBrush);
Rectangle(hDC, x, y, 350+x, 150+y);

DeleteObject(hBrush);
EndPaint(hwnd,&Ps);
break;

break;
case WM_CHAR:

if(wParam=='c')
{
red=rand()%256;
green=rand()%256;
blue=rand()%256;
InvalidateRect(hwnd,NULL,true);
}

break;
case WM_KEYDOWN:
if(wParam==VK_NEXT)
{
scale=scale*0.99;
InvalidateRect(hwnd,NULL,true);
}
if(wParam==VK_PRIOR)
{
scale=scale*1.01;
InvalidateRect(hwnd,NULL,true);
}
if(wParam==VK_UP)
{
cy-=1;
InvalidateRect(hwnd,NULL,true);
}
if(wParam==VK_DOWN)
{
cy+=1;
InvalidateRect(hwnd,NULL,true);
}
if(wParam==VK_LEFT)
{
cx-=1;
InvalidateRect(hwnd,NULL,true);
}
if(wParam==VK_RIGHT)
{
cx+=1;
InvalidateRect(hwnd,NULL,true);
}
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;

//Step 1: Registering the Window Class
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

if(!RegisterClassEx(&wc))
{
MessageBox(NULL, L"Window Registration Failed!", L"Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}

// Step 2: Creating the Window
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
L"Garrett Genova",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 800, 600,
NULL, NULL, hInstance, NULL);

if(hwnd == NULL)
{
MessageBox(NULL, L"Window Creation Failed!", L"Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}

ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);

// Step 3: The Message Loop
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
Topic archived. No new replies allowed.