任务管理器——让你的任务更好的完成 助力中考

任务管理器程序 源代码

注意

这不是在说Windows自带的任务管理器,走错片场的请自行跳转。

百度搜索

百度百科

下载相关

点我

绪言

妈妈给了本关于拖延症的书,叫《别让拖延症毁了你》,我看到标题就觉得这本书适合我(因为我觉得自己太拖延了!)

里面有许多关于拖延症的原因,道理,逻辑方面的知识,也有许多小故事,每个故事都对应这一种类型的拖延症表现(当然也有正面的)

其中就有个措施是“合理的制定计划”,我想,在这神奇的编程下,制定计划应该会很容易吧,就设想了几个比较不错的功能

但是我到网上一搜,得到的代码都无法满足我的要求(虽然我的标准也不是恒定不变的,但我觉得我可以写出让我满意的代码)

于是我就开始动手了……

 

//尽管写代码也浪费了好几天,但我觉得这也是值得的吧……

介绍

互动方式

本着简洁,快速,方便,功能齐全的想法

先要考虑的就是选择合适的用户和程序之间的交流,传输数据方式。

之前不是写了连点器的代码嘛,就在想,可以检测鼠标是否点击控制台内,鼠标的位置,控制台的位置这三个数据,就可以知道鼠标点在了哪里。

  1 #include<iostream>
  2 #include<algorithm>
  3 #include<cstdio>
  4 #include<cstring>
  5 #include<cmath>
  6 #include<map>
  7 #include<set>
  8 #include<queue>
  9 #include<vector>
 10 #include<fstream>
 11 #include<windows.h>
 12 #include<stdlib.h>
 13 #include<ctime> 
 14 #include<conio.h>
 15 #define IL inline
 16 #define re register
 17 using namespace std;
 18 
 19 POINT curpos;//鼠标的位置
 20 
 21 //window
 22 RECT rect; 
 23 HWND hwnd;
 24 //mouse
 25 HANDLE ConsoleWin=GetStdHandle(STD_INPUT_HANDLE);
 26 INPUT_RECORD eventMsg;
 27 DWORD Pointer;
 28 
 29 struct eve{
 30     string name;
 31     int stime,ftime,rtime;
 32     string dec;
 33     eve(){
 34         stime=ftime=rtime=0;
 35         dec="无描述.快点完成吧!";
 36     }
 37 };
 38 vector<eve>his;
 39 
 40 bool hiscmp(eve a,eve b){
 41     if(a.stime==b.stime) return a.ftime<b.ftime;
 42     return a.stime<b.stime;
 43 }
 44 
 45 void read();
 46 void save();
 47 int choose(string,string,string,string);
 48 void _return();
 49 
 50 void init(){
 51     system("cls");
 52     his.clear();
 53     read();
 54 }
 55 
 56 int lx,ly;
 57 
 58 IL void goxy(int x,int y)
 59 {
 60     HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
 61     COORD coordScreen = {0, 0}; //光标位置
 62     CONSOLE_SCREEN_BUFFER_INFO csbi;
 63     GetConsoleScreenBufferInfo(hConsole, &csbi);
 64     lx=csbi.dwCursorPosition.X,ly=csbi.dwCursorPosition.Y;
 65     
 66     COORD pos;
 67     pos.X = x - 1;
 68     pos.Y = y - 1;
 69     SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
 70 }
 71 
 72 IL void backxy()
 73 {
 74     COORD pos;
 75     pos.X = lx;
 76     pos.Y = ly;
 77     SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
 78 } 
 79 
 80 IL void gotoxy(int x, int y)
 81 {
 82     /*
 83     HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
 84     COORD coordScreen = {0, 0}; //光标位置
 85     CONSOLE_SCREEN_BUFFER_INFO csbi;
 86     GetConsoleScreenBufferInfo(hConsole, &csbi);
 87     lx=csbi.dwCursorPosition.X,ly=csbi.dwCursorPosition.Y;
 88     
 89     */
 90     COORD pos;
 91     pos.X = x - 1;
 92     pos.Y = y - 1;
 93     SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
 94 }
 95 
 96 int choose(string a="",string b="",string c="",string d="退出"){
 97     HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
 98     COORD coordScreen = {0, 0}; //光标位置
 99     CONSOLE_SCREEN_BUFFER_INFO csbi;
100     GetConsoleScreenBufferInfo(hConsole, &csbi);
101     lx=csbi.dwCursorPosition.X,ly=csbi.dwCursorPosition.Y;
102     
103     gotoxy(50,1);
104     cout<<"----------------";
105     gotoxy(50,3);
106     cout<<"1."<<a;
107     
108     gotoxy(50,5);
109     cout<<"----------------";
110     gotoxy(50,7);
111     cout<<"2."<<b;
112     
113     gotoxy(50,9);
114     cout<<"----------------";
115     gotoxy(50,11);
116     cout<<"3."<<c;
117     
118     gotoxy(50,13);
119     cout<<"----------------";
120     gotoxy(50,15);
121     cout<<"4."<<d;
122     
123     gotoxy(50,17);
124     cout<<"----------------";
125     
126     gotoxy(50,18);
127     cout<<"请输入你的回复";gotoxy(50,19);cout<<"用数字1,2,3,4表示";
128     int tim=0;
129 
130     
131     int w,h; 
132     while(1){ 
133         ReadConsoleInput(ConsoleWin, &eventMsg, 1, &Pointer);//Read input msg
134         if(eventMsg.EventType == MOUSE_EVENT && eventMsg.Event.MouseEvent.dwButtonState == FROM_LEFT_1ST_BUTTON_PRESSED){
135             GetCursorPos(&curpos);
136             w=(int)curpos.x;
137             h=(int)curpos.y;
138             hwnd=GetForegroundWindow();
139             GetWindowRect(hwnd,&rect); 
140             w-=rect.left;h-=rect.top;cout<<"接受到数据"<<w<<" "<<h<<endl<<endl;
141             if(w>400){
142                 
143                 if(h<102) return 1;
144                 if(h<167) return 2;
145                 if(h<231) return 3;
146                 return 4;
147             }
148         }
149     } 
150     
151 }
152 
153 //时间戳转换成标准时间 
154 typedef struct times
155 {
156     int Year;
157     int Mon;
158     int Day;
159     int Hour;
160     int Min;
161     int Second;
162 } Times;
163 
164 Times stamp_to_standard(int stampTime)
165 {
166     time_t tick = (time_t)stampTime;
167     struct tm tm; 
168     char s[100];
169     Times standard;
170     //tick = time(NULL);
171     tm = *localtime(&tick);
172     strftime(s, sizeof(s), "%Y-%m-%d %H:%M:%S", &tm);
173 //    printf("%d: %s\n", (int)tick, s);
174 //    cout<<b.Year<<" "<<b.Mon<<" "<<b.Day<<" "<<b.Hour<<" "<<b.Min<<" "<<b.Second; 
175     standard.Year = atoi(s);
176     standard.Mon = atoi(s+5);
177     standard.Day = atoi(s+8);
178     standard.Hour = atoi(s+11);
179     standard.Min = atoi(s+14);
180     standard.Second = atoi(s+17);
181     return standard;
182 }
183 
184 //标准时间准换成时间戳 
185 int standard_to_stamp(char *str_time)//
186 {  
187     struct tm stm;  
188     int iY, iM, iD, iH, iMin, iS;  
189     
190     memset(&stm,0,sizeof(stm));  
191     iY = atoi(str_time);  
192     iM = atoi(str_time+5);  
193     iD = atoi(str_time+8);  
194     iH = atoi(str_time+11);  
195     iMin = atoi(str_time+14);  
196     iS = atoi(str_time+17);  
197     
198     stm.tm_year=iY-1900;  
199     stm.tm_mon=iM-1;  
200     stm.tm_mday=iD;  
201     stm.tm_hour=iH;  
202     stm.tm_min=iMin;  
203     stm.tm_sec=iS;  
204     //printf("%d-%0d-%0d %0d:%0d:%0d\n", iY, iM, iD, iH, iMin, iS);*/   //标准时间格式例如:2016:08:02 12:12:30
205     return (int)mktime(&stm);  
206 } 
207 
208 void new_event(){
209     system("cls");
210     eve now;
211     cout<<"请输入标题,中间不能带空格,以回车结尾\n";cin>>now.name;
212     system("cls");
213     
214     cout<<"标题:"<<now.name<<endl<<endl; 
215     cout<<"设定起始时间\n"<<"是否使用当前的时间?\ntime_stamp:"<<time(0)<<endl;
216     times b=stamp_to_standard(time(0));
217     cout<<b.Year<<"/"<<b.Mon<<"/"<<b.Day<<" "<<b.Hour<<":"<<b.Min<<":"<<b.Second<<endl;
218     if(choose("使用当前时间","自己设定时间")==1){
219         now.stime=time(0);
220     }
221     else{
222         cout<<"请输入时间,格式如:2020/02/24/11/15/20\n其中的/可以换成其他单字符\n";
223         char a[100];
224         for(int i=0;i<20;i++) a[i]=getchar();
225         now.stime=standard_to_stamp(a);
226     }
227     
228     times c=stamp_to_standard(now.stime);
229     cout<<"是否输入描述?";
230     if(choose("输入描述","无描述")==1){
231         system("cls"); 
232         cout<<"请输入描述,描述中不能空格,以回车结尾\n";
233         cin>>now.dec;
234     }
235     
236     cout<<"你有没有想好在多久以后完成?\n";
237     if(choose("想好了","暂时没想好")==1){
238         cout<<"请输入你打算在何时完成\n格式如:2020/02/24/11/15/20\n其中的/可以换成其他单字符\n";
239         char a[100];
240         for(int i=0;i<19;i++) a[i]=getchar();
241         now.ftime=standard_to_stamp(a);
242     }
243     
244     system("cls");
245     cout<<"设置完毕"<<cout<<"标题:"<<now.name<<endl<<"起始时间:"<<b.Year<<"/"<<b.Mon<<"/"<<b.Day<<" "<<b.Hour<<":"<<b.Min<<":"<<b.Second<<endl<<"描述:"<<now.dec<<endl;
246     if(now.ftime)
247         b=stamp_to_standard(now.ftime),cout<<"预计完成时间:"<<b.Year<<"/"<<b.Mon<<"/"<<b.Day<<" "<<b.Hour<<":"<<b.Min<<":"<<b.Second<<endl;
248     else cout<<"还没有预计完成时时间\n";
249     cout<<"是否保存?";
250     if(choose("保存","当然要保存!","不保存")!=3){
251         his.push_back(now);
252         sort(his.begin(),his.end(),hiscmp);
253     } 
254 }
255 
256 void show(){
257     system("cls");
258     cout<<"现在是";
259     times b=stamp_to_standard(time(0));
260     cout<<b.Year<<"/"<<b.Mon<<"/"<<b.Day<<" "<<b.Hour<<":"<<b.Min<<":"<<b.Second<<endl;
261     
262     cout<<"所有的任务\n";
263     for(int i=0;i<his.size();i++){
264         cout<<i+1000<<" "<<his[i].name<<endl<<his[i].dec<<endl;
265         b=stamp_to_standard(his[i].stime);
266         cout<<b.Year<<"/"<<b.Mon<<"/"<<b.Day<<" "<<b.Hour<<":"<<b.Min<<":"<<b.Second<<endl;
267         if(his[i].ftime)
268             b=stamp_to_standard(his[i].ftime),
269             cout<<b.Year<<"/"<<b.Mon<<"/"<<b.Day<<" "<<b.Hour<<":"<<b.Min<<":"<<b.Second<<endl;
270         else cout<<"还没有想好完成时间\n";
271         if(his[i].rtime)
272             b=stamp_to_standard(his[i].rtime),
273             cout<<b.Year<<"/"<<b.Mon<<"/"<<b.Day<<" "<<b.Hour<<":"<<b.Min<<":"<<b.Second<<endl;
274         else cout<<"没有完成这项任务\n";
275         cout<<endl;
276     }
277 }
278 
279 void read(){
280     ifstream fin("event.lib",ios::in);
281     if(fin.eof()) return;
282     eve t;int n;fin>>n;
283     for(int i=0;i<n;i++){
284         fin>>t.name;
285         getline(fin,t.dec);
286         fin>>t.stime>>t.ftime>>t.rtime;
287         his.push_back(t);
288     }
289 }
290 
291 IL void finish()
292 {
293     
294 }
295 
296 
297 
298 void save(){
299     ofstream fout("event.lib",ios::out);
300     fout<<his.size()<<endl;
301     for(int i=0;i<his.size();i++){
302         fout<<his[i].name<<endl<<his[i].dec<<endl<<his[i].stime<<" "<<his[i].ftime<<" "<<his[i].rtime<<endl<<endl;
303     }
304 }
305 
306 int main()
307 {
308     system("title Code by S.O.A.F");
309     read();
310     cout<<"唤醒欲望。若有想法,立即行动。\n";Sleep(1000);
311     while(true){
312         system("cls");
313         show();
314         switch(choose("创建新的事项","事项已完成","更多","退出"))
315         {
316             case 1:{ 
317                 new_event();
318                 break;
319             }
320             case 2:{
321                 finish(); 
322                 break;
323             }
324             case 3:{
325                 
326                 break;
327             }
328         }
329     }
330     
331 
332     
333     
334     return 0;
335 }
336 
337 void _return(){
338     system("cls");
339     save();
340     cout<<"已自动保存\n确认退出吗?";
341     switch(choose("是的","暂时不退出","重启","re")) {
342         case 1:{
343             exit(0);
344             break;
345         }
346         case 2:{
347             return;
348             break;
349         }
350         case 3:{
351             init();
352             main();
353             exit(0);
354             break;
355         }
356     }
357      
358 }
359 /*
360 GetCursorPos(&curpos);
361 a=(int)curpos.x;
362 b=(int)curpos.y;
363 
364 RECT rect; 
365 HWND hwnd=GetForegroundWindow();
366 GetWindowRect(hwnd,&rect); 
367 MoveWindow(hwnd,rect.left+SHAKE,rect.top,rect.right-rect.left,rect.bottom-rect.top,TRUE);
368 
369 
370 
371 
372 //moban
373 
374     while(1){
375         ReadConsoleInput(ConsoleWin, &eventMsg, 1, &Pointer);//Read input msg
376         if(eventMsg.EventType == MOUSE_EVENT && eventMsg.Event.MouseEvent.dwButtonState == FROM_LEFT_1ST_BUTTON_PRESSED){
377             GetCursorPos(&curpos);
378             a=(int)curpos.x;//w
379             b=(int)curpos.y;//h
380             cout<<a<<" "<<b<<endl;
381             hwnd=GetForegroundWindow();
382             GetWindowRect(hwnd,&rect); 
383             cout<<rect.left<<" "<<rect.top<<" "<<rect.right<<" "<<rect.bottom<<endl;
384             
385             cout<<a-rect.left<<" "<<b-rect.top<<endl<<endl;
386         }
387     } 
388 */ 
鼠标点击版

