Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <math.h>
- const char szClassName[] = "WinDZ";
- const char szWindowName[] = "Windows DZ";
- LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam);
- bool isVisible = false;
- HWND buttonHwnd;
- void DrawGraph(HWND hWnd, HDC hDC)
- {
- RECT rect;
- GetClientRect(hWnd, &rect);
- const int xVE=rect.right-rect.left;
- const int yVE=rect.bottom-rect.top;
- SetBkMode(hDC, TRANSPARENT);
- SetMapMode(hDC, MM_ISOTROPIC);
- SetWindowExtEx(hDC, xVE, yVE, NULL);
- SetViewportExtEx(hDC, xVE, -yVE, NULL);
- SetViewportOrgEx(hDC, xVE/2, yVE/2, NULL);
- HPEN hPen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
- HPEN hOldPen = (HPEN)SelectObject (hDC, hPen);
- HFONT hOldFont, hFont;
- hFont = CreateFont(15,0,0,0,FW_NORMAL,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_DONTCARE,"Times New Roman Cyr");
- hOldFont=(HFONT)SelectObject(hDC,hFont);
- TextOut(hDC, 5, -5, "0", 1);
- MoveToEx(hDC, 0, -yVE/2, NULL);
- LineTo(hDC, 0, yVE/2);
- MoveToEx(hDC, -xVE/2, 0, NULL);
- LineTo(hDC, xVE/2, 0);
- double maxY = -999999.0;
- double ax[21], ay[21];
- int x;
- double xVal = -1.0;
- int pointX, pointY;
- for (x = 0; x <= 20; x++)
- {
- ax[x] = xVal;
- ay[x] = sin(xVal);
- if (ay[x] > maxY)
- maxY = ay[x];
- xVal += 0.1;
- }
- double mx = xVE/2;
- double my = yVE/2;
- char fStr[100];
- int len;
- MoveToEx(hDC, ax[0]*mx, ay[0]*my, NULL);
- for (x = 0; x <= 20; x++)
- {
- pointX = ax[x]*mx;
- pointY = ay[x]*my;
- if (!(x % 2) && x != 10)
- {
- len = sprintf(fStr, "%.1f", ax[x]);
- TextOut(hDC, x < 10 ? pointX : pointX - 20, 0, fStr, len);
- len = sprintf(fStr, "%.1f", ay[x]);
- TextOut(hDC, 5, pointY, fStr, len);
- }
- LineTo(hDC, pointX, pointY);
- }
- SelectObject(hDC, hOldPen);
- SelectObject(hDC, hOldFont);
- DeleteObject (hPen);
- }
- int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine,
- int nCmdShow)
- {
- HWND hWnd;
- WNDCLASS wndclass;
- wndclass.style = (CS_HREDRAW | CS_VREDRAW);
- wndclass.lpfnWndProc = WndProc;
- wndclass.hInstance = hInstance;
- wndclass.cbClsExtra = 0;
- wndclass.cbWndExtra = 0;
- wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
- wndclass.hbrBackground = (HBRUSH)GetStockObject(0);
- wndclass.lpszMenuName = NULL;
- wndclass.lpszClassName = szClassName;
- if (!RegisterClass(&wndclass))
- exit(FALSE);
- hWnd = CreateWindow(szClassName,
- szWindowName,
- WS_OVERLAPPEDWINDOW,
- 250,
- 250,
- 800,
- 600,
- NULL,
- 0,
- hInstance,
- NULL);
- if (!hWnd)
- exit(FALSE);
- buttonHwnd = CreateWindow("button", "Показать/Скрыть", WS_CHILD|WS_VISIBLE, 0, 0, 150, 30, hWnd, (HMENU)333, hInstance, NULL);
- ShowWindow(hWnd, nCmdShow);
- UpdateWindow(hWnd);
- MSG msg;
- while(GetMessage(&msg, NULL, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return (int)msg.wParam;
- }
- LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
- {
- HDC hDC;
- PAINTSTRUCT ps;
- RECT rct;
- switch (iMessage)
- {
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- case WM_PAINT:
- if (isVisible)
- {
- hDC=BeginPaint(hWnd, &ps);
- DrawGraph(hWnd, hDC);
- EndPaint(hWnd, &ps);
- }
- case WM_COMMAND:
- if (wParam == 333)
- {
- if (!(isVisible = !isVisible))
- {
- GetClientRect(hWnd, &rct);
- InvalidateRect(hWnd, &rct, true);
- UpdateWindow(buttonHwnd);
- }
- }
- break;
- default:
- return DefWindowProc(hWnd, iMessage, wParam, lParam);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement