Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ctime>
- #include <conio.h>
- #include <iostream>
- #include <string>
- #include <functional>
- #include <windows.h>
- using namespace std;
- HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
- COORD CursorPosition;
- void Draw(int style, int col, int row, int length,int amount, bool fill, int sw );
- void gotoXY(int x, int y );
- void gotoXY(int x, int y, string text);
- void setcursor(bool visible, DWORD size);
- int main()
- {
- setcursor(0,0);
- int hours, minutes, seconds, t;
- struct tm * timeinfo;
- bool Military_Time = false;
- string AM_PM;
- string Segment[11][10]={
- {" \x11\xDB\xDB\xDB\x10 "," "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "," "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "},
- {"\x1E \x1E"," \x1E"," \x1E"," \x1E","\x1E \x1E","\x1E ","\x1E "," \x1E","\x1E \x1E","\x1E \x1E"},
- {"\xDB \xDB"," \xDB"," \xDB"," \xDB","\xDB \xDB","\xDB ","\xDB "," \xDB","\xDB \xDB","\xDB \xDB"},
- {"\xDB \xDB"," \xDB"," \xDB"," \xDB","\xDB \xDB","\xDB ","\xDB "," \xDB","\xDB \xDB","\xDB \xDB"},
- {"\x1F \x1F"," \x1F"," \x1F"," \x1F","\x1F \x1F","\x1F ","\x1F "," \x1F","\x1F \x1F","\x1F \x1F"},
- {" "," ", " \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "," "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "},
- {"\x1E \x1E"," \x1E","\x1E "," \x1E"," \x1E"," \x1E","\x1E \x1E"," \x1E","\x1E \x1E"," \x1E"},
- {"\xDB \xDB"," \xDB","\xDB "," \xDB"," \xDB"," \xDB","\xDB \xDB"," \xDB","\xDB \xDB"," \xDB"},
- {"\xDB \xDB"," \xDB","\xDB "," \xDB"," \xDB"," \xDB","\xDB \xDB"," \xDB","\xDB \xDB"," \xDB"},
- {"\x1F \x1F"," \x1F","\x1F "," \x1F"," \x1F"," \x1F","\x1F \x1F"," \x1F","\x1F \x1F"," \x1F"},
- {" \x11\xDB\xDB\xDB\x10 "," "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "," "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "," "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "}
- };
- string Colon[11] = {" "," "," "," \xFE "," "," "," "," \xFE "," "," "," "};
- Draw(2,2,5,76,15,0,2);
- gotoXY(26,11,"Pressing the \"M\" key");
- gotoXY(26,13,"toggles Military Time");
- Sleep(2000);
- Draw(1,4,6,72,13,1,0);
- gotoXY(73,8,"HR");
- do
- {
- time_t rawtime;
- time ( &rawtime );
- timeinfo = localtime( &rawtime );
- hours = timeinfo->tm_hour;
- seconds = timeinfo->tm_sec;
- minutes = timeinfo->tm_min;
- if (_kbhit())
- {
- char ch = _getch();
- ch = toupper(ch);
- if (ch == 'M')
- {
- Military_Time = !Military_Time;
- ch = ' ';
- }
- }
- if( Military_Time)
- {
- AM_PM = " ";
- gotoXY(73,7,"24");
- }
- else
- {
- AM_PM = "AM";
- gotoXY(73,7,"12");
- if ( hours >= 12)
- AM_PM = "PM";
- if ( hours == 0 )
- hours = 12;
- if ( hours > 12)
- hours -=12;
- }
- for(t=0;t<11;t++)
- {
- gotoXY(6,7+t);
- cout << Segment[t][hours/10] << " " << Segment[t][hours%10] << Colon[t] << Segment[t][minutes/10] << " " << Segment[t][minutes%10] << Colon[t] << Segment[t][seconds/10] << " " << Segment[t][seconds%10];
- }
- gotoXY(73,17, AM_PM);
- Sleep(1000);
- } while (true);
- }
- void Draw(int style, int col, int row, int length,int amount, bool fill, int sw )
- {
- // Draws a 1 or 2 line box
- int a;
- if ( sw >4)
- sw = 4;
- style=(style-1)*6;
- char box[24];
- char shdw[5];
- box[0] = '\xDA';
- box[1] = '\xBF';
- box[2] = '\xC0';
- box[3] = '\xD9';
- box[4] = '\xB3';
- box[5] = '\xC4';
- box[6] = '\xC9';
- box[7] = '\xBB';
- box[8] = '\xC8';
- box[9] = '\xBC';
- box[10] = '\xBA';
- box[11] = '\xCD';
- box[12] = '\xD5';// +
- box[13] = '\xB8';// +
- box[14] = '\xD4';// +
- box[15] = '\xBE';// +
- box[16] = '\xB3';// ¦
- box[17] = '\xCD';// -
- box[18] = '\xD6';// +
- box[19] = '\xB7';// +
- box[20] = '\xD3';// +
- box[21] = '\xBD';// +
- box[22] = '\xBA';// ¦
- box[23] = '\xC4';// -
- shdw[1] = '\xB0';// ¦
- shdw[2] = '\xB1';// ¦
- shdw[3] = '\xB2';// ¦
- shdw[4] = '\xDB';// ¦
- char tl,tr,bl,br,side,edge,shadow;
- tl = box[style];
- tr = box[style+1];
- bl = box[style+2];
- br = box[style+3];
- side = box[style+4];
- edge = box[style+5];
- shadow = shdw[sw];
- string Line(length-2,edge);
- string Shadow(length,shadow);
- string Fill(length-2, ' ');
- gotoXY(col,row);
- cout << tl << Line << tr;
- for (a = 1; a <amount-1;a++)
- {
- gotoXY(col,row+a);
- cout << side;
- if (fill)
- cout << Fill;
- else
- gotoXY(col+length-1,row+a);
- cout << side;
- if (sw)
- cout << shadow;
- }
- gotoXY(col,(amount+row)-1);
- cout << bl << Line << br;
- if (sw)
- {
- cout << shadow;
- gotoXY(col+1,row+amount , Shadow );
- }
- }
- void gotoXY(int x, int y)
- {
- CursorPosition.X = x;
- CursorPosition.Y = y;
- SetConsoleCursorPosition(console,CursorPosition);
- }
- void gotoXY(int x, int y, string text)
- {
- CursorPosition.X = x;
- CursorPosition.Y = y;
- SetConsoleCursorPosition(console,CursorPosition);
- cout << text;
- }
- void setcursor(bool visible, DWORD size) // set bool visible = 0 - invisible, bool visible = 1 - visible
- {
- if(size == 0)
- {
- size = 20; // default cursor size
- }
- CONSOLE_CURSOR_INFO lpCursor;
- lpCursor.bVisible = visible;
- lpCursor.dwSize = size;
- SetConsoleCursorInfo(console,&lpCursor);
- }
Advertisement
Add Comment
Please, Sign In to add comment