Advertisement
Guest User

Code of eclipse

a guest
May 18th, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 13.02 KB | None | 0 0
  1. #if defined(UNICODE) && !defined(_UNICODE)
  2.     #define _UNICODE
  3. #elif defined(_UNICODE) && !defined(UNICODE)
  4.     #define UNICODE
  5. #endif
  6.  
  7. #include <tchar.h>
  8. #include <windows.h>
  9. #include <cmath>
  10. #include <string>
  11. #include <sstream>
  12.  
  13. using namespace std;
  14.  
  15. int calc(HWND text);
  16.  
  17. HWND hText, hText2, hText3,g_hbutton,hwnd,hwnd1;
  18. HDC hdc;
  19. PAINTSTRUCT ps;
  20.  
  21. /*  Declare Windows procedure  */
  22. LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
  23.  
  24. /*  Make the class name into a global variable  */
  25. TCHAR szClassName[ ] = _T("CodeBlocksWindowsApp");
  26.  
  27. int WINAPI WinMain (HINSTANCE hThisInstance,
  28.                      HINSTANCE hPrevInstance,
  29.                      LPSTR lpszArgument,
  30.                      int nCmdShow)
  31. {
  32.     /* This is the handle for our window */
  33.     MSG messages;            /* Here messages to the application are saved */
  34.     WNDCLASSEX wincl;        /* Data structure for the windowclass */
  35.  
  36.     /* The Window structure */
  37.     wincl.hInstance = hThisInstance;
  38.     wincl.lpszClassName = szClassName;
  39.     wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
  40.     wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
  41.     wincl.cbSize = sizeof (WNDCLASSEX);
  42.  
  43.     /* Use default icon and mouse-pointer */
  44.     wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  45.     wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
  46.     wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
  47.     wincl.lpszMenuName = NULL;                 /* No menu */
  48.     wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
  49.     wincl.cbWndExtra = 0;                      /* structure or the window instance */
  50.     /* Use Windows's default colour as the background of the window */
  51.     wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
  52.  
  53.     /* Register the window class, and if it fails quit the program */
  54.     if (!RegisterClassEx (&wincl))
  55.         return 0;
  56.  
  57.     /* The class is registered, let's create the program*/
  58.     hwnd = CreateWindowEx (
  59.            0,                   /* Extended possibilites for variation */
  60.            szClassName,         /* Classname */
  61.            _T("ACBR"),       /* Title Text */
  62.            WS_OVERLAPPEDWINDOW, /* default window */
  63.            CW_USEDEFAULT,       /* Windows decides the position */
  64.            CW_USEDEFAULT,       /* where the window ends up on the screen */
  65.            300,                 /* The programs width */
  66.            300,                 /* and height in pixels */
  67.            HWND_DESKTOP,        /* The window is a child-window to desktop */
  68.            NULL,                /* No menu */
  69.            hThisInstance,       /* Program Instance handler */
  70.            NULL                 /* No Window Creation data */
  71.            );
  72.     hwnd1 = CreateWindowEx (
  73.            0,                   /* Extended possibilites for variation */
  74.            szClassName,         /* Classname */
  75.            _T("ACBR"),       /* Title Text */
  76.            WS_OVERLAPPEDWINDOW, /* default window */
  77.            CW_USEDEFAULT,       /* Windows decides the position */
  78.            CW_USEDEFAULT,       /* where the window ends up on the screen */
  79.            800,                 /* The programs width */
  80.            800,                 /* and height in pixels */
  81.            HWND_DESKTOP,        /* The window is a child-window to desktop */
  82.            NULL,                /* No menu */
  83.            hThisInstance,       /* Program Instance handler */
  84.            NULL                 /* No Window Creation data */
  85.            );
  86.  
  87.         g_hbutton = CreateWindowEx( 0, "BUTTON", "paint", WS_CHILD |  WS_VISIBLE,0, 0, 150, 30, hwnd, NULL, hThisInstance, NULL );
  88.         //hText = CreateWindowEx( WS_EX_CLIENTEDGE, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER,0, 40, 150, 20, hwnd, NULL, hThisInstance, NULL );
  89.         //hText2 = CreateWindowEx( WS_EX_CLIENTEDGE, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER,0, 61, 150, 20, hwnd, NULL, hThisInstance, NULL );
  90.         //hText3 = CreateWindowEx( WS_EX_CLIENTEDGE, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER,0, 82, 150, 20, hwnd, NULL, hThisInstance, NULL );
  91.         //SetWindowText( hText, "  a" );
  92.         //SetWindowText( hText2, "  b" );
  93.         //SetWindowText( hText3, "  c" );
  94.     /* Make the window visible on the screen */
  95.     ShowWindow (hwnd, nCmdShow);
  96.  
  97.     /* Run the message loop. It will run until GetMessage() returns 0 */
  98.     while (GetMessage (&messages, NULL, 0, 0))
  99.     {
  100.         /* Translate virtual-key messages into character messages */
  101.         TranslateMessage(&messages);
  102.         /* Send message to WindowProcedure */
  103.         DispatchMessage(&messages);
  104.     }
  105.  
  106.     /* The program return-value is 0 - The value that PostQuitMessage() gave */
  107.     return messages.wParam;
  108. }
  109.  
  110. //POCZATEK STRUKTUR
  111. struct Points
  112. {
  113.     int pointsX,pointsY;
  114.     Points *next;
  115.     Points()
  116.         {
  117.             next = 0;
  118.         }
  119. };
  120.  
  121. struct Lists
  122. {
  123.         Points *first;
  124.         Points *actualy;
  125.         int number;
  126.  
  127.         void addPoints(int pointsX,int pointsY)
  128.         {
  129.             Points *neww = new Points;
  130.  
  131.             neww->pointsX = pointsX;
  132.             neww->pointsY = pointsY;
  133.  
  134.             if(first==0)
  135.             {
  136.                 first = neww;
  137.             }else{
  138.                 Points *temp = first;
  139.                 while(temp->next)
  140.                 {
  141.                     temp = temp->next;
  142.                 }
  143.                 temp->next = neww;
  144.                 neww->next = 0;
  145.             }
  146.         }
  147.         Lists()
  148.         {
  149.              first = 0;
  150.         }
  151.  
  152. int parametr()
  153. {
  154.  
  155.     Points *temp = first;
  156.  
  157.     while (temp)
  158.     {
  159.         temp=temp->next;
  160.     }
  161. }
  162.  
  163. };
  164. Lists *datebase = new Lists;
  165.  
  166. //KONIEC STRUKTUR
  167.  
  168. /*  This function is called by the Windows function DispatchMessage()  */
  169.  
  170. LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  171. {
  172.     switch (message)                  /* handle the messages */
  173.     {
  174.         case WM_DESTROY:
  175.             PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
  176.             break;
  177.         case WM_COMMAND:
  178.             {
  179.                 if(( HWND ) lParam == g_hbutton )
  180.                 {
  181.                     ShowWindow(hwnd,SW_HIDE);
  182.                     ShowWindow(hwnd1,5);
  183.  
  184.                     int tabP[17][36][4];
  185.                     int tabP1[17][36][4];
  186.                     int Top[4], Bottom[4];
  187.                     int Top1[4], Bottom1[4];
  188.                     float a,a1,b,b1,c,z;
  189.                     int i,j;
  190.  
  191.  
  192.                     a=300;
  193.                     b=240;
  194.                     c=200;
  195.                     hdc=BeginPaint(hwnd1,&ps);
  196.                     Top[1]=0;
  197.                     Top[2]=0;
  198.                     Top[3]=round(c);
  199.                     for (i=16;i>=0;i--)
  200.                     {
  201.                         z=sin((i-8)*M_PI/18);
  202.                         b1=b*sqrt(1-z*z);
  203.                         a1=a*sqrt(1-z*z);
  204.                         z=c*z;
  205.                             for (j=0; j<=35; j++)
  206.                             {
  207.                                 tabP[i][j][1]=round(a1*cos(j*M_PI/18));
  208.                                 tabP[i][j][2]=round(b1*sin(j*M_PI/18));
  209.                                 tabP[i][j][3]=round(z);
  210.                             }
  211.  
  212.                     }
  213.                     Bottom[1]=0;
  214.                     Bottom[2]=0;
  215.                     Bottom[3]=-round(c);
  216.  
  217.                    
  218.                     float alpha;
  219.                     alpha = M_PI/4;
  220.                     Top1[1] = Top[1];
  221.                     Top1[2] = round(Top[2]*cos(alpha)+Top[3]*sin(alpha));
  222.                     Top1[3] = round(-Top[2]*sin(alpha)+Top[3]*cos(alpha));
  223.  
  224.                     for (i=16;i>=0;i--)
  225.                     {
  226.                         for (j=0; j<=35; j++)
  227.                         {
  228.                             tabP1[i][j][1]=tabP[i][j][1];
  229.                             tabP1[i][j][2]=round(tabP[i][j][2]*cos(alpha)+tabP[i][j][3]*sin(alpha));
  230.                             tabP1[i][j][3]=round(-tabP[i][j][2]*sin(alpha)+tabP[i][j][3]*cos(alpha));
  231.                         }
  232.  
  233.                     }
  234.  
  235.                     Bottom1[1] = Bottom[1];
  236.                     Bottom1[2] = round(Bottom[2]*cos(alpha)+Bottom[3]*sin(alpha));
  237.                     Bottom1[3] = round(-Bottom[2]*sin(alpha)+Bottom[3]*cos(alpha));
  238.  
  239.                     alpha = M_PI/3;
  240.                     Top[1] = round(Top1[1]*cos(alpha)+Top1[2]*sin(alpha));
  241.                     Top[2] = round(-Top1[1]*sin(alpha)+Top1[2]*cos(alpha));
  242.                     Top[3] = Top1[3];
  243.                     for (i=16;i>=0;i--)
  244.                     {
  245.                         for (j=0; j<=35; j++)
  246.                         {
  247.                             tabP[i][j][1]=round(tabP1[i][j][1]*cos(alpha)+tabP1[i][j][2]*sin(alpha));
  248.                             tabP[i][j][2]=round(-tabP1[i][j][1]*sin(alpha)+tabP1[i][j][2]*cos(alpha));
  249.                             tabP[i][j][3]=tabP1[i][j][3];
  250.                         }
  251.                     }
  252.                     Bottom[1] = round(Bottom1[1]*cos(alpha)+Bottom1[2]*sin(alpha));
  253.                     Bottom[2] = round(-Bottom1[1]*sin(alpha)+Bottom1[2]*cos(alpha));
  254.                     Bottom[3] = Bottom1[3];
  255.  
  256.  
  257.                     Top1[1] = round(Top[1]+400);
  258.                     Top1[2] = round(Top[2]+400);
  259.                     Top1[3] = Top[3];
  260.  
  261.                     for (i=16;i>=0;i--)
  262.                     {
  263.                         for (j=0; j<=35; j++)
  264.                         {
  265.                             tabP1[i][j][1]=round(tabP[i][j][1]+400);
  266.                             tabP1[i][j][2]=round(tabP[i][j][2]+400);
  267.                             tabP1[i][j][3]=tabP[i][j][3];
  268.                         }
  269.                     }
  270.                     Bottom1[1] = round(Bottom[1]+400);
  271.                     Bottom1[2] = round(Bottom[2]+400);
  272.                     Bottom1[3] = Bottom[3];
  273.  
  274.                     Top[1] = Top1[1];
  275.                     Top[2] = Top1[2];
  276.                     Top[3] = 0;
  277.  
  278.                     for (i=16;i>=0;i--)
  279.                     {
  280.                         for (j=0; j<=35; j++)
  281.                         {
  282.                             tabP[i][j][1]=tabP1[i][j][1];
  283.                             tabP[i][j][2]=tabP1[i][j][2];
  284.                             tabP[i][j][3]=0;
  285.                         }
  286.                     }
  287.                     Bottom[1] = Bottom1[1];
  288.                     Bottom[2] = Bottom1[2];
  289.                     Bottom[3] = 0;
  290.  
  291.                     datebase->addPoints(Top[1],Top[2]);
  292.                     datebase->number=1;
  293.                     for(int i=0; i<=35; i++)
  294.                     {
  295.                         if(i%2==0)
  296.                         {
  297.                             for(int j=16;j>=0;j--)
  298.                             {
  299.                                 datebase->addPoints(tabP[j][i][1],tabP[j][i][2]);
  300.                                 datebase->number++;
  301.                             }
  302.                             datebase->addPoints(Bottom[1],Bottom[2]);
  303.                             datebase->number++;
  304.                         }
  305.                         else
  306.                         {
  307.  
  308.                             for(int j=0;j<=16;j++)
  309.                             {
  310.                                 datebase->addPoints(tabP[j][i][1],tabP[j][i][2]);
  311.                                 datebase->number++;
  312.                             }
  313.                             datebase->addPoints(Top[1],Top[2]);
  314.                             datebase->number++;
  315.                         }
  316.  
  317.                     }
  318.  
  319.  
  320.                     for(int i =16;i>=0;i--)
  321.                     {
  322.                         datebase->addPoints(tabP[i][0][1],tabP[i][0][2]);
  323.                         datebase->number++;
  324.                         for(int j=1;j<=35;j++)
  325.                         {
  326.                             datebase->addPoints(tabP[i][j][1],tabP[i][j][2]);
  327.                             datebase->number++;
  328.                         }
  329.                         datebase->addPoints(tabP[i][0][1],tabP[i][0][2]);
  330.                         datebase->number++;
  331.                     }
  332.  
  333.  
  334.                     datebase->actualy=datebase->first;
  335.                     MoveToEx(hdc,datebase->actualy->pointsX,datebase->actualy->pointsY,0);
  336.                     for(int i=1;i<datebase->number;i++)
  337.                     {
  338.                         datebase->actualy=datebase->actualy->next;
  339.                         LineTo(hdc,datebase->actualy->pointsX,datebase->actualy->pointsY);
  340.                     }
  341.  
  342.                     delete datebase;
  343.                     EndPaint(hwnd1,&ps);
  344.                 }
  345.             }
  346.             break;
  347.         default:                      /* for messages that we don't deal with */
  348.             return DefWindowProc (hwnd, message, wParam, lParam);
  349.     }
  350.  
  351.     return 0;
  352. }
  353.  
  354. int calc(HWND text)
  355. {
  356.     DWORD lengthh = GetWindowTextLength( text );
  357.     LPSTR Bufor =( LPSTR ) GlobalAlloc( GPTR, lengthh + 1 );
  358.     GetWindowText( text, Bufor, lengthh + 1 );
  359.     int i;
  360.     istringstream iss(Bufor);
  361.     iss >> i;
  362.  
  363.     return i;
  364. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement