Advertisement
peterzig

[PIU] Pierdolony Tangens

Nov 8th, 2016
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.15 KB | None | 0 0
  1. #include <windows.h>
  2. #include <string>
  3. #include <cmath>
  4.  
  5. using std::wstring;
  6.  
  7. HINSTANCE hInst;
  8. const wstring NazwaKlasy(L"Klasa");
  9. const wstring NazwaApp(L"Psinus");
  10. int iDiv = 2;
  11. float Pi = 3.14f;
  12.  
  13. HPEN Pen[2];
  14. /////////////////////////////////////////////////////////////////////////////////////////////////
  15.  
  16.  
  17. static void OnWM_PAINT(HWND Wnd)
  18. {
  19.     PAINTSTRUCT PS;
  20.     BeginPaint(Wnd, &PS);
  21.  
  22.     RECT R, E;
  23.     GetClientRect(Wnd, &R);
  24.  
  25.     POINT Z = { 700,700 };
  26.     SetMapMode(PS.hdc, MM_ISOTROPIC);
  27.     SetWindowExtEx(PS.hdc, Z.x, Z.y, NULL);                        //zakres okna
  28.     SetViewportExtEx(PS.hdc, R.right, R.bottom, NULL);            //zakres ukł wsp
  29.     SetViewportOrgEx(PS.hdc, R.right / 2, R.bottom / 2, NULL);    //pocz ukł wsp
  30.     E.left = R.left + ((R.right - R.left) / 10);
  31.     E.right = R.right - ((R.right - R.left) / 10);
  32.     E.top = R.top + ((R.bottom - R.top) / 10);
  33.     E.bottom = R.bottom - ((R.bottom - R.top) / 10);
  34.  
  35.     SelectObject(PS.hdc, Pen[0]);
  36.  
  37.  
  38.  
  39.     //MoveToEx( PS.hdc, 0, -250, NULL );
  40.     MoveToEx(PS.hdc, 0, -((E.bottom - E.top) / iDiv), NULL);
  41.     LineTo(PS.hdc, 0, ((E.bottom - E.top) / iDiv));
  42.  
  43.     MoveToEx(PS.hdc, -((E.right - E.left) / iDiv), 0, NULL);
  44.     LineTo(PS.hdc, (E.right - E.left) / iDiv, 0);
  45.  
  46.  
  47.     SelectObject(PS.hdc, Pen[1]);
  48.     float ytan;
  49.     float ytans;
  50.     for (float drzwi = -(E.right - E.left) / iDiv; drzwi <= (E.right - E.left) / iDiv; drzwi += iDiv)
  51.     {
  52.         ytan = 100 * tan((drzwi * Pi) / 180);
  53.         ytans = 100 * tan(((drzwi - 4) * Pi) / 180);
  54.         if ((ytans <= ((E.bottom - E.top) / iDiv) && ytans >= -((E.bottom - E.top) / iDiv)) && (ytan <= ((E.bottom - E.top) / iDiv) && ytan >= -((E.bottom - E.top) / iDiv)))
  55.         {
  56.             MoveToEx(PS.hdc, drzwi, ytan, NULL);
  57.             LineTo(PS.hdc, drzwi - 4, ytans);
  58.         }
  59.     }
  60.  
  61.     EndPaint(Wnd, &PS);
  62. }
  63.  
  64. static LRESULT CALLBACK FunkcjaOkienkowa(HWND Wnd, UINT Komunikat, WPARAM wParam, LPARAM lParam)
  65. {
  66.     switch (Komunikat)
  67.     {
  68.     case WM_PAINT:
  69.     {
  70.         OnWM_PAINT(Wnd);
  71.     }break;
  72.  
  73.     case WM_DESTROY:
  74.     {
  75.         PostQuitMessage(0);
  76.     }break;
  77.  
  78.     default: return DefWindowProc(Wnd, Komunikat, wParam, lParam);
  79.     }
  80.  
  81.     return 0;
  82. }
  83.  
  84. const static bool Rejestruj()
  85. {
  86.     WNDCLASSEX wc;
  87.     wc.cbSize = sizeof(WNDCLASSEX);
  88.     wc.cbClsExtra = wc.cbWndExtra = 0;
  89.     wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
  90.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  91.     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  92.     wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  93.     wc.hInstance = hInst;
  94.     wc.lpfnWndProc = &FunkcjaOkienkowa;
  95.     wc.lpszClassName = NazwaKlasy.c_str();
  96.     wc.lpszMenuName = NULL;
  97.     wc.style = CS_HREDRAW | CS_VREDRAW;
  98.     return (RegisterClassEx(&wc) != 0);
  99. }
  100.  
  101.  
  102. INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
  103. {
  104.     hInst = hInstance;
  105.     Pen[0] = CreatePen(PS_SOLID, 1, 0x00FFFFFF);
  106.     Pen[1] = CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
  107.  
  108.  
  109.     Rejestruj();
  110.  
  111.     HWND GlowneOkno = CreateWindowEx(0, NazwaKlasy.c_str(), NazwaApp.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE, 50, 50, 700, 700, 0, 0, hInstance, 0);
  112.  
  113.     MSG msg;
  114.  
  115.     while (GetMessage(&msg, 0, 0, 0) > 0)
  116.     {
  117.         TranslateMessage(&msg);
  118.         DispatchMessage(&msg);
  119.     }
  120.  
  121.     UnregisterClass(NazwaKlasy.c_str(), hInstance);
  122.  
  123.     return msg.wParam;
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement