Advertisement
MateuszGgG

Zad 10 rev 0

Jan 16th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.35 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #include <stdlib.h>
  4.  
  5. #include <math.h>
  6.  
  7. #include <conio.h>
  8.  
  9. #include <windows.h>
  10.  
  11. #pragma warning (disable:4996)
  12.  
  13. char info[] = "Zakończyć można przez naciśnięcie klawiszy v lub w\n"
  14.  
  15. "lub podwójnym naciśnięciem myszy\r\n";
  16.  
  17. char str[2] = { ' ', '\0' };
  18.  
  19. char tytul[] = "Konsola utworzona przez Krzysztof Kusmierczyk I54";
  20.  
  21. char buf[128];
  22.  
  23. HANDLE hinp, hout;
  24.  
  25. COORD YX;
  26.  
  27. INPUT_RECORD zapis;
  28.  
  29. int nzdarz = 0;
  30.  
  31. int rbuf, rfakt, rout, lengbuf;
  32.  
  33. unsigned short kolory[15] = { 0xAC, 0x12, 0x65, 0x87, 0x4C, 0x6A, 0xCA, 0xDE, 0x25, 0xE8, 0xFC, 0x4F, 0x6B, 0xB3, 0x2B };
  34.  
  35. unsigned short kolor2 = 0xF9;
  36.  
  37. int atryb = 0xF9;
  38.  
  39. int main(void)
  40.  
  41. {
  42.  
  43. FreeConsole();
  44.  
  45. AllocConsole();
  46.  
  47. CharToOemA(tytul, tytul);
  48.  
  49. SetConsoleTitleA(tytul);
  50.  
  51. hout = GetStdHandle(STD_OUTPUT_HANDLE);
  52.  
  53. hinp = GetStdHandle(STD_INPUT_HANDLE);
  54.  
  55. YX = GetLargestConsoleWindowSize(hout);
  56.  
  57. rbuf = YX.X * YX.Y;
  58.  
  59. YX.X = 0;
  60.  
  61. YX.Y = 0;
  62.  
  63. FillConsoleOutputAttribute(hout, kolor2, rbuf, YX, &rfakt);
  64.  
  65. SetConsoleTextAttribute(hout, kolory[0]);
  66.  
  67. CharToOemA(info, buf);
  68.  
  69. lengbuf = (int)strlen(buf);
  70.  
  71. WriteConsoleA(hout, buf, lengbuf, &rfakt, NULL);
  72.  
  73. YX.X = 0;
  74.  
  75. YX.Y = 20;
  76.  
  77. FILE* fp;
  78.  
  79. fp = fopen("015.txt", "r");
  80.  
  81. int numerKoloru = 0;
  82.  
  83. while (fgets(buf, 255, (FILE*)fp)) {
  84.  
  85. AnsiToOem(buf, buf);
  86.  
  87. lengbuf = (int)strlen(buf);
  88.  
  89. SetConsoleTextAttribute(hout, kolory[numerKoloru++]);
  90.  
  91. WriteConsoleA(hout, buf, lengbuf, &rfakt, NULL);
  92.  
  93. }
  94.  
  95. fclose(fp);
  96.  
  97. powt:
  98.  
  99. FlushConsoleInputBuffer(hinp);
  100.  
  101. ReadConsoleInputA(hinp, &zapis, 1, &nzdarz);
  102.  
  103. if (zapis.EventType == MOUSE_EVENT) {
  104.  
  105. goto mysz;
  106.  
  107. }
  108.  
  109. if (zapis.EventType == KEY_EVENT) {
  110.  
  111. goto klaw;
  112.  
  113. }
  114.  
  115. goto powt;
  116.  
  117. mysz:
  118.  
  119. if (zapis.Event.MouseEvent.dwEventFlags & DOUBLE_CLICK && zapis.Event.KeyEvent.wVirtualKeyCode == LEFT_CTRL_PRESSED) {
  120.  
  121. goto kon;
  122.  
  123. }
  124.  
  125. YX = zapis.Event.MouseEvent.dwMousePosition;
  126.  
  127. SetConsoleCursorPosition(hout, YX);
  128.  
  129. goto powt;
  130.  
  131. klaw:
  132.  
  133. if (zapis.Event.KeyEvent.bKeyDown == 0) {
  134.  
  135. goto powt;
  136.  
  137. }
  138.  
  139. str[0] = zapis.Event.KeyEvent.uChar.AsciiChar;
  140.  
  141. if (str[0] == 'W' || str[0] == 'w') {
  142.  
  143. goto kon;
  144.  
  145. }
  146.  
  147. str[0] = zapis.Event.KeyEvent.uChar.AsciiChar;
  148.  
  149. if (str[0] == 'V' || str[0] == 'v') {
  150.  
  151. goto kon;
  152.  
  153. }
  154.  
  155. WriteConsoleOutputCharacterA(hout, str, 1, YX, &rout);
  156.  
  157. goto powt;
  158.  
  159. kon:
  160.  
  161. FreeConsole();
  162.  
  163. ExitProcess(0);
  164.  
  165. return 0;
  166.  
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement