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 <fstream>
- #include <cstdio>
- #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
- const int liczba_pomiarow = 2485;
- const int liczba_pominiec = 100;
- const int powtorzenia = liczba_pomiarow - liczba_pominiec;
- double wektor_przyspieszenie[powtorzenia];
- double wektor_droga[powtorzenia];
- double wektor_predkosc[powtorzenia];
- INT value;
- // buttons
- HWND hwndButton;
- // sent data
- int col = 0;
- std::vector<Point> data;
- RECT drawArea1 = { 0, 0, 150, 2000 };
- RECT drawArea2 = { 50, 400, 150, 200 };
- RECT drawArea3 = { 100, 800, 150, 200 };
- // 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);
- void wczytaj() {
- std::ifstream plik;
- plik.open("outputRobotForwardA01.log");
- double wynik;
- double bufor;
- int miejsce = 1;
- for (int i = 0; i < liczba_pominiec * 12; i++) // pominiecie n linijek
- plik >> bufor;
- wektor_przyspieszenie[0] = 0;
- for (int j = 0; j < powtorzenia; j++) {
- for (int k = 0; k < 3; k++)
- plik >> bufor;
- plik >> wynik;
- wektor_przyspieszenie[miejsce] = wynik;
- miejsce++;
- for (int k = 4; k < 12; k++)
- plik >> bufor;
- }
- }
- void calki() {
- for (int i = 0; i< powtorzenia; i++)
- wektor_predkosc[i] = (wektor_przyspieszenie[i] + wektor_przyspieszenie[i + 1]) / 2;
- for (int j = 0; j< powtorzenia; j++)
- wektor_droga[j] = (wektor_predkosc[j] + wektor_predkosc[j + 1]) / 2;
- }
- void MyOnPaint(HDC hdc)
- {
- Graphics graphics(hdc);
- Pen pen(Color(255, 0, 0, 255));
- Pen pen2(Color(255, 25 * col, 0, 255));
- for (int i = 1; i < 100; i++)
- graphics.DrawLine(&pen2, data[i - 1].X, data[i - 1].Y, data[i].X, data[i].Y);
- }
- void repaintWindow(HWND hWnd, HDC &hdc, PAINTSTRUCT &ps, RECT *drawArea)
- {
- if (drawArea == NULL)
- InvalidateRect(hWnd, NULL, TRUE); // repaint all
- else
- InvalidateRect(hWnd, drawArea, TRUE); //repaint drawArea
- hdc = BeginPaint(hWnd, &ps);
- MyOnPaint(hdc);
- EndPaint(hWnd, &ps);
- }
- void inputData()
- {
- data.push_back(Point(0, 0));
- for (int i = 1; i < 100; i++) {
- data.push_back(Point(2 * i + 1, 100* wektor_przyspieszenie[i]));
- }
- }
- int OnCreate(HWND window)
- {
- inputData();
- return 0;
- }
- // main function (exe hInstance)
- int APIENTRY _tWinMain(HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPTSTR lpCmdLine,
- int nCmdShow)
- {
- UNREFERENCED_PARAMETER(hPrevInstance);
- UNREFERENCED_PARAMETER(lpCmdLine);
- // 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("Przyspieszenie"), // the caption of the button
- WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, // the styles
- 500, 400, // the left and top co-ordinates
- 120, 50, // width and height
- hWnd, // parent window handle
- (HMENU)ID_BUTTON1, // 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("Droga"), // the caption of the button
- WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, // the styles
- 100, 400, // the left and top co-ordinates
- 120, 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("Predkosc"), // the caption of the button
- WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, // the styles
- 300, 400, // the left and top co-ordinates
- 120, 50, // width and height
- hWnd, // parent window handle
- (HMENU)ID_BUTTON3, // the ID of your button
- hInstance, // the instance of your application
- NULL);
- // create button and store the handle
- 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:
- col++;
- if (col > 10)
- col = 0;
- repaintWindow(hWnd, hdc, ps, &drawArea1);
- break;
- case ID_BUTTON2:
- repaintWindow(hWnd, hdc, ps, NULL);
- 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;
- 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