Winapi, Переключение Между Фигурами, Исправить Ошибку

  • Автор темы BenderRR
  • Дата начала
B

BenderRR

Гость
#1
всем доброго времени суток! работа с фигурами: перемещение, создание, переключение между ними и т.д. Вот как раз переключение (фокус) и не работает.
код:
C++:
class myRectangle
{
public:
int X1,Y1,X2,Y2;
int numbRect;
int color;
HDC hdc;
HWND hWnd;
int focus;
HBRUSH Brushes[6];
HPEN Pens[2];
myRectangle ()
{
X1=150;
Y1=300;
X2=250;
Y2=400;
numbRect=-1;
color=0;
focus=-1;
Brushes[0]=CreateSolidBrush(RGB(255,0,0));
Brushes[1]=CreateSolidBrush(RGB(0,255,0));
Brushes[2]=CreateSolidBrush(RGB(0,0,255));
Brushes[3]=CreateSolidBrush(RGB(255,0,102));
Brushes[4]=CreateSolidBrush(RGB(255,255,0));
Brushes[5]=CreateSolidBrush(RGB(255,255,255));
Pens[0]  =CreatePen(0,1,RGB(255,255,255));
Pens[1]  =CreatePen(0,7,RGB(0,0,0));
}
void MoveRight(myRectangle& mf)
{
mf.X1+=10;
mf.X2+=10;
InvalidateRect(hWnd, NULL, TRUE);
}
int CreateRect(myRectangle& mf, int n)
{
if((n+1)<numb)
{
n++;
InvalidateRect(hWnd, NULL, TRUE);	  
}
return n;
}
};
C++:
LRESULT CALLBACK FiguresWndProc(HWND hWnd, UINT Message,UINT wParam,LONG lParam )
{
static HBRUSH Brushes[6];
static HPEN Pens[2];
Brushes[0]=CreateSolidBrush(RGB(255,0,0));
Brushes[1]=CreateSolidBrush(RGB(0,255,0));
Brushes[2]=CreateSolidBrush(RGB(0,0,255));
Brushes[3]=CreateSolidBrush(RGB(255,0,102));
Brushes[4]=CreateSolidBrush(RGB(255,255,0));
Brushes[5]=CreateSolidBrush(RGB(255,255,255));
Pens[0]  =CreatePen(0,1,RGB(255,255,255));
Pens[1]  =CreatePen(0,7,RGB(0,0,0));

static myRectangle rect[numb];
static int numR=rect[0].numbRect; //кол-во квадратов
static myEllipse ellps[numb];
static int numE=ellps[0].numbEllps; //кол-во эллипсов
static int countFocus=-1; //кол-во фигур
static int nowFocus=-1; //сейчас в фокусе

static int i=0;
HDC hdc;
RECT Rect;
PAINTSTRUCT PaintStruct;

switch(Message)
{
case WM_PAINT:
GetClientRect(hWnd,&Rect);
hdc=BeginPaint(hWnd,&PaintStruct);

for (i=0; i<=numR; i++) 
{
if (nowFocus==rect[i].focus)
{
SelectObject(hdc,Brushes[rect[i].color]);
SelectObject(hdc,Pens[1]);
Rectangle(hdc,rect[i].X1,rect[i].Y1,rect[i].X2,rect[i].Y2);
DeleteObject(Pens[1]);
DeleteObject(Brushes[rect[i].color]);						  
}
else 
{
SelectObject(hdc,Brushes[rect[i].color]);
SelectObject(hdc,Pens[0]);
Rectangle(hdc,rect[i].X1,rect[i].Y1,rect[i].X2,rect[i].Y2);
DeleteObject(Pens[0]);
DeleteObject(Brushes[rect[i].color]);
}
}
for (i=0; i<=numE; i++) 
{
if (nowFocus==ellps[i].focus)
{
SelectObject(hdc,Brushes[ellps[i].color]);
SelectObject(hdc,Pens[1]);
Ellipse(hdc,ellps[i].X1,ellps[i].Y1,ellps[i].X2,ellps[i].Y2);
DeleteObject(Pens[1]);
DeleteObject(Brushes[ellps[i].color]);
}
else
{
SelectObject(hdc,Brushes[ellps[i].color]);
SelectObject(hdc,Pens[0]);
Ellipse(hdc,ellps[i].X1,ellps[i].Y1,ellps[i].X2,ellps[i].Y2);
DeleteObject(Pens[0]);
DeleteObject(Brushes[ellps[i].color]);
}
}

DeleteDC(hdc);
EndPaint(hWnd,&PaintStruct);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;	  
case WM_KEYDOWN:
switch (wParam) {
case VK_RIGHT:
for (i=0; i<=numR; i++)
if (nowFocus==rect[i].focus) 
{
rect[0].MoveRight(rect[numR]);
}
for (i=0; i<=numE; i++)
if (nowFocus==ellps[i].focus) 
{
ellps[0].MoveRight(ellps[numE]);
}
break;
case VK_1:
numR=rect[0].CreateRect(rect[numR],numR);
rect[numR].focus=++countFocus;
nowFocus=countFocus;
break;
case VK_2:
numE=ellps[0].CreateEllps(ellps[numE],numE);
ellps[numE].focus=++countFocus;
nowFocus=countFocus;
break;
case VK_TAB:
if(countFocus!=-1)
{
if(countFocus==nowFocus) nowFocus=0;
else nowFocus++;
InvalidateRect(hWnd, NULL, TRUE);
}
break;
}				  
}  
return DefWindowProc(hWnd,Message,wParam,lParam);
}