Olaphsen

Untitled

Nov 28th, 2022
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.96 KB | Source Code | 0 0
  1. LRESULT CALLBACK DrawProcedure(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
  2. {
  3.     int i;
  4.     PAINTSTRUCT ps;
  5.     HDC hdc;
  6.     RECT rect;
  7.     GetClientRect (hWnd, &rect); // client window size
  8.  
  9.     switch (msg)
  10.     {
  11.  
  12.     case WM_PAINT:
  13.     {
  14.         hdc = BeginPaint(hWnd, &ps);
  15.  
  16.         const int xWS = rect.right; // horizontal working window size
  17.         const int yWS = rect.bottom; // vertical working window size
  18.  
  19.         const int OmegaGridStep = 2; // Omega_step
  20.         const int OmegaMin = -30;  // Omega_min
  21.         const int OmegaMax = 30;  // Omega_max
  22.  
  23.         int tMin = 0;
  24.         int tMax_1 = 60;
  25.  
  26.         SetViewportOrgEx(hdc, 0, yWS / 2, NULL); // origin point
  27.  
  28.         double nPixPerOmega = yWS / 60;
  29.         double nPixPerT = xWS / 60;
  30.  
  31.         int yMin = OmegaMin * nPixPerOmega;
  32.         int yMax = OmegaMax * nPixPerOmega;
  33.  
  34.         const double tGridStep_1_min = 1;
  35.         int xMin = tMin * nPixPerT;
  36.         int xMax_1 = tMax_1 * nPixPerT;
  37.  
  38.         // OX
  39.         HPEN hPen1=CreatePen(PS_SOLID, 3, RGB(0, 0, 0));
  40.         SelectObject(hdc, hPen1);
  41.  
  42.         MoveToEx(hdc, 20, 0, NULL);
  43.         LineTo(hdc, xMax_1 + 20, 0);
  44.  
  45.         TextOutA(hdc, xWS - xWS / 20, yWS / 50, "T,min", 6);
  46.  
  47.         // OY
  48.         MoveToEx(hdc, 20, yMin, NULL);
  49.         LineTo(hdc, 20, yMax);
  50.  
  51.         TextOutA(hdc, 15, -yWS / 2, "Omega,deg/sec", 14);
  52.  
  53.         // grid
  54.         HPEN hPen0=CreatePen(PS_SOLID, 1, RGB(0, 160, 0));
  55.         HPEN hOldPen=(HPEN)SelectObject(hdc, hPen0);
  56.  
  57.         int vertical_grid_0 = OmegaMin;
  58.         int horizontal_grid_0 = tMin;
  59.         int x, y;
  60.         UINT uAlignPrev;
  61.         for (int i=0; i<(sizeof(yMark)/sizeof(yMark[0])); ++i) // vertical
  62.         {
  63.             y = vertical_grid_0 * nPixPerOmega;
  64.             MoveToEx(hdc, xMin + 20, y, NULL);
  65.             LineTo(hdc, xMax_1 + 20, y);
  66.             vertical_grid_0 += OmegaGridStep;
  67.             static LOGFONT lf;
  68.             lf.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;
  69.             lf.lfItalic = TRUE;
  70.             lf.lfHeight = 12;
  71.             SetTextColor(hdc, RGB(0, 0, 200));
  72.             uAlignPrev = SetTextAlign(hdc, TA_CENTER);
  73.             HFONT hFont0=CreateFontIndirect(&lf);
  74.             HFONT hOldFont=(HFONT) SelectObject(hdc, hFont0);
  75.  
  76.             TextOutA(hdc, xMin+10, y - 7, yMark[i], strlen(yMark[i]));
  77.         }
  78.         for (int j=1; j<(sizeof(xMark_1)/sizeof(xMark_1[0])); ++j) // horizontal
  79.         {
  80.             x = horizontal_grid_0 * nPixPerT;
  81.             MoveToEx(hdc, x + 20, yMin, NULL);
  82.             LineTo(hdc, x + 20, yMax);
  83.             horizontal_grid_0 += tGridStep_1_min;
  84.             TextOutA(hdc, x+40, 3, xMark_1[j], strlen(xMark_1[j]));
  85.         }
  86.         EndPaint(hWnd, &ps);
  87.     }
  88.     case WM_LBUTTONDOWN:
  89.     {
  90.         HDC hdc;
  91.         WORD nSize, xPos, yPos;
  92.  
  93.         TCHAR szBuf[80];
  94.         DWORD dw;
  95.         HANDLE File;
  96.         RECT rc;
  97.         GetClientRect (hWnd, &rc); // client window size
  98.  
  99.         con
Advertisement
Add Comment
Please, Sign In to add comment