Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // draw.cpp : Defines the entry point for the application.
- //
- #include "stdafx.h"
- #include "draw2.h"
- #include <vector>
- #include <cstdio>
- #include <fstream>
- #include <iostream>
- #define MAX_LOADSTRING 100
- #define TMR_1 1
- // Global Variables:
- HINSTANCE hInst; // current instance
- TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
- TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
- INT value;
- // buttons
- HWND hwndButton;
- // sent data
- int col = 0;
- std::vector<Point> datax;
- std::vector<Point> datay;
- std::vector<Point> dataz;
- RECT drawArea1 = { 100, 100, 500, 300 };
- RECT drawArea2 = { 100, 100, 800, 300 };
- // Forward declarations of functions included in this code module:
- ATOM MyRegisterClass(HINSTANCE hInstance);
- BOOL InitInstance(HINSTANCE, int);
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
- INT_PTR CALLBACK Buttons(HWND, UINT, WPARAM, LPARAM);
- int tabx[567], taby[567], tabz[567];
- int missedSamplesX = 100;
- int missedSamplesY = 111;
- int missedSamplesZ = 56;
- void MyOnPaint(HDC hdc, int choose)
- {
- Graphics graphics(hdc);
- Pen pen(Color(255, 0, 0, 255));
- Pen pen2(Color(255, 0, 55, 255));
- Pen pen3(Color(255, 55, 0, 3));
- if (choose == 1) {
- for (int i = 1 ; i < datax.size() - missedSamplesX; i++)
- graphics.DrawLine(&pen2, datax[i - 1].X+10, datax[i - 1].Y + 100, datax[i].X + 10, datax[i].Y + 100);
- }
- if (choose == 2)
- for (int i = 1 + missedSamplesY; i < datay.size() - missedSamplesY; i++)
- graphics.DrawLine(&pen2, datay[i - 1].X + 10, datay[i - 1].Y + 200, datay[i].X + 10, datay[i].Y + 200);
- if (choose == 3)
- for (int i = 1+ missedSamplesZ; i < dataz.size() - missedSamplesZ; i++)
- graphics.DrawLine(&pen2, dataz[i - 1].X + 10, dataz[i - 1].Y + 300, dataz[i].X + 10, dataz[i].Y + 300);
- }
- void repaintWindow(HWND hWnd, HDC &hdc, PAINTSTRUCT &ps, RECT *drawArea, int choose)
- {
- if (drawArea == NULL)
- InvalidateRect(hWnd, NULL, TRUE); // repaint all
- else
- InvalidateRect(hWnd, drawArea, TRUE); //repaint drawArea
- hdc = BeginPaint(hWnd, &ps);
- switch (choose) {
- case 1:
- MyOnPaint(hdc,1);
- break;
- case 2:
- MyOnPaint(hdc, 2);
- break;
- case 3:
- MyOnPaint(hdc, 3);
- break;
- }
- EndPaint(hWnd, &ps);
- }
- void inputData()
- {
- datax.push_back(Point(0, 0));
- for (int i = 1 + missedSamplesX; i < 567; i++) {
- datax.push_back(Point(2.7 * (i - missedSamplesX) + 1, tabx[i - 1]));
- }
- }
- void inputData2()
- {
- datay.push_back(Point(0, 0));
- for (int i = 1; i < 567; i++) {
- datay.push_back(Point(3.4 * (i - missedSamplesY) + 1, taby[i - 1]));
- }
- }
- void inputData3()
- {
- dataz.push_back(Point(0, 0));
- for (int i = 1; i < 567; i++) {
- dataz.push_back(Point(2.5 * (i - missedSamplesZ) + 1, tabz[i - 1]));
- }
- }
- void LoadFile()
- {
- float roll, pitch, yaw, a_x, a_y, a_z, m_x, m_y, m_z, omega_x, omega_y, omega_z;
- std::fstream plik;
- std::ofstream plik2;
- int i = 0;
- plik.open("outputFreeFall01.log", std::ios::in | std::ios::out);
- if (plik) {
- while (plik) {
- plik >> roll >> pitch >> yaw >> a_x >> a_y >> a_z >> m_x >> m_y >> m_z >> omega_x >> omega_y >> omega_z;
- a_x *=150;
- a_y *= 100;
- a_z *= 100;
- tabx[i] = a_x;
- taby[i] = a_y;
- tabz[i] = a_z;
- i++;
- }
- }
- plik.close();
- }
- int OnCreate(HWND window)
- {
- inputData();
- inputData2();
- inputData3();
- return 0;
- }
- // main function (exe hInstance)
- int APIENTRY _tWinMain(HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPTSTR lpCmdLine,
- int nCmdShow)
- {
- UNREFERENCED_PARAMETER(hPrevInstance);
- UNREFERENCED_PARAMETER(lpCmdLine);
- LoadFile();
- // TODO: Place code here.
- MSG msg;
- HACCEL hAccelTable;
- value = 0;
- GdiplusStartupInput gdiplusStartupInput;
- ULONG_PTR gdiplusToken;
- GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
- // Initialize global strings
- LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
- LoadString(hInstance, IDC_DRAW, szWindowClass, MAX_LOADSTRING);
- MyRegisterClass(hInstance);
- // Perform application initialization:
- if (!InitInstance(hInstance, nCmdShow))
- {
- return FALSE;
- }
- hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_DRAW));
- // Main message loop:
- while (GetMessage(&msg, NULL, 0, 0))
- {
- if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- }
- GdiplusShutdown(gdiplusToken);
- return (int)msg.wParam;
- }
- //
- // FUNCTION: MyRegisterClass()
- //
- // PURPOSE: Registers the window class.
- //
- // COMMENTS:
- //
- // This function and its usage are only necessary if you want this code
- // to be compatible with Win32 systems prior to the 'RegisterClassEx'
- // function that was added to Windows 95. It is important to call this function
- // so that the application will get 'well formed' small icons associated
- // with it.
- //
- ATOM MyRegisterClass(HINSTANCE hInstance)
- {
- WNDCLASSEX wcex;
- wcex.cbSize = sizeof(WNDCLASSEX);
- wcex.style = CS_HREDRAW | CS_VREDRAW;
- wcex.lpfnWndProc = WndProc;
- wcex.cbClsExtra = 0;
- wcex.cbWndExtra = 0;
- wcex.hInstance = hInstance;
- wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_DRAW));
- wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
- wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
- wcex.lpszMenuName = MAKEINTRESOURCE(IDC_DRAW);
- wcex.lpszClassName = szWindowClass;
- wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
- return RegisterClassEx(&wcex);
- }
- //
- // FUNCTION: InitInstance(HINSTANCE, int)
- //
- // PURPOSE: Saves instance handle and creates main window
- //
- // COMMENTS:
- //
- // In this function, we save the instance handle in a global variable and
- // create and display the main program window.
- //
- BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
- {
- HWND hWnd;
- hInst = hInstance; // Store instance handle (of exe) in our global variable
- // main window
- hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
- // create button and store the handle
- hwndButton = CreateWindow(TEXT("button"), // The class name required is button
- TEXT("Rysuj wykres X"), // the caption of the button
- WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, // the styles
- 900, 100, // the left and top co-ordinates
- 100, 50, // width and height
- hWnd, // parent window handle
- (HMENU)ID_BUTTON1, // the ID of your button
- hInstance, // the instance of your application
- NULL);
- hwndButton = CreateWindow(TEXT("button"), // The class name required is button
- TEXT("Rysuj wykres Y"), // the caption of the button
- WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, // the styles
- 900, 200, // the left and top co-ordinates
- 100, 50, // width and height
- hWnd, // parent window handle
- (HMENU)ID_BUTTON2, // the ID of your button
- hInstance, // the instance of your application
- NULL); // extra bits you dont really need
- hwndButton = CreateWindow(TEXT("button"), // The class name required is button
- TEXT("Rysuj wykres Z"), // the caption of the button
- WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, // the styles
- 900, 300, // the left and top co-ordinates
- 100, 50, // width and height
- hWnd, // parent window handle
- (HMENU)ID_BUTTON3, // the ID of your button
- hInstance, // the instance of your application
- NULL);
- hwndButton = CreateWindow(TEXT("button"), // The class name required is button
- TEXT("Rysuj wszystko"), // the caption of the button
- WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, // the styles
- 900, 400, // the left and top co-ordinates
- 100, 50, // width and height
- hWnd, // parent window handle
- (HMENU)ID_BUTTON4, // the ID of your button
- hInstance, // the instance of your application
- NULL); // extra bits you dont really need
- hwndButton = CreateWindow(TEXT("button"), // The class name required is button
- TEXT("WYCZYŚĆ"), // the caption of the button
- WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, // the styles
- 900, 500, // the left and top co-ordinates
- 100, 50, // width and height
- hWnd, // parent window handle
- (HMENU)ID_BUTTON5, // the ID of your button
- hInstance, // the instance of your application
- NULL);
- // create button and store the handle
- /*
- hwndButton = CreateWindow(TEXT("button"), TEXT("Timer ON"),
- WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
- 300, 155, 100, 30, hWnd, (HMENU)ID_RBUTTON1, GetModuleHandle(NULL), NULL);
- hwndButton = CreateWindow(TEXT("button"), TEXT("Timer OFF"),
- WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
- 300, 200, 100, 30, hWnd, (HMENU)ID_RBUTTON2, GetModuleHandle(NULL), NULL);
- */
- OnCreate(hWnd);
- if (!hWnd)
- {
- return FALSE;
- }
- ShowWindow(hWnd, nCmdShow);
- UpdateWindow(hWnd);
- return TRUE;
- }
- //
- // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
- //
- // PURPOSE: Processes messages for the main window.
- //
- // WM_COMMAND - process the application menu
- // WM_PAINT - Paint the main window (low priority)
- // WM_DESTROY - post a quit message and return
- //
- //
- LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- int wmId, wmEvent;
- PAINTSTRUCT ps;
- HDC hdc;
- switch (message)
- {
- case WM_COMMAND:
- wmId = LOWORD(wParam);
- wmEvent = HIWORD(wParam);
- // MENU & BUTTON messages
- // Parse the menu selections:
- switch (wmId)
- {
- case IDM_ABOUT:
- DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
- break;
- case IDM_EXIT:
- DestroyWindow(hWnd);
- break;
- case ID_BUTTON1:
- repaintWindow(hWnd, hdc, ps, NULL, 1);
- break;
- case ID_BUTTON2:
- repaintWindow(hWnd, hdc, ps, NULL, 2);
- break;
- case ID_BUTTON3:
- repaintWindow(hWnd, hdc, ps, NULL, 3);
- break;
- case ID_BUTTON4:
- repaintWindow(hWnd, hdc, ps, NULL, 3);
- repaintWindow(hWnd, hdc, ps, NULL, 1);
- repaintWindow(hWnd, hdc, ps, NULL, 2);
- break;
- case ID_BUTTON5:
- repaintWindow(hWnd, hdc, ps, NULL, 777);
- break;
- case ID_RBUTTON1:
- SetTimer(hWnd, TMR_1, 25, 0);
- break;
- case ID_RBUTTON2:
- KillTimer(hWnd, TMR_1);
- break;
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- break;
- case WM_PAINT:
- hdc = BeginPaint(hWnd, &ps);
- // TODO: Add any drawing code here (not depend on timer, buttons)
- EndPaint(hWnd, &ps);
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- case WM_TIMER:
- switch (wParam)
- {
- case TMR_1:
- //force window to repaint
- repaintWindow(hWnd, hdc, ps, &drawArea2, 4);
- value++;
- break;
- }
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- return 0;
- }
- // Message handler for about box.
- INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
- {
- UNREFERENCED_PARAMETER(lParam);
- switch (message)
- {
- case WM_INITDIALOG:
- return (INT_PTR)TRUE;
- case WM_COMMAND:
- if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
- {
- EndDialog(hDlg, LOWORD(wParam));
- return (INT_PTR)TRUE;
- }
- break;
- }
- return (INT_PTR)FALSE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement