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
#include "stdafx.h"
#include <windowsx.h>
#include <AtlConv.h> // необходимо для преобразования типов
#include <conio.h>
void Zakras(FILE *f,HDC hdc,HWND hwnd)
{
int x[3],y[3],x1[3],y1[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);
}
void neZakras(FILE *f, HDC hdc,HWND hwnd)
{
int x[3],y[3],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);
Pro(hwnd, x1,y1);
}
void Pro(HWND hwnd, int x[], int y[])
{
if((x[0]==x[1])&&(x[0]==x[2]) || (y[0]==y[1])&&(y[0]==y[2]))
printf("odna iz figur ne treougolnik\n");
else printf("treugolnik");
}
void Proverko(HWND hwnd,int x[],int y[], int x1[], int y1[])
{
RECT r;
GetClientRect (hwnd, &r);
if((x[0]<0) && (x[1]<0) && (x[2]<0) && (y[0]<0) && (y[1]<0) && (y[2]<0))
printf(" zakrashennaya figura ne zadana\n");
else 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))
printf(" zakrashennaya figura lejit v predelah okna\n");
else printf(" zakrashennaya figura vyhodit za predely okna!\n");
if((x1[0]<0) && (x1[1]<0) && (x1[2]<0) && (y1[0]<0) && (y1[1]<0) && (y1[2]<0))
printf(" nezakrashennaya figura ne zadana\n");
else if((x1[0]>r.left) && (x1[1]>r.left) && (x1[2]>r.left) && (x1[0]<r.right) && (x1[1]<r.right) &&(x1[2]<r.right)
&& (y1[0]>r.top) && (y1[1]>r.top) && (y1[2]>r.top) && (y1[0]<r.bottom) && (y1[1]<r.bottom) && (y1[2]<r.bottom))
printf(" nezakrashennaya figura lejit v predelah okna\n");
else printf(" nezakrashennaya figura vyhodit za predely okna!\n");
}
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));
printf("1 - zakrashennaya figura\n");
printf("2 - ne zakrashennaya\n");
printf("3 - proverka na predel ekrana\n");
printf("4 - proverka na vlozenost\n");
printf("5 - quit\n");
scanf("%d", &j);
while(j<5)
{
switch(j)
{
case 1:
{
fp=fopen("lll.txt","r");
TextOut (hdc, 250, 20, A2W(buf), strlen(buf));
Zakras(fp,hdc,hwnd);
}break;
case 2:
{
fp=fopen("lll2.txt","r");
TextOut (hdc, 250, 20, A2W(buf), strlen(buf));
neZakras(fp,hdc,hwnd);
}break;
case 3:
{
Proverko(hwnd, x,y,x1,y1);
}break;
case 4:
{
if((x[0]==x[1])&&(x[0]==x[2]) || (y[0]==y[1])&&(y[0]==y[2]) || (x1[0]==x1[1])&&(x1[0]==x1[2]) || (y1[0]==y1[1])&&(y1[0]==y1[2]))
printf("odna iz figur ne treougolnik\n");
COLORREF rgb=GetBkColor(hdc);
while((rgb!=GetPixel(hdc,x[i],y[i]) && i<3) || (rgb!=GetPixel(hdc,x1[i],y1[i]))) i=i+1;
if (i==3) printf("vlozeni\n");
else printf("NET\n");
}break;
}
scanf("%d", &j);
}
printf("Press any key\n");
_getch( );
ReleaseDC (hwnd, hdc);
}
}