Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <iostream>
- #include <ctime>
- #include <cstdlib>
- #include <conio.h>
- #include <cmath>
- using namespace std;
- HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
- HANDLE hIn=GetStdHandle(STD_INPUT_HANDLE);
- const int ncolors=3;
- int colors[ncolors]={BACKGROUND_RED|BACKGROUND_INTENSITY,BACKGROUND_GREEN|BACKGROUND_INTENSITY,BACKGROUND_BLUE|BACKGROUND_INTENSITY};
- int colors2[ncolors]={FOREGROUND_RED|FOREGROUND_INTENSITY,FOREGROUND_GREEN|FOREGROUND_INTENSITY,FOREGROUND_BLUE|FOREGROUND_INTENSITY};
- struct Window
- {
- char title[100];
- int left,top,right,bottom;
- };
- void DrawWindow(Window w)
- {
- COORD c;
- c.X=w.left;
- c.Y=w.top;
- //устанавливает курсор
- SetConsoleCursorPosition(hOut,c);
- SetConsoleTextAttribute(hOut,FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_RED|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
- for(int i=0; i<w.right-w.left; ++i)
- {
- if(i<strlen(w.title))
- cout<<w.title[i];
- else
- cout<<' ';
- }
- for(int i=1; i<w.bottom-w.top; ++i)
- {
- SetConsoleTextAttribute(hOut,BACKGROUND_GREEN|BACKGROUND_BLUE|BACKGROUND_RED);
- c.Y=w.top+i;
- SetConsoleCursorPosition(hOut,c);
- for(int j=0; j<w.right-w.left; ++j)
- cout<<' ';
- SetConsoleTextAttribute(hOut,0);
- cout<<' ';
- }
- c.Y=w.bottom;
- ++c.X;
- SetConsoleCursorPosition(hOut,c);
- for(int j=0; j<w.right-w.left; ++j)
- cout<<' ';
- for(int i=0; i<ncolors; ++i)
- {
- c.X=w.right-(i+1);
- c.Y=w.top;
- SetConsoleCursorPosition(hOut,c);
- SetConsoleTextAttribute(hOut,colors[i]);
- cout<<' ';
- }
- }
- void Set(Window & w, int x, int y, int width, int height, char * title)
- {
- w.left=x;
- w.right=x+width;
- w.top=y;
- w.bottom=y+height;
- strcpy_s(w.title,100,title);
- }
- int CheckWnd(Window * w, int count, COORD c)
- {
- for(int i=count-1; i>-1; --i)
- {
- if(c.X>=w[i].left&&c.X<w[i].right&&c.Y>=w[i].top&&c.Y<w[i].bottom)
- {
- return i;
- }
- }
- return -1;
- }
- void BringToTop(Window * w, int count, int index)
- {
- if(index<0||index>=count) return;
- Window temp=w[index];
- for(int i=index; i<count-1; ++i)
- w[i]=w[i+1];
- w[count-1]=temp;
- }
- void Show(Window * w, int count)
- {
- for(int i=0; i<count; ++i)
- {
- DrawWindow(w[i]);
- }
- }
- void main()
- {
- system("color a0");
- srand((int)time(0));
- CONSOLE_CURSOR_INFO cInfo={100,false};
- DWORD l, mode;
- INPUT_RECORD ir;
- CONSOLE_SCREEN_BUFFER_INFO cbinf;
- COORD c0={0,0};
- SetConsoleCursorInfo(hOut,&cInfo);
- int count=0;
- Window * w=nullptr, wtemp;
- int c;
- GetConsoleMode(hIn,&mode);
- SetConsoleMode(hIn,ENABLE_MOUSE_INPUT|ENABLE_WINDOW_INPUT);
- char str[100],temp[10];
- int wpos=-1;
- int color=colors2[0];
- do{
- while(ReadConsoleInput(hIn,&ir,1, &l))
- {
- if(ir.EventType==MOUSE_EVENT)
- {
- if(ir.Event.MouseEvent.dwButtonState==FROM_LEFT_1ST_BUTTON_PRESSED)
- {
- c=CheckWnd(w,count,ir.Event.MouseEvent.dwMousePosition);
- if(c!=count-1)
- {
- BringToTop(w,count,c);
- DrawWindow(w[count-1]);
- }else if(c!=-1&&ir.Event.MouseEvent.dwMousePosition.Y>w[c].top)
- {
- SetConsoleTextAttribute(hOut,color|BACKGROUND_GREEN|BACKGROUND_BLUE|BACKGROUND_RED);
- SetConsoleCursorPosition(hOut,ir.Event.MouseEvent.dwMousePosition);
- cout<<char(3);
- }else if(c!=-1&&ir.Event.MouseEvent.dwMousePosition.Y==w[c].top&&ir.Event.MouseEvent.dwMousePosition.X>=w[c].right-3)
- {
- color=colors2[w[c].right-ir.Event.MouseEvent.dwMousePosition.X-1];
- }else if(c!=-1&&ir.Event.MouseEvent.dwEventFlags!=MOUSE_MOVED)
- {
- wpos=ir.Event.MouseEvent.dwMousePosition.X-w[count-1].left;
- }
- if(ir.Event.MouseEvent.dwEventFlags==MOUSE_MOVED&&wpos!=-1)
- {
- w[count-1].top=ir.Event.MouseEvent.dwMousePosition.Y;
- w[count-1].left=ir.Event.MouseEvent.dwMousePosition.X-wpos;
- w[count-1].right=w[count-1].left+20;
- w[count-1].bottom=w[count-1].top+10;
- GetConsoleScreenBufferInfo(hIn,&cbinf);
- FillConsoleOutputAttribute(hOut,BACKGROUND_GREEN|BACKGROUND_INTENSITY,cbinf.dwSize.X*cbinf.dwSize.Y,c0,&l);
- FillConsoleOutputCharacter(hOut,' ',cbinf.dwSize.X*cbinf.dwSize.Y,c0,&l);
- Show(w,count);
- //DrawWindow(w[count-1]);
- }
- }else
- if(ir.Event.MouseEvent.dwButtonState==RIGHTMOST_BUTTON_PRESSED)
- {
- if(count) delete [] w;
- count=0;
- GetConsoleScreenBufferInfo(hIn,&cbinf);
- FillConsoleOutputAttribute(hOut,BACKGROUND_GREEN|BACKGROUND_INTENSITY,cbinf.dwSize.X*cbinf.dwSize.Y,c0,&l);
- FillConsoleOutputCharacter(hOut,' ',cbinf.dwSize.X*cbinf.dwSize.Y,c0,&l);
- }else
- {
- wpos=-1;
- }
- }else
- if(ir.EventType==KEY_EVENT)
- {
- if(ir.Event.KeyEvent.bKeyDown)
- {
- c=ir.Event.KeyEvent.wVirtualKeyCode;
- switch(ir.Event.KeyEvent.wVirtualKeyCode)
- {
- case 9:
- wtemp=w[count-1];
- for(int i=count-1; i>0; --i)
- w[i]=w[i-1];
- w[0]=wtemp;
- Show(w,count);
- break;
- case VK_RETURN:
- Window * tempw=new Window[count+1];
- for(int i=0; i<count; ++i)
- {
- tempw[i]=w[i];
- }
- if(count) delete [] w;
- w=tempw;
- strcpy(str,"Title ");
- _itoa(count+1,temp,10);
- strcat(str,temp);
- Set(w[count++],rand()%20,rand()%10,20,10,str);
- Show(w,count);
- break;
- }
- }
- }
- }
- }while(c!=VK_ESCAPE);
- delete [] w;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement