没用的C++程序

打印 上一主题 下一主题

主题 708|帖子 708|积分 2124

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
一个没啥大用的程序
  1. #include <bits/stdc++.h>
  2. #include <cstdio>
  3. #include <windows.h>
  4. #include <cstdlib>
  5. #include <conio.h>
  6. #include <iostream>
  7. #include <cstring>
  8. #include <ctime>
  9. #include <fstream>
  10. #define S(i) Sleep(i)
  11. #define cls system("cls");
  12. #define ei else if
  13. using namespace std;
  14. bool agreedshutdown = false; //判断是否关闭
  15. //项目名称
  16. long long recentnum = 15, projectnum = 15, settingnum = 3;
  17. string recentfilename[1010100]  = {};
  18. string projectfilename[1010100] = {};
  19. string settingfilename[1010100] = {" ", "声音", "亮度", "关于"};
  20. //--------
  21. HWND hwnd = GetConsoleWindow();
  22. /*
  23. HANDLE HOUT = GetStdHandle(STD_OUTPUT_HANDLE);    //获得控制台句柄
  24. COORD NewSize = GetLargestConsoleWindowSize(HOUT);//获得控制台最大坐标,坐标以字符数为单位
  25. NewSize.X -= 1;
  26. NewSize.Y -= 1;    //可以不加,不加时显示滚动条
  27. SetConsoleScreenBufferSize(HOUT, NewSize); //设置控制台缓冲区大小
  28. SMALL_RECT DisplayArea={0,0,0,0};
  29. DisplayArea.Right = NewSize.X;
  30. DisplayArea.Bottom = NewSize.Y;
  31. SetConsoleWindowInfo(HOUT, TRUE, &DisplayArea);    //设置控制台大小
  32. //控制台已经最大化,但是初始位置不在屏幕左上角,添加如下代码
  33. HWND hwnd = GetConsoleWindow();
  34. ShowWindow(hwnd, SW_MAXIMIZE);    //窗体最大化
  35. */
  36. void SetColorAndBackground(int ForgC, int BackC) {//单个字的颜色
  37. //1深蓝,2深绿,3深青,4深红,5深紫,6深黄,7灰白(默认),8深灰
  38. //9浅蓝,10浅绿,11浅青,12浅红,13浅紫,14浅黄,15白色,0黑色
  39.         WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);
  40.         SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
  41. }
  42. void gotoxy(long long x, long long y) {
  43.         COORD pos;
  44.         pos.X = 2 * x;
  45.         pos.Y = y;
  46.         SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
  47. }
  48. struct CMDset {
  49.         void setfont(int size) {//字体、大小、粗细
  50.                 CONSOLE_FONT_INFOEX cfi;
  51.                 cfi.cbSize = sizeof cfi;
  52.                 cfi.nFont = 0;
  53.                 cfi.dwFontSize.X = 0;
  54.                 cfi.dwFontSize.Y = size;//设置字体大小
  55.                 cfi.FontFamily = FF_DONTCARE;
  56.                 cfi.FontWeight = FW_NORMAL;//字体粗细 FW_BOLD,原始为FW_NORMAL
  57.                 wcscpy_s(cfi.FaceName, L"Minecraft AE");//设置字体,必须是控制台已有的
  58.                 SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi);
  59.                 HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
  60.                 CONSOLE_FONT_INFO consoleCurrentFont;
  61.                 GetCurrentConsoleFont(handle, FALSE, &consoleCurrentFont);
  62.         }
  63. } cmdset;
  64. struct Start {
  65.         struct Fileinput { /*注入文件名*/
  66.                 void recentfileinput() {
  67.                         CreateDirectory("./files",NULL );
  68.                         ifstream recent("./files/recent.whstu");
  69.                         if (!recent.is_open()) {
  70.                                 ofstream recent_create("./files/recent.whstu");//如果文件不存在就创建文件
  71.                                 recent_create.close();
  72.                         }
  73.                         string line;
  74.                         recentfilename[0] = {" "};
  75.                         long long i = 1;
  76.                         while (getline(recent, line)) {
  77.                                 recentfilename[i] = line;
  78.                                 i++;
  79.                         }
  80.                         recentnum = i - 1;
  81.                 }
  82.                 void projectfileinput() {
  83.                         CreateDirectory("./files",NULL );
  84.                         ifstream project("./files/project.whstu");
  85.                         if (!project.is_open()) {
  86.                                 ofstream project_create("./files/project.whstu");//如果文件不存在就创建文件
  87.                                 project_create.close();
  88.                         }
  89.                         string line;
  90.                         projectfilename[0] = {" "};
  91.                         long long i = 1;
  92.                         while (getline(project, line)) {
  93.                                 projectfilename[i] = line;
  94.                                 i++;
  95.                         }
  96.                         projectnum = i - 1;
  97.                 }
  98.         } fileinput;
  99.         void powerOn() {
  100.                 ShowWindow(hwnd, SW_MAXIMIZE);
  101.                 cmdset.setfont(30);
  102.                 cout << "\n  ";
  103.                 SetColorAndBackground(4, 12);
  104.                 cout << "W";
  105.                 SetColorAndBackground(6, 14);
  106.                 cout << "H";
  107.                 SetColorAndBackground(2, 10);
  108.                 cout << "S";
  109.                 SetColorAndBackground(1, 9);
  110.                 cout << "T";
  111.                 SetColorAndBackground(13, 5);
  112.                 cout << "U";
  113.                 SetColorAndBackground(0, 0);
  114.                 cout << " ";
  115.                 SetColorAndBackground(15, 8);
  116.                 cout << "Studio";
  117.                 SetColorAndBackground(7, 0);
  118.                 S(5000);
  119.                 cls
  120.                 gotoxy(13, 10);
  121.                 cout << "S";
  122.                 Sleep(1000);
  123.                 cout << "\b\bS  ";
  124.                 S(100);
  125.                 cout << "\b\b\b\bS  ";
  126.                 S(100);
  127.                 cout << "\b\b\b\bS  ";
  128.                 S(100);
  129.                 cout << "\b\b\b\bS  ";
  130.                 S(100);
  131.                 cout << "\b\b\b\bS  ";
  132.                 S(100);
  133.                 cout << "\b\b\b\bS \b";
  134.                 S(100);
  135.                 cout << "l";
  136.                 S(100);
  137.                 cout << "y";
  138.                 S(100);
  139.                 cout << "t";
  140.                 S(100);
  141.                 cout << "h";
  142.                 S(100);
  143.                 cout << "e";
  144.                 S(100);
  145.                 cout << "r";
  146.                 S(100);
  147.                 cout << "i";
  148.                 S(100);
  149.                 cout << "n";
  150.                 S(100);
  151.                 cout << "  O";
  152.                 S(100);
  153.                 cout << "S";
  154.                 S(4000);
  155.                 system("cls");
  156.                 cmdset.setfont(16);
  157.                 return;
  158.         }
  159.         void Lock(string pass) {
  160.                 while (true) {
  161.                         cout << "请输入密码:";
  162.                         string in;
  163.                         cin >> in;
  164.                         if (in == pass) {
  165.                                 return;
  166.                         } else {
  167.                                 cout << "再试一次";
  168.                                 Sleep(1000);
  169.                                 system("cls");
  170.                         }
  171.                 }
  172.         }
  173.         void prepareStart() {
  174.                 cout << "\n正在准备Slytherin OS";
  175.                 S(500);
  176.                 system("ipconfig /flushdns");
  177.                 S(100);
  178.                 system("ipconfig");
  179.                 S(100);
  180.                 cls
  181.                 cout << "正在导入文件...";
  182.                 fileinput.projectfileinput();
  183.                 fileinput.recentfileinput();
  184.                 cout << "\n完成。\n";
  185.                 S(100);
  186.                 cout << "欢迎...";
  187.         }
  188. } start;
  189. //apps
  190. struct Filemanager { /*文件管理*/
  191.         void createfile(string name) {
  192.                 return;
  193.         }
  194.         void deletefile(string name) {
  195.                 return;
  196.         }
  197.         void fileinfo(string name) {
  198.                 return;
  199.         }
  200.         void editfile(string name) {
  201.                 return;
  202.         }
  203. } filemanager;
  204. struct Setting {
  205.         void voice() {
  206.                 return;
  207.         }
  208.         void light() {
  209.                 return;
  210.         }
  211.         void about() {
  212.                 //初始化
  213.                 gotoxy(0, 3);
  214.                 SetColorAndBackground(7, 0);
  215.                 for (int i = 0; i < 15; i++) {
  216.                         cout << "                              \n";
  217.                 }
  218.                 gotoxy(0, 3);
  219.                 //--------
  220.                 cout << "\nPowered by\n\n ";
  221.                 S(1000);
  222.                 SetColorAndBackground(4, 12);
  223.                 cout << " W ";
  224.                 SetColorAndBackground(6, 14);
  225.                 cout << " H ";
  226.                 SetColorAndBackground(2, 10);
  227.                 cout << " S ";
  228.                 SetColorAndBackground(1, 9);
  229.                 cout << " T ";
  230.                 SetColorAndBackground(13, 5);
  231.                 cout << " U ";
  232.                 SetColorAndBackground(0, 0);
  233.                 cout << "   ";
  234.                 SetColorAndBackground(15, 8);
  235.                 cout << " S t u d i o ";
  236.                 SetColorAndBackground(7, 0);
  237.                 S(3000);
  238.                 cout << "\n";
  239.                 //写入版本号
  240.                 CreateDirectory("./info",NULL );
  241.                 ofstream info("./info/info.txt");
  242.                 info<<"Slytherin OS 0.2_Build20240807152900_DeveloperBeta3"<<endl;
  243.                 info<<"版本代号:000217"<<endl;
  244.                 info<<"注意:请不要在此处留下重要信息,因为此文件会被SlytherinOS覆盖!";
  245.                 info.close();
  246.                 //----------
  247.                 cout << "\nSlytherin OS 0.2_Build20240807152900_DeveloperBeta3\n";
  248.                 cout << "\n版本代号000217\n";
  249.                 cout << "\nSlytherin OS\n";
  250.                 cout << "\n按b返回";
  251.                 while (1) {
  252.                         if ( _kbhit() ) {
  253.                                 char x = _getch();
  254.                                 switch (x) {
  255.                                         case 'b': {
  256.                                                 //setting板块初始化
  257.                                                 gotoxy(0, 3);
  258.                                                 SetColorAndBackground(7, 0);
  259.                                                 for (int i = 0; i < 15; i++) {
  260.                                                         cout << "                                                                \n";
  261.                                                 }
  262.                                                 gotoxy(0, 3);
  263.                                                 SetColorAndBackground(0, 7);
  264.                                                 cout << settingfilename[1] << endl;
  265.                                                 SetColorAndBackground(7, 0);
  266.                                                 for (int i = 2; i <= settingnum; i++) {
  267.                                                         cout << settingfilename[i] << endl;
  268.                                                 }
  269.                                                 gotoxy(0, 3);
  270.                                                 //---------------
  271.                                                 return;
  272.                                         }
  273.                                 }
  274.                         }
  275.                 }
  276.         }
  277. } com_whstu_setting;
  278. struct Launcher {
  279.         void title() {
  280.                 gotoxy(0, 0);
  281.                 cout << "Slytherin OS    ";
  282.                 time_t now = time(0);
  283.                 tm* localTime = localtime(&now);
  284.                 char timeString[100];
  285.                 strftime(timeString, sizeof(timeString), "%Y-%m-%d %H:%M", localTime);
  286.                 cout << timeString;
  287.                 return;
  288.         }
  289.         void home() { /*主页*/
  290.                 //初始化
  291.                 gotoxy(0, 3);
  292.                 SetColorAndBackground(7, 0);
  293.                 for (int i = 0; i < 15; i++) {
  294.                         cout << "                              \n";
  295.                 }
  296.                 //------
  297.                 gotoxy(2, 5);
  298.                 cout << "Slytherin OS 0";
  299.                 while (1) {
  300.                         if ( _kbhit() ) {
  301.                                 char x = _getch();
  302.                                 switch (x) {
  303.                                         case 'b': {
  304.                                                 return;
  305.                                         }
  306.                                         case 'a': {
  307.                                                 return;
  308.                                         }
  309.                                         case 'd': {
  310.                                                 return;
  311.                                         }
  312.                                         case 'w': {
  313.                                                 return;
  314.                                         }
  315.                                         case 's': {
  316.                                                 return;
  317.                                         }
  318.                                 }
  319.                         }
  320.                 }
  321.                 return;
  322.         }
  323.         void recent() { /*最近*/
  324.                 //初始化
  325.                 gotoxy(0, 3);
  326.                 SetColorAndBackground(7, 0);
  327.                 for (int i = 0; i < projectnum + 3; i++) {
  328.                         cout << "                              \n";
  329.                 }
  330.                 gotoxy(0, 3);
  331.                 SetColorAndBackground(0, 7);
  332.                 cout << recentfilename[1] << endl;
  333.                 SetColorAndBackground(7, 0);
  334.                 for (int i = 2; i <= recentnum; i++) {
  335.                         cout << recentfilename[i] << endl;
  336.                 }
  337.                 int file = 1;
  338.                 //---------------
  339.                 while (1) {
  340.                         if ( _kbhit() ) {
  341.                                 char x = _getch();
  342.                                 switch (x) {
  343.                                         case ' ': {
  344.                                                 /*运行*/
  345.                                                 break;
  346.                                         }
  347.                                         case 'a': {
  348.                                                 return;
  349.                                         }
  350.                                         case 'd': {
  351.                                                 return;
  352.                                         }
  353.                                         case 's': {
  354.                                                 if (file < recentnum) {
  355.                                                         gotoxy(0, 2 + file);
  356.                                                         SetColorAndBackground(7, 0);
  357.                                                         cout << recentfilename[file];
  358.                                                         file++;
  359.                                                         gotoxy(0, 2 + file);
  360.                                                         SetColorAndBackground(0, 7);
  361.                                                         cout << recentfilename[file];
  362.                                                 }
  363.                                                 break;
  364.                                         }
  365.                                         case 'w' : {
  366.                                                 if (file > 1) {
  367.                                                         gotoxy(0, 2 + file);
  368.                                                         SetColorAndBackground(7, 0);
  369.                                                         cout << recentfilename[file];
  370.                                                         file--;
  371.                                                         gotoxy(0, 2 + file);
  372.                                                         SetColorAndBackground(0, 7);
  373.                                                         cout << recentfilename[file];
  374.                                                 }
  375.                                                 break;
  376.                                         }
  377.                                         case 'b': {
  378.                                                 return;
  379.                                         }
  380.                                 }
  381.                         }
  382.                 }
  383.                 return;
  384.         }
  385.         void project() {/*文件*/
  386.                 //初始化
  387.                 gotoxy(0, 3);
  388.                 SetColorAndBackground(7, 0);
  389.                 for (int i = 0; i < max(recentnum, settingnum) + 3; i++) {
  390.                         cout << "                              \n";
  391.                 }
  392.                 gotoxy(0, 3);
  393.                 SetColorAndBackground(0, 7);
  394.                 cout << projectfilename[1] << endl;
  395.                 SetColorAndBackground(7, 0);
  396.                 for (int i = 2; i <= projectnum; i++) {
  397.                         cout << projectfilename[i] << endl;
  398.                 }
  399.                 int file = 1;
  400.                 //---------------
  401.                 while (1) {
  402.                         if ( _kbhit() ) {
  403.                                 char x = _getch();
  404.                                 switch (x) {
  405.                                         case ' ': {
  406.                                                 /*运行*/
  407.                                                 break;
  408.                                         }
  409.                                         case 'a': {
  410.                                                 return;
  411.                                         }
  412.                                         case 'd': {
  413.                                                 return;
  414.                                         }
  415.                                         case 'b': {
  416.                                                 return;
  417.                                         }
  418.                                         case 's': {
  419.                                                 if (file < projectnum) {
  420.                                                         gotoxy(0, 2 + file);
  421.                                                         SetColorAndBackground(7, 0);
  422.                                                         cout << projectfilename[file];
  423.                                                         file++;
  424.                                                         gotoxy(0, 2 + file);
  425.                                                         SetColorAndBackground(0, 7);
  426.                                                         cout << projectfilename[file];
  427.                                                 }
  428.                                                 break;
  429.                                         }
  430.                                         case 'w' : {
  431.                                                 if (file > 1) {
  432.                                                         gotoxy(0, 2 + file);
  433.                                                         SetColorAndBackground(7, 0);
  434.                                                         cout << projectfilename[file];
  435.                                                         file--;
  436.                                                         gotoxy(0, 2 + file);
  437.                                                         SetColorAndBackground(0, 7);
  438.                                                         cout << projectfilename[file];
  439.                                                 }
  440.                                                 break;
  441.                                         }
  442.                                 }
  443.                         }
  444.                 }
  445.                 return;
  446.         }
  447.         void settings() {/*设置*/
  448.                 //初始化
  449.                 gotoxy(0, 3);
  450.                 SetColorAndBackground(7, 0);
  451.                 for (int i = 0; i < projectnum + 3; i++) {
  452.                         cout << "                              \n";
  453.                 }
  454.                 gotoxy(0, 3);
  455.                 SetColorAndBackground(0, 7);
  456.                 cout << settingfilename[1] << endl;
  457.                 SetColorAndBackground(7, 0);
  458.                 for (int i = 2; i <= settingnum; i++) {
  459.                         cout << settingfilename[i] << endl;
  460.                 }
  461.                 int file = 1;
  462.                 //---------------
  463.                 while (1) {
  464.                         if ( _kbhit() ) {
  465.                                 char x = _getch();
  466.                                 switch (x) {
  467.                                         case ' ': {
  468.                                                 switch (file) {
  469.                                                         case 3: {
  470.                                                                 com_whstu_setting.about();
  471.                                                                 break;
  472.                                                         }
  473.                                                 }
  474.                                                 break;
  475.                                         }
  476.                                         case 'a': {
  477.                                                 return;
  478.                                         }
  479.                                         case 'd': {
  480.                                                 return;
  481.                                         }
  482.                                         case 'b': {
  483.                                                 return;
  484.                                         }
  485.                                         case 's': {
  486.                                                 if (file < settingnum) {
  487.                                                         gotoxy(0, 2 + file);
  488.                                                         SetColorAndBackground(7, 0);
  489.                                                         cout << settingfilename[file];
  490.                                                         file++;
  491.                                                         gotoxy(0, 2 + file);
  492.                                                         SetColorAndBackground(0, 7);
  493.                                                         cout << settingfilename[file];
  494.                                                 }
  495.                                                 break;
  496.                                         }
  497.                                         case 'w' : {
  498.                                                 if (file > 1) {
  499.                                                         gotoxy(0, 2 + file);
  500.                                                         SetColorAndBackground(7, 0);
  501.                                                         cout << settingfilename[file];
  502.                                                         file--;
  503.                                                         gotoxy(0, 2 + file);
  504.                                                         SetColorAndBackground(0, 7);
  505.                                                         cout << settingfilename[file];
  506.                                                 }
  507.                                                 break;
  508.                                         }
  509.                                 }
  510.                         }
  511.                 }
  512.                 return;
  513.         }
  514.         void head() { /*标签栏*/
  515.                 //初始化
  516.                 title();
  517.                 gotoxy(0, 2);
  518.                 SetColorAndBackground(7, 0);
  519.                 cout << "                                                    ";
  520.                 gotoxy(0, 2);
  521.                 cout << "  |";
  522.                 SetColorAndBackground(0, 7);
  523.                 cout << "  主页  ";
  524.                 SetColorAndBackground(7, 0);
  525.                 cout << " |  最近  |  文件  |  设置  |";
  526.                 home();
  527.                 int channel = 1;
  528.                 //---------------
  529.                 while (1) {
  530.                         if ( _kbhit() ) {
  531.                                 char x = _getch();
  532.                                 switch (x) {
  533.                                         case 'a' : {
  534.                                                 if (channel > 1) {
  535.                                                         channel--;
  536.                                                 }
  537.                                                 break;
  538.                                         }
  539.                                         case 'd': {
  540.                                                 if (channel < 4) {
  541.                                                         channel++;
  542.                                                 }
  543.                                                 break;
  544.                                         }
  545.                                         case 'b': {
  546.                                                 return;
  547.                                         }
  548.                                 }
  549.                                 if (channel == 1) {
  550.                                         gotoxy(0, 2);
  551.                                         SetColorAndBackground(7, 0);
  552.                                         cout << "                                                    ";
  553.                                         gotoxy(0, 2);
  554.                                         cout << "  |";
  555.                                         SetColorAndBackground(0, 7);
  556.                                         cout << "  主页  ";
  557.                                         SetColorAndBackground(7, 0);
  558.                                         cout << " |  最近  |  文件  |  设置  |";
  559.                                         home();
  560.                                 }
  561.                                 if (channel == 2) {
  562.                                         gotoxy(0, 2);
  563.                                         SetColorAndBackground(7, 0);
  564.                                         cout << "                                                    ";
  565.                                         gotoxy(0, 2);
  566.                                         cout << "  |  主页  |";
  567.                                         SetColorAndBackground(0, 7);
  568.                                         cout << "  最近  ";
  569.                                         SetColorAndBackground(7, 0);
  570.                                         cout << " |  文件  |  设置  |";
  571.                                         recent();
  572.                                 }
  573.                                 if (channel == 3) {
  574.                                         gotoxy(0, 2);
  575.                                         SetColorAndBackground(7, 0);
  576.                                         cout << "                                                    ";
  577.                                         gotoxy(0, 2);
  578.                                         cout << "  |  主页  |  最近  |";
  579.                                         SetColorAndBackground(0, 7);
  580.                                         cout << "  文件  ";
  581.                                         SetColorAndBackground(7, 0);
  582.                                         cout << " |  设置  |";
  583.                                         project();
  584.                                 }
  585.                                 if (channel == 4) {
  586.                                         gotoxy(0, 2);
  587.                                         SetColorAndBackground(7, 0);
  588.                                         cout << "                                                    ";
  589.                                         gotoxy(0, 2);
  590.                                         cout << "  |  主页  |  最近  |  文件  |";
  591.                                         SetColorAndBackground(0, 7);
  592.                                         cout << "  设置  ";
  593.                                         SetColorAndBackground(7, 0);
  594.                                         cout << " |";
  595.                                         settings();
  596.                                 }
  597.                         }
  598.                 }
  599.         }
  600. } launcher;
  601. void shutdownagreement() {//关闭提示
  602.         cls
  603.         cout << "确实要关闭吗?(y/n)";
  604.         while (1) {
  605.                 if ( _kbhit() ) {
  606.                         char x = _getch();
  607.                         switch (x) {
  608.                                 case 'y': {
  609.                                         agreedshutdown = true;
  610.                                         return;
  611.                                 }
  612.                                 case 'n': {
  613.                                         agreedshutdown = false;
  614.                                         return;
  615.                                 }
  616.                         }
  617.                 }
  618.         }
  619. }
  620. int main() {
  621.         start.powerOn();
  622.         cls
  623.         start.Lock("123456");
  624.         cls
  625.         S(10);
  626.         cout << "欢迎...";
  627.         start.prepareStart();
  628.         S(500);
  629.         cls
  630.         while (agreedshutdown == false) {
  631.                 ShowWindow(hwnd, SW_MAXIMIZE);
  632.                 cmdset.setfont(16);
  633.                 launcher.head();
  634.                 shutdownagreement();
  635.         }
  636.         return 0;
  637. }
  638. /*
  639. Slytherin OS 版本0.2
  640. 最后更新:20240807
  641. 更新日志
  642. 20240807
  643. 修复了取消退出后无法控制UI的问题;增加了项目名称读取程序
  644. 20240805
  645. UI编写
  646. */
复制代码


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

梦应逍遥

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表