但后来添加了新功能后就不能用鼠标点击的方式来操作了。就是我太菜了

如果有大神愿意看看请看choose函数。

 

抛弃了这个项目一会儿,后来只好改成键盘互动啦。纯键盘互动也不是挺好的嘛

getchar()还要打回车,所以就用来getch(),可以避免要按回车太麻烦。

时间转换

计算机存储时间用的是时间戳,是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总毫秒数

但c++中,time_t time(0)其实是一个long类型的数据,是秒级别的而不是毫秒级别的。

用时间戳我们可以很方便的计算,储存。

至于时间戳的转换,也可以用部分内置函数来实现。

//时间戳转换成标准时间 
typedef struct times
{
    int Year;
    int Mon;
    int Day;
    int Hour;
    int Min;
    int Second;
} Times;

Times stamp_to_standard(int stampTime,bool output=false)
{
    time_t tick = (time_t)stampTime;
    struct tm tm; 
    char s[100];
    Times standard;
    //tick = time(NULL);
    tm = *localtime(&tick);
    strftime(s, sizeof(s), "%Y-%m-%d %H:%M:%S", &tm);
    if(output)
        printf("%d: %s", (int)tick, s);
//    cout<<b.Year<<" "<<b.Mon<<" "<<b.Day<<" "<<b.Hour<<" "<<b.Min<<" "<<b.Second; 
    standard.Year = atoi(s);
    standard.Mon = atoi(s+5);
    standard.Day = atoi(s+8);
    standard.Hour = atoi(s+11);
    standard.Min = atoi(s+14);
    standard.Second = atoi(s+17);
    return standard;
}

