Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <windows.h>
  2. #include <vector>
  3.      
  4. LPCWSTR ClassName = L"WndClass";
  5. MSG msg;
  6.  
  7. std::vector<HWND> handles;
  8. std::vector<COLORREF> colours;
  9.  
  10. PAINTSTRUCT ps;
  11. HDC hdc;
  12. RECT wRect;
  13.  
  14. HBRUSH currentBrush;
  15. HPEN currentPen;
  16.  
  17. COLORREF menuColor = RGB(135, 135, 135);
  18. COLORREF colBrush;
  19. COLORREF colPen;
  20.  
  21. RECT menu;
  22.  
  23. int x, y, x2, y2;
  24.  
  25. enum {rectangle, ellipse, triangle} object;
  26.  
  27. LRESULT CALLBACK WndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
  28.  
  29. void IconRect(HDC hdc, int left, int top, int right, int bottom);
  30. void IconEllipse(HDC hdc, int left, int top, int right, int bottom);
  31. void IconTriangle(HDC hdc, int left, int top, int right, int bottom);
  32.      
  33. int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
  34. {
  35.     WNDCLASSEX wc;
  36.      
  37.     wc.cbSize = sizeof( WNDCLASSEX );
  38.     wc.style = 0;
  39.     wc.lpfnWndProc = WndProc;
  40.     wc.cbClsExtra = 0;
  41.     wc.cbWndExtra = 0;
  42.     wc.hInstance = hInstance;
  43.     wc.hIcon = LoadIcon( 0, IDI_APPLICATION );
  44.     wc.hCursor = LoadCursor( 0, IDC_ARROW );
  45.     wc.hbrBackground =( HBRUSH )( COLOR_WINDOW + 1 );
  46.     wc.lpszMenuName = 0;
  47.     wc.lpszClassName = ClassName;
  48.     wc.hIconSm = LoadIcon( 0, IDI_APPLICATION );
  49.  
  50.     colours.push_back(RGB(255,255,255));
  51.     colours.push_back(RGB(0,0,0));
  52.     colours.push_back(RGB(127,0,0));
  53.     colours.push_back(RGB(0,127,0));
  54.     colours.push_back(RGB(0,0,127));
  55.     colours.push_back(RGB(127,127,0));
  56.     colours.push_back(RGB(127,0,127));
  57.     colours.push_back(RGB(0,127,127));
  58.    
  59.     if( !RegisterClassEx( & wc ) )
  60.     {
  61.         MessageBox( NULL, L"Wysoka Komisja odmawia rejestracji tego okna!", L"Niestety...", MB_ICONEXCLAMATION | MB_OK );
  62.         return 1;
  63.     }
  64.      
  65.     handles.push_back(CreateWindowEx( 0, ClassName, L"MainWnd", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, 0, 0, hInstance, 0 ));
  66.      
  67.     for(int i = 0; i < handles.size(); ++i)
  68.     {
  69.         if( handles[i] == 0 )
  70.         {
  71.             MessageBox( NULL, L"Okno odmówiło przyjścia na świat!", L"Ale kicha...", MB_ICONEXCLAMATION );
  72.             return 1;
  73.         }
  74.     }
  75.    
  76.     for(int i = 0; i < handles.size(); ++i)
  77.     {
  78.         ShowWindow( handles[i], nCmdShow );
  79.         UpdateWindow( handles[i] );
  80.     }
  81.  
  82.     while( GetMessage( & msg, 0, 0, 0 ) )
  83.     {
  84.         TranslateMessage( & msg );
  85.         DispatchMessage( & msg );
  86.     }
  87.     UnregisterClassW(ClassName, hInstance);
  88.     return msg.wParam;
  89. }
  90.      
  91.      
  92. LRESULT CALLBACK WndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  93. {
  94.     switch( uMsg )
  95.     {
  96.         case WM_CLOSE:
  97.             {
  98.                 DestroyWindow( hwnd );     
  99.             }
  100.             break;
  101.      
  102.         case WM_DESTROY:
  103.             if(handles.size() <= 1)
  104.             {
  105.                 colours.erase(colours.begin(), colours.end());
  106.                 PostQuitMessage( 0 );
  107.             }
  108.             break;
  109.      
  110.         case WM_PAINT:
  111.             {
  112.                 hdc = BeginPaint(hwnd, &ps);
  113.                 GetClientRect(hwnd, &wRect);
  114.  
  115.                 menu = wRect;
  116.                 menu.left = wRect.right - 220;
  117.  
  118.                 HBRUSH brush = CreateSolidBrush(menuColor);
  119.                 SelectObject(hdc, brush);
  120.                 Rectangle(hdc, menu.left, menu.top, menu.right, menu.bottom);
  121.                 DeleteObject(brush);
  122.  
  123.                 for(int i = 0; i < colours.size(); ++i)
  124.                 {      
  125.                     HBRUSH brush = CreateSolidBrush(colours[i]);
  126.                     HBRUSH def = (HBRUSH) SelectObject(hdc, brush);
  127.  
  128.                     if(i % 2)
  129.                     {
  130.                         Rectangle(hdc, wRect.right - 190, wRect.top - 20 + i*40, wRect.right - 140, wRect.top + (30 + i*40));
  131.                     }
  132.                     else
  133.                     {
  134.                         Rectangle(hdc, wRect.right - 90, wRect.top + (20 + i*40), wRect.right - 40, wRect.top + (70 + i*40));
  135.                     }
  136.  
  137.                     SelectObject(hdc, def);
  138.                     DeleteObject(brush);
  139.                 }              
  140.  
  141.                 IconRect(hdc, wRect.right - 190, wRect.top + 400, wRect.right - 140, wRect.top + 450);
  142.                 IconEllipse(hdc, wRect.right - 90, wRect.top + 400, wRect.right - 40, wRect.top + 450);
  143.                 IconTriangle(hdc, wRect.right - 190, wRect.top + 470, wRect.right - 140, wRect.top + 520);
  144.  
  145.                 switch(object)
  146.                 {
  147.                     case rectangle:
  148.                         {
  149.                             HPEN defPen = (HPEN) SelectObject(hdc, currentPen);
  150.                             Rectangle(hdc, x, y, x2, y2);
  151.                             HBRUSH defBrush = (HBRUSH) SelectObject(hdc, currentBrush);
  152.                             Rectangle(hdc, x, y, x2, y2);
  153.                         }
  154.                         break;
  155.  
  156.                     case ellipse:
  157.                         {
  158.                             HPEN defPen = (HPEN) SelectObject(hdc, currentPen);
  159.                             Ellipse(hdc, x, y, x2, y2);
  160.                             HBRUSH defBrush = (HBRUSH) SelectObject(hdc, currentBrush);
  161.                             Ellipse(hdc, x, y, x2, y2);
  162.                         }
  163.                         break;
  164.  
  165.                     case triangle:
  166.                         {
  167.                             POINT pts[3];
  168.                             pts[0].x = x + (x2-x)/2;
  169.                             pts[0].y = y;
  170.                             pts[1].x = x2;
  171.                             pts[1].y = y2;
  172.                             pts[2].x = x;
  173.                             pts[2].y = y2;
  174.  
  175.                             HPEN defPen = (HPEN) SelectObject(hdc, currentPen);
  176.                             Polygon(hdc, pts , 3);
  177.                             HBRUSH defBrush = (HBRUSH) SelectObject(hdc, currentBrush);
  178.                             Polygon(hdc, pts , 3);
  179.                         }
  180.                         break;
  181.                 }
  182.  
  183.                 EndPaint(hwnd, &ps);
  184.             }
  185.             break;
  186.  
  187.         case WM_RBUTTONDOWN:
  188.             {          
  189.                 x = LOWORD(lParam);
  190.                 y = HIWORD(lParam);
  191.  
  192.                 hdc = GetDC(hwnd);
  193.  
  194.                 if(GetPixel(hdc, x, y) != menuColor && x > menu.left)
  195.                 {
  196.                     currentPen = CreatePen(BS_SOLID, 3, GetPixel(hdc, x, y));
  197.                 }
  198.  
  199.                 ReleaseDC(hwnd, hdc);
  200.             }
  201.             break;
  202.  
  203.         case WM_LBUTTONDOWN:
  204.             {
  205.                 x = LOWORD(lParam);
  206.                 y = HIWORD(lParam);
  207.  
  208.                 hdc = GetDC(hwnd);
  209.  
  210.                 if(GetPixel(hdc, x, y) != menuColor && x > menu.left)
  211.                 {
  212.                     currentBrush = CreateSolidBrush(GetPixel(hdc, x, y));
  213.                 }
  214.  
  215.                 ReleaseDC(hwnd, hdc);
  216.  
  217.                 if(x > wRect.right - 190 && y > wRect.top + 400 && x < wRect.right - 140 && y < wRect.top + 450)
  218.                 {
  219.                     object = rectangle;
  220.                 }
  221.                 else if(x > wRect.right - 90 && y > wRect.top + 400 && x < wRect.right - 40 && y < wRect.top + 450)
  222.                 {
  223.                     object = ellipse;
  224.                 }
  225.                 else if(x > wRect.right - 190 && y > wRect.top + 470 && x < wRect.right - 140 && y < wRect.top + 520)
  226.                 {
  227.                     object = triangle;
  228.                 }  
  229.             }
  230.             break;
  231.  
  232.         case WM_LBUTTONUP:
  233.             {
  234.                 x2 = LOWORD(lParam);
  235.                 y2 = HIWORD(lParam);
  236.  
  237.                 if(x2 < menu.left && x < menu.left)
  238.                 {
  239.                     InvalidateRect(hwnd, 0, false);
  240.                 }
  241.             }
  242.             break;
  243.  
  244.         case WM_SIZE:
  245.             {
  246.                 InvalidateRect(hwnd, &menu, true);
  247.                 UpdateWindow(hwnd);
  248.             }
  249.             break;
  250.  
  251.         default:
  252.         return DefWindowProc( hwnd, uMsg, wParam, lParam );
  253.     }
  254.      
  255.     return 0;
  256. }
  257.  
  258. void IconRect(HDC hdc, int left, int top, int right, int bottom)
  259. {
  260.     HBRUSH brush = CreateSolidBrush(RGB(255, 255, 255));
  261.     HBRUSH brush2 = CreateSolidBrush(RGB(0, 0, 0));
  262.     HBRUSH def = (HBRUSH) SelectObject(hdc, brush);
  263.    
  264.     Rectangle(hdc, left, top, right, bottom);
  265.     SelectObject(hdc, brush2);
  266.     Rectangle(hdc, left + (right-left)*0.15, top + (bottom - top)*0.15, right - (right-left)*0.15, bottom - (bottom - top)*0.15);
  267.  
  268.     SelectObject(hdc, def);
  269.     DeleteObject(brush);
  270.     DeleteObject(brush2);
  271. }
  272.  
  273. void IconEllipse(HDC hdc, int left, int top, int right, int bottom)
  274. {
  275.     HBRUSH brush = CreateSolidBrush(RGB(255, 255, 255));
  276.     HBRUSH brush2 = CreateSolidBrush(RGB(0, 0, 0));
  277.     HBRUSH def = (HBRUSH) SelectObject(hdc, brush);
  278.    
  279.     Rectangle(hdc, left, top, right, bottom);
  280.     SelectObject(hdc, brush2);
  281.     Ellipse(hdc, left + (right-left)*0.15, top + (bottom - top)*0.15, right - (right-left)*0.15, bottom - (bottom - top)*0.15);
  282.  
  283.     SelectObject(hdc, def);
  284.     DeleteObject(brush);
  285.     DeleteObject(brush2);
  286. }
  287.  
  288. void IconTriangle(HDC hdc, int left, int top, int right, int bottom)
  289. {
  290.     POINT pts[3];
  291.     pts[0].x = left + (right-left)/2;
  292.     pts[0].y = top + (bottom - top)*0.15;
  293.     pts[1].x = left + (right-left)*22/25;
  294.     pts[1].y = top + (bottom - top)*0.85;
  295.     pts[2].x = left + (right-left)*3/25;
  296.     pts[2].y = top + (bottom - top)*0.85;
  297.  
  298.     HBRUSH brush = CreateSolidBrush(RGB(255, 255, 255));
  299.     HBRUSH brush2 = CreateSolidBrush(RGB(0, 0, 0));
  300.     HBRUSH def = (HBRUSH) SelectObject(hdc, brush);
  301.    
  302.     Rectangle(hdc, left, top, right, bottom);
  303.     SelectObject(hdc, brush2);
  304.     Polygon(hdc, pts , 3);
  305.  
  306.     SelectObject(hdc, def);
  307.     DeleteObject(brush);
  308.     DeleteObject(brush2);
  309. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement