Advertisement
Guest User

hg

a guest
May 19th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 12.04 KB | None | 0 0
  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 <cstdio>
  8. #include <fstream>
  9. #include <iostream>
  10.  
  11. #define MAX_LOADSTRING 100
  12. #define TMR_1 1
  13.  
  14. // Global Variables:
  15. HINSTANCE hInst;                                // current instance
  16. TCHAR szTitle[MAX_LOADSTRING];                  // The title bar text
  17. TCHAR szWindowClass[MAX_LOADSTRING];            // the main window class name
  18.  
  19. INT value;
  20.  
  21. // buttons
  22. HWND hwndButton;
  23.  
  24. // sent data
  25. int col = 0;
  26. std::vector<Point> datax;
  27. std::vector<Point> datay;
  28. std::vector<Point> dataz;
  29. RECT drawArea1 = { 100, 100, 500, 300 };
  30. RECT drawArea2 = { 100, 100, 800, 300 };
  31.  
  32. // Forward declarations of functions included in this code module:
  33. ATOM                MyRegisterClass(HINSTANCE hInstance);
  34. BOOL                InitInstance(HINSTANCE, int);
  35. LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
  36. INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
  37. INT_PTR CALLBACK    Buttons(HWND, UINT, WPARAM, LPARAM);
  38.  
  39. int tabx[567], taby[567], tabz[567];
  40.  
  41. int missedSamplesX = 100;
  42. int missedSamplesY = 111;
  43. int missedSamplesZ = 56;
  44.  
  45. void MyOnPaint(HDC hdc, int choose)
  46. {
  47.     Graphics graphics(hdc);
  48.     Pen pen(Color(255, 0, 0, 255));
  49.     Pen pen2(Color(255, 0, 55, 255));
  50.     Pen pen3(Color(255, 55, 0, 3));
  51.  
  52.    
  53.     if (choose == 1) {
  54.         for (int i = 1 ; i < datax.size() - missedSamplesX; i++)
  55.             graphics.DrawLine(&pen2, datax[i - 1].X+10, datax[i - 1].Y + 100, datax[i].X + 10, datax[i].Y + 100);
  56.     }
  57.     if (choose == 2)
  58.     for (int i = 1 + missedSamplesY; i < datay.size() - missedSamplesY; i++)
  59.         graphics.DrawLine(&pen2, datay[i - 1].X + 10, datay[i - 1].Y + 200, datay[i].X + 10, datay[i].Y + 200);
  60.     if (choose == 3)
  61.     for (int i = 1+ missedSamplesZ; i < dataz.size() - missedSamplesZ; i++)
  62.         graphics.DrawLine(&pen2, dataz[i - 1].X + 10, dataz[i - 1].Y + 300, dataz[i].X + 10, dataz[i].Y + 300);
  63.  
  64. }
  65.  
  66. void repaintWindow(HWND hWnd, HDC &hdc, PAINTSTRUCT &ps, RECT *drawArea, int choose)
  67. {
  68.  
  69.  
  70.         if (drawArea == NULL)
  71.             InvalidateRect(hWnd, NULL, TRUE); // repaint all
  72.  
  73.     else
  74.         InvalidateRect(hWnd, drawArea, TRUE); //repaint drawArea
  75.     hdc = BeginPaint(hWnd, &ps);
  76.     switch (choose) {
  77.     case 1:
  78.         MyOnPaint(hdc,1);
  79.         break;
  80.     case 2:
  81.         MyOnPaint(hdc, 2);
  82.         break;
  83.     case 3:
  84.         MyOnPaint(hdc, 3);
  85.         break;
  86.     }
  87.     EndPaint(hWnd, &ps);
  88. }
  89.  
  90. void inputData()
  91. {
  92.     datax.push_back(Point(0, 0));
  93.     for (int i = 1 + missedSamplesX; i < 567; i++) {
  94.         datax.push_back(Point(2.7 * (i - missedSamplesX) + 1, tabx[i - 1]));
  95.     }
  96. }
  97. void inputData2()
  98. {
  99.     datay.push_back(Point(0, 0));
  100.     for (int i = 1; i < 567; i++) {
  101.         datay.push_back(Point(3.4 * (i - missedSamplesY) + 1, taby[i - 1]));
  102.     }
  103. }
  104.  
  105. void inputData3()
  106. {
  107.     dataz.push_back(Point(0, 0));
  108.     for (int i = 1; i < 567; i++) {
  109.         dataz.push_back(Point(2.5 * (i - missedSamplesZ) + 1, tabz[i - 1]));
  110.     }
  111. }
  112.  
  113.  
  114. void LoadFile()
  115. {
  116.     float roll, pitch, yaw, a_x, a_y, a_z, m_x, m_y, m_z, omega_x, omega_y, omega_z;
  117.  
  118.  
  119.     std::fstream plik;
  120.     std::ofstream plik2;
  121.     int i = 0;
  122.     plik.open("outputFreeFall01.log", std::ios::in | std::ios::out);
  123.  
  124.     if (plik) {
  125.         while (plik) {
  126.  
  127.             plik >> roll >> pitch >> yaw >> a_x >> a_y >> a_z >> m_x >> m_y >> m_z >> omega_x >> omega_y >> omega_z;
  128.             a_x *=150;
  129.             a_y *= 100;
  130.             a_z *= 100;
  131.             tabx[i] = a_x;
  132.             taby[i] = a_y;
  133.             tabz[i] = a_z;
  134.             i++;
  135.         }
  136.     }
  137.     plik.close();
  138. }
  139.  
  140.  
  141. int OnCreate(HWND window)
  142. {
  143.     inputData();
  144.     inputData2();
  145.     inputData3();
  146.     return 0;
  147. }
  148.  
  149.  
  150. // main function (exe hInstance)
  151. int APIENTRY _tWinMain(HINSTANCE hInstance,
  152.     HINSTANCE hPrevInstance,
  153.     LPTSTR    lpCmdLine,
  154.     int       nCmdShow)
  155. {
  156.     UNREFERENCED_PARAMETER(hPrevInstance);
  157.     UNREFERENCED_PARAMETER(lpCmdLine);
  158.  
  159.     LoadFile();
  160.     // TODO: Place code here.
  161.     MSG msg;
  162.     HACCEL hAccelTable;
  163.  
  164.     value = 0;
  165.  
  166.     GdiplusStartupInput gdiplusStartupInput;
  167.     ULONG_PTR           gdiplusToken;
  168.     GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
  169.  
  170.     // Initialize global strings
  171.     LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  172.     LoadString(hInstance, IDC_DRAW, szWindowClass, MAX_LOADSTRING);
  173.     MyRegisterClass(hInstance);
  174.  
  175.  
  176.  
  177.     // Perform application initialization:
  178.     if (!InitInstance(hInstance, nCmdShow))
  179.     {
  180.         return FALSE;
  181.     }
  182.  
  183.     hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_DRAW));
  184.  
  185.     // Main message loop:
  186.     while (GetMessage(&msg, NULL, 0, 0))
  187.     {
  188.         if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  189.         {
  190.             TranslateMessage(&msg);
  191.             DispatchMessage(&msg);
  192.         }
  193.     }
  194.  
  195.     GdiplusShutdown(gdiplusToken);
  196.  
  197.     return (int)msg.wParam;
  198. }
  199.  
  200.  
  201.  
  202. //
  203. //  FUNCTION: MyRegisterClass()
  204. //
  205. //  PURPOSE: Registers the window class.
  206. //
  207. //  COMMENTS:
  208. //
  209. //    This function and its usage are only necessary if you want this code
  210. //    to be compatible with Win32 systems prior to the 'RegisterClassEx'
  211. //    function that was added to Windows 95. It is important to call this function
  212. //    so that the application will get 'well formed' small icons associated
  213. //    with it.
  214. //
  215. ATOM MyRegisterClass(HINSTANCE hInstance)
  216. {
  217.     WNDCLASSEX wcex;
  218.  
  219.     wcex.cbSize = sizeof(WNDCLASSEX);
  220.  
  221.     wcex.style = CS_HREDRAW | CS_VREDRAW;
  222.     wcex.lpfnWndProc = WndProc;
  223.     wcex.cbClsExtra = 0;
  224.     wcex.cbWndExtra = 0;
  225.     wcex.hInstance = hInstance;
  226.     wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_DRAW));
  227.     wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  228.     wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  229.     wcex.lpszMenuName = MAKEINTRESOURCE(IDC_DRAW);
  230.     wcex.lpszClassName = szWindowClass;
  231.     wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
  232.  
  233.     return RegisterClassEx(&wcex);
  234. }
  235.  
  236. //
  237. //   FUNCTION: InitInstance(HINSTANCE, int)
  238. //
  239. //   PURPOSE: Saves instance handle and creates main window
  240. //
  241. //   COMMENTS:
  242. //
  243. //        In this function, we save the instance handle in a global variable and
  244. //        create and display the main program window.
  245. //
  246. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  247. {
  248.     HWND hWnd;
  249.  
  250.  
  251.     hInst = hInstance; // Store instance handle (of exe) in our global variable
  252.  
  253.     // main window
  254.     hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
  255.         CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
  256.  
  257.     // create button and store the handle                                                      
  258.  
  259.     hwndButton = CreateWindow(TEXT("button"),                      // The class name required is button
  260.         TEXT("Rysuj wykres X"),                  // the caption of the button
  261.         WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,  // the styles
  262.         900, 100,                                  // the left and top co-ordinates
  263.         100, 50,                              // width and height
  264.         hWnd,                                 // parent window handle
  265.         (HMENU)ID_BUTTON1,                   // the ID of your button
  266.         hInstance,                            // the instance of your application
  267.         NULL);
  268.  
  269.     hwndButton = CreateWindow(TEXT("button"),                      // The class name required is button
  270.         TEXT("Rysuj wykres Y"),                  // the caption of the button
  271.         WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,  // the styles
  272.         900, 200,                                  // the left and top co-ordinates
  273.         100, 50,                              // width and height
  274.         hWnd,                                 // parent window handle
  275.         (HMENU)ID_BUTTON2,                   // the ID of your button
  276.         hInstance,                            // the instance of your application
  277.         NULL);                               // extra bits you dont really need
  278.  
  279.  
  280.     hwndButton = CreateWindow(TEXT("button"),                      // The class name required is button
  281.         TEXT("Rysuj wykres Z"),                  // the caption of the button
  282.         WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,  // the styles
  283.         900, 300,                                  // the left and top co-ordinates
  284.         100, 50,                              // width and height
  285.         hWnd,                                 // parent window handle
  286.         (HMENU)ID_BUTTON3,                   // the ID of your button
  287.         hInstance,                            // the instance of your application
  288.         NULL);
  289.  
  290.     hwndButton = CreateWindow(TEXT("button"),                      // The class name required is button
  291.         TEXT("Rysuj wszystko"),                  // the caption of the button
  292.         WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,  // the styles
  293.         900, 400,                                  // the left and top co-ordinates
  294.         100, 50,                              // width and height
  295.         hWnd,                                 // parent window handle
  296.         (HMENU)ID_BUTTON4,                   // the ID of your button
  297.         hInstance,                            // the instance of your application
  298.         NULL);                               // extra bits you dont really need
  299.  
  300.     hwndButton = CreateWindow(TEXT("button"),                      // The class name required is button
  301.         TEXT("WYCZYŚĆ"),                  // the caption of the button
  302.         WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,  // the styles
  303.         900, 500,                                  // the left and top co-ordinates
  304.         100, 50,                              // width and height
  305.         hWnd,                                 // parent window handle
  306.         (HMENU)ID_BUTTON5,                   // the ID of your button
  307.         hInstance,                            // the instance of your application
  308.         NULL);
  309.  
  310.     // create button and store the handle                                                      
  311.  
  312.  
  313.  
  314.     /*
  315.     hwndButton = CreateWindow(TEXT("button"), TEXT("Timer ON"),
  316.         WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
  317.         300, 155, 100, 30, hWnd, (HMENU)ID_RBUTTON1, GetModuleHandle(NULL), NULL);
  318.  
  319.     hwndButton = CreateWindow(TEXT("button"), TEXT("Timer OFF"),
  320.         WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
  321.         300, 200, 100, 30, hWnd, (HMENU)ID_RBUTTON2, GetModuleHandle(NULL), NULL);
  322.     */
  323.  
  324.     OnCreate(hWnd);
  325.  
  326.     if (!hWnd)
  327.     {
  328.         return FALSE;
  329.     }
  330.  
  331.     ShowWindow(hWnd, nCmdShow);
  332.     UpdateWindow(hWnd);
  333.  
  334.     return TRUE;
  335. }
  336.  
  337. //
  338. //  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
  339. //
  340. //  PURPOSE:  Processes messages for the main window.
  341. //
  342. //  WM_COMMAND  - process the application menu
  343. //  WM_PAINT    - Paint the main window (low priority)
  344. //  WM_DESTROY  - post a quit message and return
  345. //
  346. //
  347. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  348. {
  349.     int wmId, wmEvent;
  350.     PAINTSTRUCT ps;
  351.     HDC hdc;
  352.  
  353.     switch (message)
  354.     {
  355.     case WM_COMMAND:
  356.         wmId = LOWORD(wParam);
  357.         wmEvent = HIWORD(wParam);
  358.  
  359.         // MENU & BUTTON messages
  360.         // Parse the menu selections:
  361.         switch (wmId)
  362.         {
  363.         case IDM_ABOUT:
  364.             DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
  365.             break;
  366.         case IDM_EXIT:
  367.             DestroyWindow(hWnd);
  368.             break;
  369.  
  370.         case ID_BUTTON1:
  371.  
  372.             repaintWindow(hWnd, hdc, ps, NULL, 1);
  373.             break;
  374.  
  375.         case ID_BUTTON2:
  376.  
  377.             repaintWindow(hWnd, hdc, ps, NULL, 2);
  378.             break;
  379.  
  380.         case ID_BUTTON3:
  381.             repaintWindow(hWnd, hdc, ps, NULL, 3);
  382.             break;
  383.         case ID_BUTTON4:
  384.             repaintWindow(hWnd, hdc, ps, NULL, 3);
  385.             repaintWindow(hWnd, hdc, ps, NULL, 1);
  386.             repaintWindow(hWnd, hdc, ps, NULL, 2);
  387.             break;
  388.         case ID_BUTTON5:
  389.             repaintWindow(hWnd, hdc, ps, NULL, 777);
  390.             break;
  391.  
  392.         case ID_RBUTTON1:
  393.             SetTimer(hWnd, TMR_1, 25, 0);
  394.             break;
  395.         case ID_RBUTTON2:
  396.             KillTimer(hWnd, TMR_1);
  397.             break;
  398.         default:
  399.             return DefWindowProc(hWnd, message, wParam, lParam);
  400.         }
  401.         break;
  402.     case WM_PAINT:
  403.         hdc = BeginPaint(hWnd, &ps);
  404.         // TODO: Add any drawing code here (not depend on timer, buttons)
  405.         EndPaint(hWnd, &ps);
  406.         break;
  407.     case WM_DESTROY:
  408.         PostQuitMessage(0);
  409.         break;
  410.  
  411.     case WM_TIMER:
  412.         switch (wParam)
  413.         {
  414.         case TMR_1:
  415.             //force window to repaint
  416.             repaintWindow(hWnd, hdc, ps, &drawArea2, 4);
  417.             value++;
  418.             break;
  419.         }
  420.  
  421.     default:
  422.         return DefWindowProc(hWnd, message, wParam, lParam);
  423.     }
  424.     return 0;
  425. }
  426.  
  427. // Message handler for about box.
  428. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  429. {
  430.     UNREFERENCED_PARAMETER(lParam);
  431.     switch (message)
  432.     {
  433.     case WM_INITDIALOG:
  434.         return (INT_PTR)TRUE;
  435.  
  436.     case WM_COMMAND:
  437.         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  438.         {
  439.             EndDialog(hDlg, LOWORD(wParam));
  440.             return (INT_PTR)TRUE;
  441.         }
  442.         break;
  443.     }
  444.     return (INT_PTR)FALSE;
  445. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement