include stdafx include windowsx include AtlConv необходимо для преобра

  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
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#include "stdafx.h"
#include <windowsx.h>
#include <AtlConv.h> // необходимо для преобразования типов
#include <conio.h>
int Pro(HWND hwnd, int x[], int y[])//проверка на треугольник
{
if((x[0]==x[1])&&(x[0]==x[2]) || (y[0]==y[1])&&(y[0]==y[2]))
return 0;
else return 1;
}
int Proverko(HWND hwnd,int x[],int y[])//проверка на пределы экрана
{
RECT r;
GetClientRect (hwnd, &r);
if((x[0]>r.left) && (x[1]>r.left) && (x[2]>r.left) && (x[0]<r.right) && (x[1]<r.right) &&(x[2]<r.right)
&& (y[0]>r.top) && (y[1]>r.top) && (y[2]>r.top) && (y[0]<r.bottom) && (y[1]<r.bottom) && (y[2]<r.bottom))
return 0;
else return 1;
}
void Na_vloz(HDC hdc,int x[],int y[]) //проверка вложенности двух фигур
{
int a=0;
COLORREF rgb = GetPixel (hdc, x[0], y[0]);
if (GetRValue(rgb)==0 && GetGValue(rgb)==0 && GetBValue(rgb)==0)
{
a++;
}
rgb = GetPixel (hdc, x[1], y[1]);
if (GetRValue(rgb)==0 && GetGValue(rgb)==0 && GetBValue(rgb)==0)
{
a++;
}
rgb = GetPixel (hdc, x[2], y[2]);
if (GetRValue(rgb)==0 && GetGValue(rgb)==0 && GetBValue(rgb)==0)
{
a++;
}
if(a==0) printf(" !!!Figuri vlozeni!!! \n");
else printf(" !!!Figuri ne vlozeni!!! \n");
}
int clrcls(HDC hdc)
{
HBRUSH hBrush;
hBrush = CreateSolidBrush(RGB(0,0,0));
HBRUSH hOldBrush = SelectBrush(hdc, hBrush);
Rectangle(hdc, 640, 300, 0, 0);
SelectBrush(hdc, hOldBrush);
DeleteBrush(hBrush);
return 0;
}
void Zakras(FILE *f,HDC hdc,HWND hwnd)//закрашенная фигура
{
int x[3],y[3];
HPEN hRedPen = CreatePen(PS_SOLID, 3, RGB(255, 0, 0));
HPEN hOldPen = SelectPen (hdc, hRedPen);
HBRUSH hGreenBrush = CreateSolidBrush (RGB(0, 10, 200));
HBRUSH hOldBrush = SelectBrush (hdc, hGreenBrush);
fscanf(f,"%d %d %d %d %d %d", &x[0], &y[0], &x[1], &y[1], &x[2], &y[2]);
POINT ppt[3]={ {x[0],y[0]}, {x[1],y[1]}, {x[2],y[2]} } ;
Polygon (hdc, ppt, 3);
SelectPen (hdc, hOldPen);
SelectBrush (hdc, hOldBrush);
DeletePen (hRedPen);
DeleteBrush (hGreenBrush);
fclose(f);
if(Pro(hwnd,x,y)==0) printf(" figura ne treougolnik\n");
else printf("figura treugolnik\n");
if(Proverko(hwnd,x,y)==0) printf(" figura lezit v predelah okna\n");
else printf(" figura ne lezit v predelah okna\n");
}
void neZakras(FILE *f, HDC hdc,HWND hwnd)//незакрашенная фигура
{
int x1[3],y1[3];
HPEN hWhitePen = CreatePen(PS_SOLID, 3, RGB(0, 0, 0));
HPEN hOldPen = SelectPen (hdc, hWhitePen);
HBRUSH hGrBrush = CreateSolidBrush (RGB(255, 255, 255));
HBRUSH hOldBrush = SelectBrush (hdc, hGrBrush);
fscanf(f,"%d %d %d %d %d %d", &x1[0], &y1[0], &x1[1], &y1[1], &x1[2], &y1[2]);
POINT ppt[3]={ {x1[0],y1[0]}, {x1[1],y1[1]}, {x1[2],y1[2]} } ;
Polygon (hdc, ppt, 3);
SelectPen (hdc, hOldPen);
SelectBrush (hdc, hOldBrush);
DeletePen (hWhitePen);
DeleteBrush (hGrBrush);
fclose(f);
if(Pro(hwnd,x1,y1)==0) printf(" figura ne treougolnik\n");
else printf("figura treugolnik\n");
if(Proverko(hwnd,x1,y1)==0) printf(" figura lezit v predelah okna\n");
else printf(" figura ne lezit v predelah okna\n");
}
void dve_figuri(FILE *f,HDC hdc,HWND hwnd)//вложенные фигуры
{
int x[3],y[3],x1[3],y1[3];
fscanf(f,"%d %d %d %d %d %d", &x[0],&y[0],&x[1],&y[1],&x[2],&y[2]);
fscanf(f,"%d %d %d %d %d %d", &x1[0],&y1[0],&x1[1],&y1[1],&x1[2],&y1[2]);
HPEN hYellowPen = CreatePen(PS_SOLID, 3, RGB(0, 255, 10));
HPEN hOldPen = SelectPen (hdc,hYellowPen);
HBRUSH hBbBrush = CreateSolidBrush (RGB(50, 200, 0));
HBRUSH hOldBrush = SelectBrush (hdc, hBbBrush);
POINT ppt[3]={ {x[0],y[0]}, {x[1],y[1]}, {x[2],y[2]} } ;
Polygon (hdc, ppt, 3);
SelectPen (hdc, hOldPen);
SelectBrush (hdc, hOldBrush);
DeletePen (hYellowPen);
DeleteBrush (hBbBrush);
if(Pro(hwnd,x,y)==0) printf("pervaya figura ne treougolnik\n");
else printf("pervaya figura treugolnik\n");
if(Proverko(hwnd,x,y)==0) printf(" pervaya figura lezit v predelah okna\n");
else printf("pervaya figura ne lezit v predelah okna\n");
Na_vloz(hdc,x1,y1);
HPEN hYellPen = CreatePen(PS_SOLID, 3, RGB(255, 90, 100));
HPEN hOlddPen = SelectPen (hdc,hYellPen);
HBRUSH hBoxBrush = CreateSolidBrush (RGB(255, 0, 255));
HBRUSH hOlddBrush = SelectBrush (hdc, hBoxBrush);
POINT pp[3]={ {x1[0],y1[0]}, {x1[1],y1[1]}, {x1[2],y1[2]} } ;
Polygon (hdc, pp, 3);
SelectPen (hdc, hOlddPen);
SelectBrush (hdc, hOlddBrush);
DeletePen (hYellPen);
DeleteBrush (hBoxBrush);
if(Pro(hwnd,x1,y1)==0) printf(" vtoraya figura ne treougolnik\n");
else printf("vtoraya figura treugolnik\n");
if(Proverko(hwnd,x1,y1)==0) printf(" vtoraya figura lezit v predelah okna\n");
else printf("vtoraya figura ne lezit v predelah okna\n");
fclose(f);
}
void _tmain ( )
{
int i,j,x[3],y[3],x1[3],y1[3];
FILE *fp,*f;
USES_CONVERSION;
HWND hwnd = FindWindow (A2W("ConsoleWindowClass"), NULL);
HDC hdc = GetDC (hwnd);
if(hdc)
{
RECT rt;
GetClientRect (hwnd, &rt);
char buf[100];
sprintf(buf, "Размер окна %d на %d пикселов", rt.right, rt.bottom);
SetBkColor (hdc, RGB(0, 0, 0));
SetTextColor (hdc, RGB(255,50, 255));
int exit=0;
while(exit == 0)
{
printf("1 - zakrashennaya figura\n");
printf("2 - ne zakrashennaya\n");
printf("3 - dve figuri\n");
printf("4 - quit\n");
switch(getche())
{
case '1':
{
system("cls");
fp=fopen("lll.txt","r");
TextOut (hdc, 250, 20, A2W(buf), strlen(buf));
Zakras(fp,hdc,hwnd);
getch();
clrcls(hdc);
}break;
case '2':
{
system("cls");
fp=fopen("lll2.txt","r");
TextOut (hdc, 250, 20, A2W(buf), strlen(buf));
neZakras(fp,hdc,hwnd);
getch();
clrcls(hdc);
}break;
case '3':
{
system("cls");
fp=fopen("lll3.txt","r");
TextOut (hdc, 250, 20, A2W(buf), strlen(buf));
dve_figuri(fp,hdc,hwnd);
getch();
clrcls(hdc);
}break;
case '4':exit = 1; break;
}
system("cls");
}
ReleaseDC (hwnd, hdc);
}
}