//标准时间准换成时间戳 
int standard_to_stamp(char *str_time)
{  
    struct tm stm;  
    int iY, iM, iD, iH, iMin, iS;  
    
    memset(&stm,0,sizeof(stm));  
    iY = atoi(str_time);  
    iM = atoi(str_time+5);  
    iD = atoi(str_time+8);  
    iH = atoi(str_time+11);  
    iMin = atoi(str_time+14);  
    iS = atoi(str_time+17);  
    
    stm.tm_year=iY-1900;  
    stm.tm_mon=iM-1;  
    stm.tm_mday=iD;  
    stm.tm_hour=iH;  
    stm.tm_min=iMin;  
    stm.tm_sec=iS;  
    //printf("%d-%0d-%0d %0d:%0d:%0d\n", iY, iM, iD, iH, iMin, iS);*/   //标准时间格式例如:2016:08:02 12:12:30
    return (int)mktime(&stm);  
} 

其输入的方式是:

标准时间:2020*01*01*21*01*00

其中“*”可以替换为任何单个字符,如空格 ,左斜杠/右斜杠\等。

时间戳:自己调用time(0)看看呗

并排窗口设计

可使用

getxy()

HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(hConsole, &csbi);
lx=csbi.dwCursorPosition.X,ly=csbi.dwCursorPosition.Y;

gotoxy()

IL void gotoxy(int x, int y)
{
    COORD pos;
    pos.X = x - 1;
    pos.Y = y - 1;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}

backxy()

IL void backxy()
{
    COORD pos;
    pos.X = lx;
    pos.Y = ly;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
} 

可以灵活地使控制台的光标跳转

所以,我就将所有的选择写成一个函数

int choose(string a="",string b="",string c="",string d=""){
    int all=0;
    if(a!="") all++;
    if(b!="") all++;
    if(c!="") all++; 
    if(d!="") all++;  
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    GetConsoleScreenBufferInfo(hConsole, &csbi);
    lx=csbi.dwCursorPosition.X,ly=csbi.dwCursorPosition.Y;
    
    if(MODE==2){
        gotoxy(50,1);
        cout<<"----------------";
        gotoxy(50,3);cout<<"                          ";
        gotoxy(50,3);cout<<"1."<<a;
        
        gotoxy(50,5);
        cout<<"----------------";
        gotoxy(50,7);cout<<"                          ";
        gotoxy(50,7);cout<<"2."<<b;
        
        gotoxy(50,9);
        cout<<"----------------";
        gotoxy(50,11);cout<<"                          ";
        gotoxy(50,11);cout<<"3."<<c;
        
        gotoxy(50,13);
        cout<<"----------------";
        gotoxy(50,15);cout<<"                          ";
        gotoxy(50,15);cout<<"4."<<d;
        
        gotoxy(50,17);
        cout<<"----------------";
        gotoxy(50,18);cout<<"返回请按b键";
        gotoxy(50,19);cout<<"按下s键以保存数据";
        gotoxy(50,20);cout<<"按下x键以保存并退出"; 
        gotoxy(50,21);cout<<"用数字1,2,3,4选择";
        gotoxy(50,22);cout<<"请输入你的回复";
    }
    
    if(MODE==1){
        gotoxy(50,1);
        cout<<"----------------";
        gotoxy(50,2);cout<<"                          ";
        gotoxy(50,2);cout<<"1."<<a;
        
        gotoxy(50,3);
        cout<<"----------------";
        gotoxy(50,4);cout<<"                          ";
        gotoxy(50,4);cout<<"2."<<b;
        
        gotoxy(50,5);
        cout<<"----------------";
        gotoxy(50,6);cout<<"                          ";
        gotoxy(50,6);cout<<"3."<<c;
        
        gotoxy(50,7);
        cout<<"----------------";
        gotoxy(50,8);cout<<"                          ";
        gotoxy(50,8);cout<<"4."<<d;
        
        gotoxy(50,9);
        cout<<"----------------";
        gotoxy(50,10);cout<<"返回请按b键";
        gotoxy(50,11);cout<<"按下s键以保存数据";
        gotoxy(50,12);cout<<"按下x键以保存并退出"; 
        gotoxy(50,13);cout<<"用数字1,2,3,4选择";
        gotoxy(50,14);cout<<"请输入你的回复";
    }
    
    char ans;
    while(1){
        ans=getch();
        if(ans>'0'&&ans<=all+'0')
        {
            backxy();
            return ans-'0';
        }  
        if(ans=='x'||ans=='X'){
            backxy();
            _return();return 0;
        }
        if(ans=='s'||ans=='S'){
            backxy();
            save();cout<<"保存成功";Sleep(2000);cout<<"\b\b  \b\b\b\b  \b\b\b\b  \b\b\b\b  \b\b";
        }
        if(ans=='b'||ans=='B'){
            backxy();
            return 0;
        } 
    } 
}

效果

储存任务

当然用 vector<task> 啦

posted @ 2020-03-08 19:15  Vanilla_chan  阅读(301)  评论(0编辑  收藏  举报