#include <Windows.h>
#define MAXHEIGHT 25
void HideCurs(HANDLE hStdout, int cursor)
{
COORD wCoord = {0, cursor};
DWORD num;
FillConsoleOutputAttribute(hStdout,
FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED,
80, wCoord, &num);
}
void MoveCurs(HANDLE hStdout, int *cursor, int delta)
{
COORD wCoord = {0, *cursor};
int num;
if (delta) {
HideCurs(hStdout, *cursor);
(*cursor) += delta;
wCoord.Y += delta;
}
FillConsoleOutputAttribute(hStdout,
BACKGROUND_BLUE | BACKGROUND_GREEN, 80, wCoord, &num);
}
void main()
{
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
INPUT_RECORD buffer;
int currCursor = 0, pressExit = 0, length = 10;
DWORD eventsRead, Mode;
CONSOLE_CURSOR_INFO cInfo = {25, 0};
COORD size = {80, MAXHEIGHT};
SMALL_RECT sizew = {0, 0, 79, MAXHEIGHT -1};
SetConsoleCursorInfo(hStdout, &cInfo);
SetConsoleScreenBufferSize(hStdout, size);
SetConsoleWindowInfo(hStdout, 1, &sizew);
GetConsoleMode(hStdin, &Mode);
if ((Mode&ENABLE_MOUSE_INPUT) != ENABLE_MOUSE_INPUT)
SetConsoleMode(hStdin, Mode | ENABLE_MOUSE_INPUT);
if (length) MoveCurs(hStdout, &currCursor, 0);
do {
ReadConsoleInput (hStdin, (PINPUT_RECORD) &buffer,
1, &eventsRead);
if (!eventsRead) continue;
switch (buffer.EventType) {
int y;
case MOUSE_EVENT:
if (!length) break;
y = buffer.Event.MouseEvent.dwMousePosition.Y;
switch (buffer.Event.MouseEvent.dwButtonState)
{
case FROM_LEFT_1ST_BUTTON_PRESSED :
if (y < length)
MoveCurs (hStdout, &currCursor,
y - currCursor);
break;
}
break;
case KEY_EVENT:
if (!buffer.Event.KeyEvent.bKeyDown) break;
switch (buffer.Event.KeyEvent.wVirtualKeyCode)
{
int k;
case VK_ESCAPE:
pressExit = 1;
break;
case VK_UP:
if (!length ||
!buffer.Event.KeyEvent.bKeyDown)
break;
if (!currCursor) k = length - 1;
else k = -1;
MoveCurs (hStdout, &currCursor, k);
break;
case VK_DOWN:
if (!length ||
!buffer.Event.KeyEvent.bKeyDown)
break;
if (currCursor + 1 == length)
k = - length + 1;
else k = 1;
MoveCurs(hStdout, &currCursor, k);
break;
}
break;
}
}while (!pressExit);
}
Организация меню
Код:
#include <Windows.h>
#define MAXHEIGHT 25
void HideCurs(HANDLE hStdout, int cursor)
{
COORD wCoord = (0, cursor); /* Тут ошибка */
int num;
FillConsoleOutputAttribute(hStdout,
FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED,
80, wCoord, &num);/* Тут ошибка &num*/
}
void MoveCurs(HANDLE hStdout, int *cursor, int delta)
{
COORD wCoord = (0, *cursor);/* Тут ошибка */
int num;
if (delta) {
HideCurs(hStdout, *cursor);
(*cursor) += delta;
wCoord.Y += delta;
}
FillConsoleOutputAttribute(hStdout,
BACKGROUND_BLUE | BACKGROUND_GREEN, 80, wCoord, &num);/* Тут ошибка &num */
}
void main()
{
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
INPUT_RECORD buffer;
int currCursor = 0, pressExit = 0, length = 10;
DWORD eventsRead, Mode;
CONSOLE_CURSOR_INFO cInfo = {25, 0};
COORD size = {80, MAXHEIGHT};
SMALL_RECT sizew = {0, 0, 79, MAXHEIGHT -1};
SetConsoleCursorInfo(hStdout, &cInfo);
SetConsoleScreenBufferSize(hStdout, size);
SetConsoleWindowInfo(hStdout, 1, &sizew);
GetConsoleMode(hStdin, &Mode);
if ((Mode&ENABLE_MOUSE_INPUT) != ENABLE_MOUSE_INPUT)
SetConsoleMode(hStdin, Mode | ENABLE_MOUSE_INPUT);
if (length) MoveCurs(hStdout, &currCursor, 0);
do {
ReadConsoleInput (hStdin, (PINPUT_RECORD) &buffer,
1, &eventsRead);
if (!eventsRead) continue;
switch (buffer.EventType) {
int y;
case MOUSE_EVENT:
if (!length) break;
y = buffer.Event.MouseEvent.dwMousePosition.Y;
switch (buffer.Event.MouseEvent.dwButtonState)
{
case FROM_LEFT_1ST_BUTTON_PRESSED :
if (y < length)
MoveCurs (hStdout, &currCursor,
y - currCursor);
break;
}
break;
case KEY_EVENT:
if (!buffer.Event.KeyEvent.bKeyDown) break;
switch (buffer.Event.KeyEvent.wVirtualKeyCode)
{
int k;
case VK_ESCAPE:
pressExit = 1;
break;
case VK_UP:
if (!length ||
!buffer.Event.KeyEvent.bKeyDown)
break;
if (!currCursor) k = length - 1;
else k = -1;
MoveCurs (hStdout, &currCursor, k);
break;
case VK_DOWN:
if (!length ||
!buffer.Event.KeyEvent.bKeyDown)
break;
if (currCursor + 1 == length)
k = - length + 1;
else k = 1;
MoveCurs(hStdout, &currCursor, k);
break;
}
break;
}
}while (!pressExit);
}
#define MAXHEIGHT 25
void HideCurs(HANDLE hStdout, int cursor)
{
COORD wCoord = (0, cursor); /* Тут ошибка */
int num;
FillConsoleOutputAttribute(hStdout,
FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED,
80, wCoord, &num);/* Тут ошибка &num*/
}
void MoveCurs(HANDLE hStdout, int *cursor, int delta)
{
COORD wCoord = (0, *cursor);/* Тут ошибка */
int num;
if (delta) {
HideCurs(hStdout, *cursor);
(*cursor) += delta;
wCoord.Y += delta;
}
FillConsoleOutputAttribute(hStdout,
BACKGROUND_BLUE | BACKGROUND_GREEN, 80, wCoord, &num);/* Тут ошибка &num */
}
void main()
{
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
INPUT_RECORD buffer;
int currCursor = 0, pressExit = 0, length = 10;
DWORD eventsRead, Mode;
CONSOLE_CURSOR_INFO cInfo = {25, 0};
COORD size = {80, MAXHEIGHT};
SMALL_RECT sizew = {0, 0, 79, MAXHEIGHT -1};
SetConsoleCursorInfo(hStdout, &cInfo);
SetConsoleScreenBufferSize(hStdout, size);
SetConsoleWindowInfo(hStdout, 1, &sizew);
GetConsoleMode(hStdin, &Mode);
if ((Mode&ENABLE_MOUSE_INPUT) != ENABLE_MOUSE_INPUT)
SetConsoleMode(hStdin, Mode | ENABLE_MOUSE_INPUT);
if (length) MoveCurs(hStdout, &currCursor, 0);
do {
ReadConsoleInput (hStdin, (PINPUT_RECORD) &buffer,
1, &eventsRead);
if (!eventsRead) continue;
switch (buffer.EventType) {
int y;
case MOUSE_EVENT:
if (!length) break;
y = buffer.Event.MouseEvent.dwMousePosition.Y;
switch (buffer.Event.MouseEvent.dwButtonState)
{
case FROM_LEFT_1ST_BUTTON_PRESSED :
if (y < length)
MoveCurs (hStdout, &currCursor,
y - currCursor);
break;
}
break;
case KEY_EVENT:
if (!buffer.Event.KeyEvent.bKeyDown) break;
switch (buffer.Event.KeyEvent.wVirtualKeyCode)
{
int k;
case VK_ESCAPE:
pressExit = 1;
break;
case VK_UP:
if (!length ||
!buffer.Event.KeyEvent.bKeyDown)
break;
if (!currCursor) k = length - 1;
else k = -1;
MoveCurs (hStdout, &currCursor, k);
break;
case VK_DOWN:
if (!length ||
!buffer.Event.KeyEvent.bKeyDown)
break;
if (currCursor + 1 == length)
k = - length + 1;
else k = 1;
MoveCurs(hStdout, &currCursor, k);
break;
}
break;
}
}while (!pressExit);
}
><
COORD wCoord = {0, cursor};
FillConsoleOutputAttribute(hStdout,
BACKGROUND_BLUE | BACKGROUND_GREEN, 80, wCoord, &num);/* Тут ошибка &num */
q(>_<)p
DWORD a;
FillConsoleOutputAttribute(hStdout,
BACKGROUND_BLUE | BACKGROUND_GREEN, 80, wCoord, &a);
Первая
Код:
Код:
#include <stdio.h>
#include <conio.h>
typedef struct SStudent {
char name[50];
enum {one, two, thre, four, faiv} srocenka;
int vozrast;
double ves;
} TStudent;
char *srname[5] = {"Одиница ", "Двойка ", "Тройка ", "Четверка ", "Петёрка"};
void show(TStudent *Student, int num)
{
int i;
if (!num){
puts("\a База пустая!");
return;
}
for (i = 0; i < num; i++) {
printf("Студент - %s, Средняя оценка = %s\n",
Student[i].name,
srname[Student[i].srocenka]);
printf("\tВозраст %d, вес %lg кг\n",
Student[i].vozrast,
Student[i].ves);
}
}
void add(TStudent *Student, int *num)
{
int i, tch;
if (*num == 20){
puts("\aБаза заполнина!");
return;
}
printf("Имя: ");
gets(Student[*num].name);
printf("Средняя оценка (");
for (i = 0; i < 5; i++)
printf("%d - %s",i,srname[i]);
printf("\b): ");
do {
putchar('\b');
tch = getche();
} while (tch < '0' || tch >'4');
putchar('\n');
Student[*num].srocenka = tch -'0';
printf("Возраст: ");
scanf("%d",&Student[*num].vozrast);
printf("Вес: ");
scanf("%lg%*c",&Student[*num].ves);
(*num)++;
}
void main()
{
TStudent Student[50];
int num = 0, ch;
do {
puts("1. Посматреть базу");
puts("2. Добавить студента");
puts("0. Завершить работу");
do {
putchar('\b');
ch = getche();
} while (ch < '0' || ch > '2');
putchar('\n');
switch (ch - '0') {
case 1:
show(Student,num);
break;
case 2:
add(Student,&num);
}
}while (ch - '0');
}
#include <conio.h>
typedef struct SStudent {
char name[50];
enum {one, two, thre, four, faiv} srocenka;
int vozrast;
double ves;
} TStudent;
char *srname[5] = {"Одиница ", "Двойка ", "Тройка ", "Четверка ", "Петёрка"};
void show(TStudent *Student, int num)
{
int i;
if (!num){
puts("\a База пустая!");
return;
}
for (i = 0; i < num; i++) {
printf("Студент - %s, Средняя оценка = %s\n",
Student[i].name,
srname[Student[i].srocenka]);
printf("\tВозраст %d, вес %lg кг\n",
Student[i].vozrast,
Student[i].ves);
}
}
void add(TStudent *Student, int *num)
{
int i, tch;
if (*num == 20){
puts("\aБаза заполнина!");
return;
}
printf("Имя: ");
gets(Student[*num].name);
printf("Средняя оценка (");
for (i = 0; i < 5; i++)
printf("%d - %s",i,srname[i]);
printf("\b): ");
do {
putchar('\b');
tch = getche();
} while (tch < '0' || tch >'4');
putchar('\n');
Student[*num].srocenka = tch -'0';
printf("Возраст: ");
scanf("%d",&Student[*num].vozrast);
printf("Вес: ");
scanf("%lg%*c",&Student[*num].ves);
(*num)++;
}
void main()
{
TStudent Student[50];
int num = 0, ch;
do {
puts("1. Посматреть базу");
puts("2. Добавить студента");
puts("0. Завершить работу");
do {
putchar('\b');
ch = getche();
} while (ch < '0' || ch > '2');
putchar('\n');
switch (ch - '0') {
case 1:
show(Student,num);
break;
case 2:
add(Student,&num);
}
}while (ch - '0');
}