Advertisement
Guest User

Untitled

a guest
May 30th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // draw.cpp : Defines the entry point for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "draw2.h"
  6. #include <vector>
  7. #include <fstream>
  8. #include <cstdio>
  9.  
  10. #define MAX_LOADSTRING 100
  11. #define TMR_1 1
  12.  
  13. // Global Variables:
  14. HINSTANCE hInst;                                // current instance
  15. TCHAR szTitle[MAX_LOADSTRING];                  // The title bar text
  16. TCHAR szWindowClass[MAX_LOADSTRING];            // the main window class name
  17.  
  18. const int liczba_pomiarow = 2485;
  19. const int liczba_pominiec = 100;
  20. const int powtorzenia = liczba_pomiarow - liczba_pominiec;
  21. double wektor_przyspieszenie[powtorzenia];
  22. double wektor_droga[powtorzenia];
  23. double wektor_predkosc[powtorzenia];
  24.  
  25. INT value;
  26.  
  27. // buttons
  28. HWND hwndButton;
  29.  
  30. // sent data
  31. int col = 0;
  32. std::vector<Point> data;
  33. RECT drawArea1 = { 0, 0, 150, 2000 };
  34. RECT drawArea2 = { 50, 400, 150, 200 };
  35. RECT drawArea3 = { 100, 800, 150, 200 };
  36.  
  37.  
  38. // Forward declarations of functions included in this code module:
  39. ATOM                MyRegisterClass(HINSTANCE hInstance);
  40. BOOL                InitInstance(HINSTANCE, int);
  41. LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
  42. INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
  43. INT_PTR CALLBACK    Buttons(HWND, UINT, WPARAM, LPARAM);
  44.  
  45. void wczytaj() {
  46.  
  47.     std::ifstream plik;
  48.     plik.open("outputRobotForwardA01.log");
  49.  
  50.     double wynik;
  51.     double bufor;
  52.  
  53.     int miejsce = 1;
  54.  
  55.     for (int i = 0; i < liczba_pominiec * 12; i++)  // pominiecie  n linijek
  56.         plik >> bufor;
  57.  
  58.     wektor_przyspieszenie[0] = 0;
  59.  
  60.     for (int j = 0; j < powtorzenia; j++) {
  61.  
  62.         for (int k = 0; k < 3; k++)
  63.             plik >> bufor;
  64.  
  65.         plik >> wynik;
  66.  
  67.         wektor_przyspieszenie[miejsce] = wynik;
  68.         miejsce++;
  69.  
  70.         for (int k = 4; k < 12; k++)
  71.             plik >> bufor;
  72.     }
  73. }
  74.  
  75. void calki() {
  76.  
  77.     for (int i = 0; i< powtorzenia; i++)
  78.         wektor_predkosc[i] = (wektor_przyspieszenie[i] + wektor_przyspieszenie[i + 1]) / 2;
  79.  
  80.     for (int j = 0; j< powtorzenia; j++)
  81.         wektor_droga[j] = (wektor_predkosc[j] + wektor_predkosc[j + 1]) / 2;
  82.  
  83. }
  84.  
  85.  
  86.  
  87.  
  88. void MyOnPaint(HDC hdc)
  89. {
  90.     Graphics graphics(hdc);
  91.     Pen pen(Color(255, 0, 0, 255));
  92.     Pen pen2(Color(255, 25 * col, 0, 255));
  93.  
  94.     for (int i = 1; i < 100; i++)
  95.         graphics.DrawLine(&pen2, data[i - 1].X, data[i - 1].Y, data[i].X, data[i].Y);
  96. }
  97.  
  98. void repaintWindow(HWND hWnd, HDC &hdc, PAINTSTRUCT &ps, RECT *drawArea)
  99. {
  100.     if (drawArea == NULL)
  101.         InvalidateRect(hWnd, NULL, TRUE); // repaint all
  102.     else
  103.         InvalidateRect(hWnd, drawArea, TRUE); //repaint drawArea
  104.     hdc = BeginPaint(hWnd, &ps);
  105.     MyOnPaint(hdc);
  106.     EndPaint(hWnd, &ps);
  107. }
  108.  
  109.  
  110. void inputData()
  111. {
  112.     data.push_back(Point(0, 0));
  113.     for (int i = 1; i < 100; i++) {
  114.         data.push_back(Point(2 * i + 1, 100* wektor_przyspieszenie[i]));
  115.     }
  116. }
  117.  
  118.  
  119.  
  120. int OnCreate(HWND window)
  121. {
  122.     inputData();
  123.     return 0;
  124. }
  125.  
  126.  
  127. // main function (exe hInstance)
  128. int APIENTRY _tWinMain(HINSTANCE hInstance,
  129.     HINSTANCE hPrevInstance,
  130.     LPTSTR    lpCmdLine,
  131.     int       nCmdShow)
  132. {
  133.     UNREFERENCED_PARAMETER(hPrevInstance);
  134.     UNREFERENCED_PARAMETER(lpCmdLine);
  135.  
  136.     // TODO: Place code here.
  137.     MSG msg;
  138.     HACCEL hAccelTable;
  139.  
  140.     value = 0;
  141.  
  142.  
  143.     GdiplusStartupInput gdiplusStartupInput;
  144.     ULONG_PTR           gdiplusToken;
  145.     GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
  146.  
  147.     // Initialize global strings
  148.     LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  149.     LoadString(hInstance, IDC_DRAW, szWindowClass, MAX_LOADSTRING);
  150.     MyRegisterClass(hInstance);
  151.  
  152.  
  153.  
  154.     // Perform application initialization:
  155.     if (!InitInstance(hInstance, nCmdShow))
  156.     {
  157.         return FALSE;
  158.     }
  159.  
  160.     hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_DRAW));
  161.  
  162.     // Main message loop:
  163.     while (GetMessage(&msg, NULL, 0, 0))
  164.     {
  165.         if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  166.         {
  167.             TranslateMessage(&msg);
  168.             DispatchMessage(&msg);
  169.         }
  170.     }
  171.  
  172.     GdiplusShutdown(gdiplusToken);
  173.  
  174.     return (int)msg.wParam;
  175. }
  176.  
  177.  
  178.  
  179. //
  180. //  FUNCTION: MyRegisterClass()
  181. //
  182. //  PURPOSE: Registers the window class.
  183. //
  184. //  COMMENTS:
  185. //
  186. //    This function and its usage are only necessary if you want this code
  187. //    to be compatible with Win32 systems prior to the 'RegisterClassEx'
  188. //    function that was added to Windows 95. It is important to call this function
  189. //    so that the application will get 'well formed' small icons associated
  190. //    with it.
  191. //
  192. ATOM MyRegisterClass(HINSTANCE hInstance)
  193. {
  194.     WNDCLASSEX wcex;
  195.  
  196.     wcex.cbSize = sizeof(WNDCLASSEX);
  197.  
  198.     wcex.style = CS_HREDRAW | CS_VREDRAW;
  199.     wcex.lpfnWndProc = WndProc;
  200.     wcex.cbClsExtra = 0;
  201.     wcex.cbWndExtra = 0;
  202.     wcex.hInstance = hInstance;
  203.     wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_DRAW));
  204.     wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  205.     wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  206.     wcex.lpszMenuName = MAKEINTRESOURCE(IDC_DRAW);
  207.     wcex.lpszClassName = szWindowClass;
  208.     wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
  209.  
  210.     return RegisterClassEx(&wcex);
  211. }
  212.  
  213. //
  214. //   FUNCTION: InitInstance(HINSTANCE, int)
  215. //
  216. //   PURPOSE: Saves instance handle and creates main window
  217. //
  218. //   COMMENTS:
  219. //
  220. //        In this function, we save the instance handle in a global variable and
  221. //        create and display the main program window.
  222. //
  223. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  224. {
  225.     HWND hWnd;
  226.  
  227.  
  228.     hInst = hInstance; // Store instance handle (of exe) in our global variable
  229.  
  230.                        // main window
  231.     hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
  232.         CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
  233.  
  234.     // create button and store the handle                                                      
  235.  
  236.     hwndButton = CreateWindow(TEXT("button"),                      // The class name required is button
  237.         TEXT("Przyspieszenie"),                  // the caption of the button
  238.         WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,  // the styles
  239.         500, 400,                                  // the left and top co-ordinates
  240.         120, 50,                              // width and height
  241.         hWnd,                                 // parent window handle
  242.         (HMENU)ID_BUTTON1,                   // the ID of your button
  243.         hInstance,                            // the instance of your application
  244.         NULL);                               // extra bits you dont really need
  245.  
  246.     hwndButton = CreateWindow(TEXT("button"),                      // The class name required is button
  247.         TEXT("Droga"),                  // the caption of the button
  248.         WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,  // the styles
  249.         100, 400,                                  // the left and top co-ordinates
  250.         120, 50,                              // width and height
  251.         hWnd,                                 // parent window handle
  252.         (HMENU)ID_BUTTON2,                   // the ID of your button
  253.         hInstance,                            // the instance of your application
  254.         NULL);                               // extra bits you dont really need
  255.  
  256.     hwndButton = CreateWindow(TEXT("button"),                      // The class name required is button
  257.         TEXT("Predkosc"),                  // the caption of the button
  258.         WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,  // the styles
  259.         300, 400,                                  // the left and top co-ordinates
  260.         120, 50,                              // width and height
  261.         hWnd,                                 // parent window handle
  262.         (HMENU)ID_BUTTON3,                   // the ID of your button
  263.         hInstance,                            // the instance of your application
  264.         NULL);
  265.     // create button and store the handle                                                      
  266.  
  267.  
  268.     OnCreate(hWnd);
  269.  
  270.     if (!hWnd)
  271.     {
  272.         return FALSE;
  273.     }
  274.  
  275.     ShowWindow(hWnd, nCmdShow);
  276.     UpdateWindow(hWnd);
  277.  
  278.  
  279.  
  280.     return TRUE;
  281. }
  282.  
  283.  
  284.  
  285. //
  286. //  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
  287. //
  288. //  PURPOSE:  Processes messages for the main window.
  289. //
  290. //  WM_COMMAND  - process the application menu
  291. //  WM_PAINT    - Paint the main window (low priority)
  292. //  WM_DESTROY  - post a quit message and return
  293. //
  294. //
  295. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  296. {
  297.     int wmId, wmEvent;
  298.     PAINTSTRUCT ps;
  299.     HDC hdc;
  300.  
  301.     switch (message)
  302.     {
  303.     case WM_COMMAND:
  304.         wmId = LOWORD(wParam);
  305.         wmEvent = HIWORD(wParam);
  306.  
  307.         // MENU & BUTTON messages
  308.         // Parse the menu selections:
  309.         switch (wmId)
  310.         {
  311.         case IDM_ABOUT:
  312.             DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
  313.             break;
  314.         case IDM_EXIT:
  315.             DestroyWindow(hWnd);
  316.             break;
  317.         case ID_BUTTON1:
  318.             col++;
  319.             if (col > 10)
  320.                 col = 0;
  321.             repaintWindow(hWnd, hdc, ps, &drawArea1);
  322.             break;
  323.         case ID_BUTTON2:
  324.             repaintWindow(hWnd, hdc, ps, NULL);
  325.             break;
  326.  
  327.         default:
  328.             return DefWindowProc(hWnd, message, wParam, lParam);
  329.         }
  330.         break;
  331.     case WM_PAINT:
  332.         hdc = BeginPaint(hWnd, &ps);
  333.         // TODO: Add any drawing code here (not depend on timer, buttons)
  334.         EndPaint(hWnd, &ps);
  335.         break;
  336.     case WM_DESTROY:
  337.         PostQuitMessage(0);
  338.         break;
  339.     default:
  340.         return DefWindowProc(hWnd, message, wParam, lParam);
  341.     }
  342.     return 0;
  343. }
  344.  
  345. // Message handler for about box.
  346. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  347. {
  348.     UNREFERENCED_PARAMETER(lParam);
  349.     switch (message)
  350.     {
  351.     case WM_INITDIALOG:
  352.         return (INT_PTR)TRUE;
  353.  
  354.     case WM_COMMAND:
  355.         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  356.         {
  357.             EndDialog(hDlg, LOWORD(wParam));
  358.             return (INT_PTR)TRUE;
  359.         }
  360.         break;
  361.     }
  362.     return (INT_PTR)FALSE;
  363. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement