跳到正文

个人记录

c++时间管理大师

WuMin4约 18 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年3月13日
篇幅
约 18 分钟

版本

  1. v1当前

作者花了一个上午写出来的。

c++写的时间管理大师。

支持一下。

C++
#include<bits/stdc++.h>
#include<windows.h>
#define kd(vk) (GetAsyncKeyState(vk)&0x8000?1:0)
using namespace std;
#define SHAKE 15
void ShakeWindow(){
	RECT rect;
	HWND hwnd=GetConsoleWindow();
	GetWindowRect(hwnd,&rect);
	MoveWindow(hwnd,rect.left+SHAKE,rect.top,rect.right-rect.left,rect.bottom-rect.top,TRUE);
	Sleep(28);
	MoveWindow(hwnd,rect.left+SHAKE,rect.top-SHAKE,rect.right-rect.left,rect.bottom-rect.top,TRUE);
	Sleep(28);
	MoveWindow(hwnd,rect.left,rect.top-SHAKE,rect.right-rect.left,rect.bottom-rect.top,TRUE);
	Sleep(28);
	MoveWindow(hwnd,rect.left,rect.top,rect.right-rect.left,rect.bottom-rect.top,TRUE);
}
void moveToMid(){
	HWND consoleWindow = GetConsoleWindow();
	RECT desktop;
	GetWindowRect(GetDesktopWindow(), &desktop);
	int width = desktop.right - desktop.left;
	int height = desktop.bottom - desktop.top;
	RECT consoleRect;
	GetWindowRect(consoleWindow, &consoleRect);
	int consoleWidth = consoleRect.right - consoleRect.left;
	int consoleHeight = consoleRect.bottom - consoleRect.top;
	SetWindowPos(consoleWindow, NULL,
		(width - consoleWidth) / 2,
		(height - consoleHeight) / 2,
		0, 0, SWP_NOSIZE | SWP_NOZORDER);
}
void gt(int x,int y){
	COORD pos;pos.X=x;pos.Y=y;
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
bool gks(char s){
	return GetKeyState(s)<0;
}
void SetConsoleWindowSize(SHORT width,SHORT height)
{
	HANDLE hStdOutput=GetStdHandle(STD_OUTPUT_HANDLE);
	SMALL_RECT wrt={0,0,width-1,height-1};
	SetConsoleWindowInfo(hStdOutput,TRUE,&wrt);
	COORD coord={width,height};
	SetConsoleScreenBufferSize(hStdOutput,coord);
}
void setTextSize(int x,int y){
	CONSOLE_FONT_INFOEX cfi;
	cfi.cbSize=sizeof(cfi);
	cfi.nFont=0;
	cfi.dwFontSize.X=x;
	cfi.dwFontSize.Y=y;
	cfi.FontFamily = FF_DONTCARE;
	cfi.FontWeight = FW_NORMAL;
	SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE),FALSE,&cfi);
}
void closeQuickEditMode(){
	HANDLE hStdin=GetStdHandle(STD_INPUT_HANDLE);DWORD mode;
	GetConsoleMode(hStdin,&mode);mode&=~ENABLE_QUICK_EDIT_MODE;
	SetConsoleMode(hStdin,mode);
}
void disMouse(){
	ShowCursor(false);HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
	CONSOLE_CURSOR_INFO cci;GetConsoleCursorInfo(hOut,&cci);
	cci.bVisible=false;SetConsoleCursorInfo(hOut,&cci);
}
POINT gm(){
	HWND h=GetForegroundWindow();
	POINT p;
	GetCursorPos(&p);
	ScreenToClient(h,&p);
	return p;
}
void TopWindow(HWND &hWnd) {
	SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}
void color(int a){
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}
void debug(){
	color(7);
	int nx=min(max((long int)-1,gm().x/16),(long int)24),ny=min(max((long int)-1,gm().y/16),(long int)8);
	gt(0,4);
	cout<<nx<<"  "<<ny<<"   ";
}
int hr,mn,sc,tot,lst=-1,mode=0;
void update(){
	color(7);
	gt(4,2);
	if(hr<10) cout<<"0"<<hr;
	else cout<<hr;
	gt(11,2);
	if(mn<10) cout<<"0"<<mn;
	else cout<<mn;
	gt(18,2);
	if(sc<10) cout<<"0"<<sc;
	else cout<<sc;
}
void count_down(){
	color(136);
	if((int)(((tot-(3600*hr+60*mn+sc))*1.0/tot)*29)!=lst){
		for(int i=lst+1;i<=(int)(((tot-(3600*hr+60*mn+sc))*1.0/tot)*29);i++)
			gt(i,4),cout<<"=";
		lst=(int)(((tot-(3600*hr+60*mn+sc))*1.0/tot)*29);
	}
}
signed main(){
	closeQuickEditMode();
	SetConsoleWindowSize(30,5);
	setTextSize(13,26);
	disMouse();
	st:
	while(kd(VK_LBUTTON)) Sleep(10);
	hr=mn=sc=tot=0,lst=-1;
	color(7);
	SetConsoleTitle("计时器");
	system("cls");
	gt(0,0);
	cout<<"计时器设置:";
	if(mode==0){
		gt(4,1);
		cout<<"︽     ︽     ︽    [启动]";
		gt(4,2);
		cout<<"  时:   分:   秒  ";
		gt(4,3);
		cout<<"︾     ︾     ︾  [倒计时]";
	}
	else{
		gt(4,1);
		cout<<"================== ";
		gt(4,2);
		cout<<"=  点击按钮开始  = ";
		gt(4,3);
		cout<<"================== ";
	}
	while(true){
		if(mode==0) update();
		int nx=min(max((long int)-1,gm().x/16),(long int)25),ny=min(max((long int)-1,gm().y/16),(long int)9);
		if((17<=nx&&nx<=24)&&(5<=ny&&ny<=6)){
			color(8),gt(22,3);
			if(mode==0) cout<<"[倒计时]";
			else cout<<"[正计时]";
			if(kd(VK_LBUTTON)){
				color(7);
				mode^=1;
				while(kd(VK_LBUTTON)) Sleep(10);
				if(mode==0){
					gt(4,1);
					cout<<"                   ";
					gt(4,2);
					cout<<"  时:   分:   秒  ";
					gt(4,3);
					cout<<"                   ";
				}
				else{
					gt(4,1);
					cout<<"================== ";
					gt(4,2);
					cout<<"=  点击按钮开始  = ";
					gt(4,3);
					cout<<"================== ";
				}
			}
		}
		else{
			color(7),gt(22,3);
			if(mode==0) cout<<"[倒计时]";
			else cout<<"[正计时]";
		}
		if((19<=nx&&nx<=24)&&(1<=ny&&ny<=2)){
			color(8),gt(24,1),cout<<"[启动]";
			if(kd(VK_LBUTTON)){
				break;
			}
		}
		else
			color(7),gt(24,1),cout<<"[启动]";
		if(mode==0){
			if((nx==3&&ny==2)||(nx==4&&ny==2)){
				color(8),gt(4,1),cout<<"︽";
				int tcnt=0;
				if(kd(VK_LBUTTON)){
					hr=(hr+1)%100,update();
					while(kd(VK_LBUTTON)&&tcnt<20) tcnt++,Sleep(10);
					tcnt=0;
					while(kd(VK_LBUTTON)&&tcnt<10)hr=(hr+1)%100,update(),Sleep(100),tcnt++;
					while(kd(VK_LBUTTON))hr=(hr+1)%100,update(),Sleep(20);
				}
			}
			else
				color(7),gt(4,1),cout<<"︽";
			if((nx==3&&ny==5)||(nx==4&&ny==5)){
				color(8),gt(4,3),cout<<"︾";
				int tcnt=0;
				if(kd(VK_LBUTTON)){
					hr=(hr+99)%100,update();
					while(kd(VK_LBUTTON)&&tcnt<20) tcnt++,Sleep(10);
					tcnt=0;
					while(kd(VK_LBUTTON)&&tcnt<10)hr=(hr+99)%100,update(),Sleep(100),tcnt++;
					while(kd(VK_LBUTTON))hr=(hr+99)%100,update(),Sleep(20);
				}
			}
			else
				color(7),gt(4,3),cout<<"︾";
			if((nx==9&&ny==2)||(nx==10&&ny==2)){
				color(8),gt(11,1),cout<<"︽";
				int tcnt=0;
				if(kd(VK_LBUTTON)){
					mn=(mn+1)%60,update();
					while(kd(VK_LBUTTON)&&tcnt<20) tcnt++,Sleep(10);
					tcnt=0;
					while(kd(VK_LBUTTON)&&tcnt<10)mn=(mn+1)%60,update(),Sleep(100),tcnt++;
					while(kd(VK_LBUTTON))mn=(mn+1)%60,update(),Sleep(20);
				}
			}
			else
				color(7),gt(11,1),cout<<"︽";
			if((nx==9&&ny==5)||(nx==10&&ny==5)){
				color(8),gt(11,3),cout<<"︾";
				int tcnt=0;
				if(kd(VK_LBUTTON)){
					mn=(mn+59)%60,update();
					while(kd(VK_LBUTTON)&&tcnt<20) tcnt++,Sleep(10);
					tcnt=0;
					while(kd(VK_LBUTTON)&&tcnt<10)mn=(mn+59)%60,update(),Sleep(100),tcnt++;
					while(kd(VK_LBUTTON))mn=(mn+59)%60,update(),Sleep(20);
				}
			}
			else
				color(7),gt(11,3),cout<<"︾";
			if((nx==14&&ny==2)||(nx==15&&ny==2)){
				color(8),gt(18,1),cout<<"︽";
				int tcnt=0;
				if(kd(VK_LBUTTON)){
					sc=(sc+1)%60,update();
					while(kd(VK_LBUTTON)&&tcnt<20) tcnt++,Sleep(10);
					tcnt=0;
					while(kd(VK_LBUTTON)&&tcnt<10)sc=(sc+1)%60,update(),Sleep(100),tcnt++;
					while(kd(VK_LBUTTON))sc=(sc+1)%60,update(),Sleep(20);
				}
			}
			else
				color(7),gt(18,1),cout<<"︽";
			if((nx==14&&ny==5)||(nx==15&&ny==5)){
				color(8),gt(18,3),cout<<"︾";
				int tcnt=0;
				if(kd(VK_LBUTTON)){
					sc=(sc+59)%60,update();
					while(kd(VK_LBUTTON)&&tcnt<20) tcnt++,Sleep(10);
					tcnt=0;
					while(kd(VK_LBUTTON)&&tcnt<10)sc=(sc+59)%60,update(),Sleep(100),tcnt++;
					while(kd(VK_LBUTTON))sc=(sc+59)%60,update(),Sleep(20);
				}
			}
			else
				color(7),gt(18,3),cout<<"︾";
		}
		HWND hWnd=GetConsoleWindow();
		TopWindow(hWnd);
		Sleep(10);
	}
	while(kd(VK_LBUTTON)) Sleep(10);
	if(mode==0)
		tot=3600*hr+60*mn+sc;
	else
		tot=hr=mn=sc=0;
	color(7);
	gt(0,0);
	if(mode==0)
		cout<<"距离结束还剩";
	else
		cout<<"            ";
	gt(3,1);
	cout<<"==================== [暂停]";
	gt(3,2);
	cout<<"=  时:   分:   秒=       ";
	gt(3,3);
	cout<<"==================== [退出]";
	int lst_sec=clock(),isp=0;
	while(true){
		int nx=min(max((long int)-1,gm().x/16),(long int)25),ny=min(max((long int)-1,gm().y/16),(long int)9);
		if(!isp){
			update();
			if(mode==0)
				sc=sc-((clock()/CLOCKS_PER_SEC)-(lst_sec/CLOCKS_PER_SEC));
			else
				sc=sc+((clock()/CLOCKS_PER_SEC)-(lst_sec/CLOCKS_PER_SEC));
			lst_sec=clock();
		}
		if(sc<0)
			sc=59,mn=mn-1;
		if(sc>59)
			sc=0,mn=mn+1;
		if(mn<0)
			mn=59,hr=hr-1;
		if(mn>59)
			mn=0,hr=hr+1;
		if((19<=nx&&nx<=24)&&(1<=ny&&ny<=2)){
			color(8),gt(24,1),cout<<(isp?"[继续]":"[暂停]");
			if(kd(VK_LBUTTON)){
				if(!isp)
					isp=true;
				else
					isp=false,lst_sec=clock();
				while(kd(VK_LBUTTON));
			}
		}
		else{
			color(7),gt(24,1),cout<<(isp?"[继续]":"[暂停]");
		}
		if((19<=nx&&nx<=24)&&(5<=ny&&ny<=6)){
			color(8),gt(24,3),cout<<"[退出]";
			if(kd(VK_LBUTTON)){
				while(kd(VK_LBUTTON)) Sleep(10);
				goto st;
			}
		}
		else{
			color(7),gt(24,3),cout<<"[退出]";
		}
		if(mode==0&&sc==0&&mn==0&&hr==0)
			break;
		if(mode==0)
			count_down();
		HWND hWnd=GetConsoleWindow();
		TopWindow(hWnd);
		Sleep(10);
	}
	color(7);
	gt(0,0);
	cout<<"                           ";
	gt(24,1);
	cout<<"      ";
	gt(3,2);
	cout<<"=[TIME  IS  OVER!!]=       ";
	gt(0,4);
	cout<<"                           ";
	while(true){
		int nx=min(max((long int)-1,gm().x/16),(long int)25),ny=min(max((long int)-1,gm().y/16),(long int)9);
		moveToMid();
		if((19<=nx&&nx<=24)&&(5<=ny&&ny<=6)){
			color(8),gt(24,3),cout<<"[退出]";
			if(kd(VK_LBUTTON)){
				goto st;
			}
		}
		else{
			color(7),gt(24,3),cout<<"[退出]";
		}
	}
	return 0;
}
原文