Advertisement
Guest User

CompModel Laba1

a guest
Apr 4th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <windows.h>
  2. #include <tchar.h>
  3.  
  4. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  5. TCHAR WinName[] = _T("MainFrame");
  6.  
  7. int APIENTRY WinMain(HINSTANCE This, HINSTANCE Prev, LPSTR cmd, int mode)
  8. {
  9.     HWND hWnd;
  10.     MSG msg;
  11.     WNDCLASS wc;
  12.  
  13.     wc.hInstance = This;
  14.     wc.lpszClassName = WinName;
  15.     wc.lpfnWndProc = WndProc;
  16.     wc.style = CS_HREDRAW | CS_VREDRAW;
  17.     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  18.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  19.     wc.lpszMenuName = NULL;
  20.     wc.cbClsExtra = 0;
  21.     wc.cbWndExtra = 0;
  22.  
  23.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  24.    
  25.     if(!RegisterClass(&wc))
  26.         return 0;
  27.  
  28.     hWnd = CreateWindow(WinName, _T("Karkas Windows-application"), WS_OVERLAPPEDWINDOW,
  29.                         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
  30.                         HWND_DESKTOP, NULL, This, NULL);
  31.  
  32.     ShowWindow(hWnd, mode);
  33.    
  34.     while(GetMessage(&msg, NULL, 0, 0))
  35.     {
  36.         TranslateMessage(&msg);
  37.         DispatchMessage(&msg);
  38.     }
  39.  
  40.     return 0;
  41. }
  42.  
  43. void paintCell(HWND* hWnd, int sx, int sy)
  44. {
  45.     PAINTSTRUCT ps;
  46.     HDC hdc = BeginPaint(*hWnd, &ps);
  47.  
  48.     for(int x = 0; x < sx; x += sx/10 )
  49.     {
  50.         MoveToEx(hdc, x, 0, NULL);
  51.         LineTo(hdc, x, sy);
  52.     }
  53.  
  54.     for(int y = 0; y < sy; y += sy/10 )
  55.     {
  56.         MoveToEx(hdc, 0, y, NULL);
  57.         LineTo(hdc, sx, y);
  58.     }
  59.  
  60.     EndPaint(*hWnd, &ps);
  61. }
  62.  
  63. void paintTriangle(HWND* hWnd, int sx, int sy)
  64. {
  65.     PAINTSTRUCT ps;
  66.     HDC hdc = BeginPaint(*hWnd, &ps);
  67.  
  68.     int width = sx;
  69.     int height = sy;
  70.     int stX = (width - height) / 2;
  71.     int stY = height;
  72.  
  73.     int lbX = stX;
  74.     int lbY = stY-50;
  75.  
  76.     int tX = stX+(height/2);
  77.     int tY = stY-450;
  78.  
  79.     int rbX = stX+height;
  80.     int rbY = stY-50;
  81.  
  82.  
  83.     BeginPath(hdc);
  84.     HBRUSH blue = CreateSolidBrush(RGB(0,0,255));
  85.     HBRUSH black = CreateSolidBrush(RGB(0,0,0));
  86.     SelectObject(hdc, blue);
  87.     FillPath(hdc);
  88.     EndPath(hdc);
  89.  
  90.  
  91.     for( int i = 0; i < width/2; i += 10 )
  92.     {
  93.         MoveToEx(hdc, lbX+i, lbY, NULL);
  94.         LineTo(hdc, tX, tY);
  95.  
  96.         MoveToEx(hdc, tX, tY, NULL);
  97.         LineTo(hdc, rbX-i, rbY);
  98.  
  99.         MoveToEx(hdc, rbX-i, rbY, NULL);
  100.         LineTo(hdc, lbX+i, lbY);
  101.     }
  102.     Ellipse(hdc, lbX+150, lbY-250, rbX-150, rbY-100);
  103.  
  104.     SelectObject(hdc, black);
  105.     FillPath(hdc);
  106.     Ellipse(hdc, lbX+300, lbY-235, rbX-300, rbY-125);
  107.  
  108.     EndPaint(*hWnd, &ps);
  109. }
  110.  
  111. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  112. {
  113.     int x = 0;
  114.     int y = 0;
  115.     static int sx = 0;
  116.     static int sy = 0;
  117.  
  118.     if(message == WM_DESTROY)
  119.     {
  120.         PostQuitMessage(0);
  121.     }
  122.     else if(message == WM_SIZE)
  123.     {
  124.         sx = LOWORD(lParam);
  125.         sy = HIWORD(lParam);
  126.     }
  127.     else if(message == WM_PAINT)
  128.     {
  129.         paintTriangle(&hWnd, sx, sy);
  130.     }
  131.     else
  132.     {
  133.         return DefWindowProc(hWnd, message, wParam, lParam);
  134.     }
  135.  
  136.     return 0;
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement