-------------------- -------------------- -------------------- -- Defa

  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
// --------------------------------------------------------------
// DefaultHeader.h
// --------------------------------------------------------------
#ifndef __DEFAULT_HEADER_H
#define __DEFAULT_HEADER_H
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#define WINVER 0x0502
#ifdef _INCLUDE_WIN
# define WIN32_LEAN_AND_MEAN
# include <Windows.h>
#else
typedef unsigned char BOOL;
#endif
typedef unsigned char bool;
#define TRUE 1
#define true 1
#define FALSE 0
#define false 0
#define out(x) printf("%i\n",(x))
#define outS(x,y) printf("%s %i\n",(x),(y))
#endif
// --------------------------------------------------------------
// Programm.c
// --------------------------------------------------------------
#define _INCLUDE_WIN
#include "DefaultHeader.h"
// .GetLastError verbose function
static CHAR lpBuffer[256];
PCHAR VerboseError()
{
PCHAR ptr = (PCHAR)lpBuffer;
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), lpBuffer, 240, NULL);
while (ptr < lpBuffer + 250 && *ptr != '\n' && *ptr != '\r')
ptr++;
*ptr = 0;
return lpBuffer;
}
// .GDI
HWND activeWindow = NULL;
HDC activeDC = NULL;
RECT activeBoundaries;
#define BLAC RGB(0x00,0x00,0x00)
#define WHITE RGB(0xFF,0xFF,0xFF)
#define GREY RGB(0x40,0x40,0x40)
#define RED RGB(0xFF,0x00,0x00)
#define GREEN RGB(0x00,0xFF,0x00)
#define BLUE RGB(0x00,0x00,0xFF)
void DrawBoundaries(COLORREF xAxisColor, COLORREF yAxisColor, COLORREF backgColor)
{
static POINT pt, *ppt = &pt;
static PRECT prct = &activeBoundaries;
// Move caret to the bottom
system("mode con: lines=40 cols=120 | color 07 | chcp 1251");
for (int i = 0; i < 40; i++)
putchar('\n');
printf("] ");
// Obtain current HDC object
if (!activeDC)
{
activeWindow = GetConsoleWindow();
activeDC = GetDC(activeWindow);
GetClientRect(activeWindow, prct);
prct->bottom -= 14;
}
// Init palette and tools
SetBkColor(activeDC, backgColor);
HBRUSH backgroundBrush = CreateSolidBrush(backgColor);
HPEN horzPen = CreatePen(PS_DASHDOTDOT, 1, yAxisColor);
HPEN vertPen = CreatePen(PS_DASHDOT, 1, xAxisColor);
HPEN borderPen = CreatePen(PS_NULL, 0, 0);
// Paint background
SelectObject(activeDC, backgroundBrush);
SelectObject(activeDC, borderPen);
Rectangle(activeDC, prct->left, prct->top, prct->right+1, prct->bottom);
// Draw axis
SelectObject(activeDC, horzPen);
MoveToEx(activeDC, 0, prct->bottom / 2, ppt);
LineTo(activeDC, prct->right, prct->bottom / 2);
SelectObject(activeDC, vertPen);
MoveToEx(activeDC, prct->right / 2, 0, ppt);
LineTo(activeDC, prct->right / 2, prct->bottom);
// Release tools
DeleteObject(backgroundBrush);
DeleteObject(borderPen);
DeleteObject(horzPen);
DeleteObject(vertPen);
}
// .Program
void Print(char * str, int msec)
{
while (putchar(*str) && *str++) Sleep(msec);
}
void Clear(int count, int msec)
{
while (count-- && printf("\b \b")) Sleep(msec);
}
DWORD WINAPI ExitThreadCallback(LPVOID lpThreadParameter)
{
_getch();
exit(0);
}
// .main
int main()
{
DrawBoundaries(RED, GREEN, GREY);
POINT triangle[3] = { { 100, 300 }, { 300, 400 }, { 200, 100 } };
DeleteObject(SelectObject(activeDC, CreatePen(PS_DOT, 1, GREEN | RED)));
DeleteObject(SelectObject(activeDC, CreateHatchBrush(HS_DIAGCROSS, BLUE)));
Ellipse(activeDC, 50, 40, 200, 300);
DeleteObject(SelectObject(activeDC, CreateHatchBrush(HS_CROSS, RGB(150,100,150))));
Polygon(activeDC, &triangle, 3);
char * poesy[14] = {
"Зима!.. Крестьянин, торжествуя,",
"На дровнях обновляет путь;",
"Его лошадка, снег почуя,",
"Плетется рысью как - нибудь;",
"Бразды пушистые взрывая,",
"Летит кибитка удалая;",
"Ямщик сидит на облучке",
"В тулупе, в красном кушаке.",
"Вот бегает дворовый мальчик,",
"В салазки жучку посадив,",
"Себя в коня преобразив;",
"Шалун уж отморозил пальчик:",
"Ему и больно и смешно,",
"А мать грозит ему в окно."
};
int poesy_num = 14;
HANDLE exitThread = CreateThread(NULL, 0, ExitThreadCallback, NULL, 0, NULL);
for (int i = 0; i < poesy_num; i++)
{
Print(poesy[i], 30);
Sleep(1000);
Clear(strlen(poesy[i])+1, 0);
}
Print("Такие вот дела, пацанчик.", 40);
WaitForSingleObject(exitThread, INFINITE);
ReleaseDC(activeWindow,activeDC);
DeleteDC(activeDC);
return 0;
}