Advertisement
huutho_96

snack_senza_v1

Nov 15th, 2016
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.34 KB | None | 0 0
  1. //Page: https://www.facebook.com/CungHocLapTrinhUIT
  2.  
  3.  
  4.  
  5. #include <iostream> // thư viên của c++
  6. #include <conio.h>  // dùng lệnh getch(), dừng màn hình lại
  7. #include <Windows.h>// các hàm định nghĩa bên dưới cần thư viện của hệ thống để tô màu, di trỏ....
  8.  
  9.  
  10. using namespace std;// trong iostream có rất nhiều thứ trùng tên cho nên họ phân ra theo vùng. vùng mà mình dùng thường xuyên là std
  11.  
  12.  
  13. //hàm di chuyển con trỏ trên màn hình console đến vị trí có tọa độ (x, y). Lưu ý toạn độ trong màn hình console vẫn là Oxy nhưng Oy hướng xuống
  14. void gotoxy(short x, short y)
  15. {
  16.     HANDLE hConsoleOutput;
  17.     COORD Cursor_an_Pos = { x, y };
  18.     hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
  19.     SetConsoleCursorPosition(hConsoleOutput, Cursor_an_Pos);
  20. }
  21.  
  22.  
  23. //Thay đổi màu chữ trên màn hình console
  24. void SetTextColor(WORD color)
  25. {
  26.     HANDLE hConsoleOutput;
  27.     hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
  28.  
  29.     CONSOLE_SCREEN_BUFFER_INFO screen_buffer_info;
  30.     GetConsoleScreenBufferInfo(hConsoleOutput, &screen_buffer_info);
  31.  
  32.     WORD wAttributes = screen_buffer_info.wAttributes;
  33.     color &= 0x000f;
  34.     wAttributes &= 0xfff0;
  35.     wAttributes |= color;
  36.  
  37.     SetConsoleTextAttribute(hConsoleOutput, wAttributes);
  38. }
  39.  
  40.  
  41. //Thay đổi màu nển. Để thay đổi có hiệu lực các bạn nên dùng lệnh xóa màn hình. system("cls");
  42. void SetBGColor(WORD color)
  43. {
  44.     HANDLE hConsoleOutput;
  45.     hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
  46.  
  47.     CONSOLE_SCREEN_BUFFER_INFO screen_buffer_info;
  48.     GetConsoleScreenBufferInfo(hConsoleOutput, &screen_buffer_info);
  49.  
  50.     WORD wAttributes = screen_buffer_info.wAttributes;
  51.     color &= 0x000f;
  52.     color <<= 4;
  53.     wAttributes &= 0xff0f;
  54.     wAttributes |= color;
  55.  
  56.     SetConsoleTextAttribute(hConsoleOutput, wAttributes);
  57. }
  58.  
  59.  
  60. //1 vấn đề các bạn hay gặp phải là kích thước màn hình console trên mỗi mãy tính đều có thể khác nhau
  61. //dẫn đến trên máy bạn nhìn cân đối nhưng sang máy khác thì nhìn nó bị lệch hoặc đơn giản bạn muốn thay đổi kích thước
  62. //màn hình console thì hay dùng hàm dưới đây.
  63. void SetWindowSize(int Width, int Height)
  64. {
  65.     _COORD coord;
  66.     coord.X = Width;
  67.     coord.Y = Height;
  68.  
  69.     _SMALL_RECT Rect;
  70.     Rect.Top = 0;
  71.     Rect.Left = 0;
  72.     Rect.Bottom = Height - 1;
  73.     Rect.Right = Width - 1;
  74.  
  75.     HANDLE Handle = GetStdHandle(STD_OUTPUT_HANDLE);
  76.     if (Handle == NULL)
  77.     {
  78.         cout << "Failure in getting the handle\n" << GetLastError();
  79.     }
  80.  
  81.     if (!SetConsoleScreenBufferSize(Handle, coord))
  82.     {
  83.         cout << "Failure in setting buffer size\n" << GetLastError();
  84.     }
  85.  
  86.     if (!SetConsoleWindowInfo(Handle, TRUE, &Rect))
  87.     {
  88.         cout << "Failure in setting window size\n" << GetLastError();
  89.     }
  90. }
  91.  
  92.  
  93. //Hàm này thì do mình nghịch nghịch tìm ra.
  94. //Nó sẽ giúp các bạn vẽ 1 khung hình chữ nhật nhanh chóng
  95. // Khi gọi nó bạn lần lượt truyền vào a b là tọa độ góc trên bên trái và c d là góc dưới bên phải
  96. // *Note là chuỗi sẽ hiển thị bên trong khung. Lưu ý a và c các bạn nên để chênh lệch ít nhất 4 đơn vị
  97. void DrawRectangle(int a, int b, int c, int d)
  98. {
  99.     int i;
  100.     for (i = a; i <= c; i++)
  101.     {
  102.         gotoxy(i, b);          printf("\xcd");
  103.         gotoxy(i, d);          printf("\xcd");
  104.     }
  105.     for (i = b; i <= d; i++)
  106.     {
  107.         gotoxy(a, i);          printf("\xba");
  108.         gotoxy(c, i);          printf("\xba");
  109.     }
  110.     gotoxy(a, b);          printf("\xc9");
  111.     gotoxy(a, d);          printf("\xc8");
  112.     gotoxy(c, b);          printf("\xbb");
  113.     gotoxy(c, d);          printf("\xbc");
  114. }
  115.  
  116.  
  117. //Các bạn có thể tham khảo thêm 2 code là tạo menu và nhập mật khẩu ở link dưới
  118. //https://drive.google.com/open?id=0B-phxZomSa4rflNFTjM1cEZ4ZE5UY2pDU3Jabjc3MldvZlFLMmliekpNUDhJckIzano4OUU
  119.  
  120.  
  121. void main()
  122. {
  123.     SetWindowSize(80, 25);          // cài đặt màn hình kích thước 80 ô ngang và 25 ô dọc
  124.     SetBGColor(15);                 //set màu nền là trắng. mã màu là từ 0 đến 15
  125.     system("cls");                  //set màu nền thì xóa màn hình cho có hiệu lực
  126.     SetTextColor(13);               //màu hường nè em
  127.     DrawRectangle(0, 1, 79, 24);    //Vẽ cho anh 1 màn hình bao quanh
  128.     gotoxy(1, 1);                   //di con trỏ tới tọa độ (1, 1)
  129.  
  130.     //snack senza
  131.     bool done = false;
  132.     while (!done){
  133.  
  134.     }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement