Advertisement
rowers

figury1

Mar 26th, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.73 KB | None | 0 0
  1. //---------------------------------------------------------------------------
  2. #include <windows.h>
  3. #pragma hdrstop
  4. //---------------------------------------------------------------------------
  5.  
  6. #define MAXF 20
  7.  
  8. typedef enum {kwadrat, kolo, prostokat, trojkat, tekst, linia, elipsa} typ_figury;
  9.  
  10. struct punkt {
  11.   int x,y;
  12. };
  13.  
  14. struct kwadrat {
  15.   struct punkt w1;
  16.   int bok;
  17. };
  18.  
  19. struct prostokat {
  20.   struct punkt w1, w2;
  21. };
  22.  
  23.  
  24. struct tekst {
  25.   struct punkt w1;
  26.   char *txt;
  27. };
  28.  
  29. struct linia {
  30.     struct punkt w1, w2;
  31. };
  32. struct elipsa {
  33.     struct punkt w1, w2;
  34. };
  35.  
  36. struct figura {
  37.   typ_figury figura;
  38.   union {
  39.     struct kwadrat kwadrat;
  40.     struct prostokat prostokat;
  41.     struct tekst tekst;
  42.     struct linia linia;
  43.     struct elipsa elipsa;
  44.   } ;
  45. };
  46.  
  47. struct figura figury[MAXF];
  48. int last;
  49.  
  50. void dodaj_kwadrat( int x, int y, int b) {
  51.   figury[last].figura = kwadrat;
  52.   figury[last].kwadrat.w1.x=x;
  53.   figury[last].kwadrat.w1.y=y;
  54.   figury[last].kwadrat.bok=b;
  55.   last++;
  56. }
  57.  
  58. void dodaj_tekst( int x, int y, char *txt) {
  59.   figury[last].figura = tekst;
  60.   figury[last].tekst.w1.x=x;
  61.   figury[last].tekst.w1.y=y;
  62.   figury[last].tekst.txt = txt;
  63.   last++;
  64. }
  65.  
  66. void dodaj_linia( int x, int y, int x1, int y1) {
  67.   figury[last].figura = linia;
  68.   figury[last].linia.w1.x=x;
  69.   figury[last].linia.w1.y=y;
  70.   figury[last].linia.w2.x=x1;
  71.   figury[last].linia.w2.x=y1;
  72.  
  73.   last++;
  74. }
  75. void dodaj_elipsa( int x, int y, int x1, int y1) {
  76.   figury[last].figura = elipsa;
  77.   figury[last].elipsa.w1.x=x;
  78.   figury[last].elipsa.w1.y=y;
  79.   figury[last].elipsa.w2.x=x1;
  80.   figury[last].elipsa.w2.x=y1;
  81.  
  82.   last++;
  83. }
  84.  
  85.  
  86. LRESULT CALLBACK WindowProc(HWND hWnd, UINT Msg,  WPARAM wParam, LPARAM lParam) {
  87.    PAINTSTRUCT ps;
  88.    int i;
  89.    HDC hdc;
  90.    RECT rt;
  91. int x, y, n;
  92.  
  93.     switch(Msg) {
  94.  
  95.     case WM_CREATE:
  96.         dodaj_kwadrat(10,10, 10);
  97.         //dodaj_kwadrat(50,50, 60);
  98.         dodaj_tekst(200,200, "Tekst");
  99.         dodaj_linia (500,10, 550,100);
  100.         dodaj_elipsa (200,100, 100,20);
  101.         // itd
  102.  
  103.         break;
  104.     case WM_PAINT:
  105.         hdc = BeginPaint(hWnd, &ps);
  106.  
  107.         for(i=0;i<last;i++)
  108.           switch (figury[i].figura) {
  109.             case kwadrat: {
  110.               RECT rect;
  111.               rect.left=figury[i].kwadrat.w1.x;
  112.               rect.top=figury[i].kwadrat.w1.y;
  113.               rect.right=figury[i].kwadrat.w1.x+figury[i].kwadrat.bok;
  114.               rect.bottom=figury[i].kwadrat.w1.y+figury[i].kwadrat.bok;
  115.               FillRect(hdc, &rect, (HBRUSH) (COLOR_BTNFACE+1) );
  116.               break;
  117.               }
  118.             case tekst: {
  119.               TextOut(hdc, figury[i].tekst.w1.x, figury[i].tekst.w1.y, figury[i].tekst.txt, strlen(figury[i].tekst.txt));
  120.               break;
  121.               }
  122.                        
  123.             case linia: {
  124.                 MoveToEx(hdc, figury[i].linia.w1.x, figury[i].linia.w1.y, (LPPOINT) NULL);
  125.                 LineTo(hdc, figury[i].linia.w2.x, figury[i].linia.w2.y);
  126.                 break;
  127.                         }
  128.             case elipsa: {
  129.               Ellipse(hdc, figury[i].elipsa.w1.x, figury[i].elipsa.w1.y, figury[i].linia.w2.x, figury[i].linia.w2.y);
  130.               }
  131.         }
  132.         EndPaint(hWnd, &ps);
  133.         break;
  134.     case WM_DESTROY:
  135.         PostQuitMessage(0);
  136.         return 0;
  137.     default:
  138.         break;
  139.     }
  140.  
  141.     return DefWindowProc(hWnd, Msg, wParam, lParam);
  142. }
  143. //---------------------------------------------------------------------------
  144. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
  145.  
  146.     // The variable that will define the window
  147.     WNDCLASS WndCls;
  148.     // The window's name
  149.     static char szAppName[] = "EdytorC3";
  150.     MSG Msg;
  151.  
  152.     // Filling out the structure that builds the window
  153.     WndCls.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
  154.     WndCls.lpfnWndProc = WindowProc;
  155.     WndCls.cbClsExtra = 0;
  156.     WndCls.cbWndExtra = 0;
  157.     WndCls.hInstance = hInstance;
  158.     WndCls.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  159.     WndCls.hCursor = LoadCursor(NULL, IDC_ARROW);
  160.     WndCls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  161.     WndCls.lpszMenuName = NULL;
  162.     WndCls.lpszClassName = szAppName;
  163.  
  164.     RegisterClass(&WndCls);
  165.  
  166.     CreateWindow(   szAppName,
  167.                     "Ćwiczenie C3 i C4",
  168.                     WS_OVERLAPPEDWINDOW | WS_VISIBLE,
  169.                     CW_USEDEFAULT,
  170.                     CW_USEDEFAULT,
  171.                     CW_USEDEFAULT,
  172.                     CW_USEDEFAULT,
  173.                     NULL,
  174.                     NULL,
  175.                     hInstance,
  176.                     NULL
  177.                   );
  178.  
  179.  
  180.     while( GetMessage(&Msg, NULL, 0, 0) )   {
  181.  
  182.         TranslateMessage(&Msg);
  183.         DispatchMessage(&Msg);
  184.     }
  185.  
  186.     return Msg.wParam;
  187. }
  188. //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement