Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <vector>
- #define _USE_MATH_DEFINES
- #include <math.h>
- #include <Windows.h>
- #include <tchar.h>
- using namespace std;
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- TCHAR WinName[] = _T("MainFrame");
- vector <int> shape;
- int APIENTRY WinMain(HINSTANCE This, HINSTANCE Prev, LPSTR cmd, int mode)
- {
- HWND hWnd;
- MSG msg;
- WNDCLASS wc;
- wc.hInstance = This;
- wc.lpszClassName = WinName;
- wc.lpfnWndProc = WndProc;
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.lpszMenuName = NULL;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
- if (!RegisterClass(&wc)) return 0;
- hWnd = CreateWindow(WinName, _T("Каркас Windows-приложения"),
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- HWND_DESKTOP,
- NULL,
- This,
- NULL);
- ShowWindow(hWnd, mode);
- while (GetMessage(&msg, NULL, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return 0;
- }
- LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
- PAINTSTRUCT ps;
- HDC hdc;
- static int sx, sy;
- static HPEN hpen1, hpen2;
- int elps(1), sqr(0);
- int a, b, x1(400), y1(400), x2(200), y2(200);
- switch (message) {
- case WM_CREATE:
- hpen1 = CreatePen(PS_SOLID, 2, RGB(0, 0, 255));
- hpen2 = CreatePen(PS_SOLID, 2, RGB(255, 0, 0));
- shape.push_back(sqr);
- shape.push_back(elps);
- break;
- case WM_SIZE:
- sx = LOWORD(lParam);
- sy = HIWORD(lParam);
- break;
- case WM_PAINT:
- hdc = BeginPaint(hWnd, &ps);
- a = sx / 2;
- b = sy / 2;
- for (int i = 0; i < shape.size(); i++) {
- if (shape[i] == 0) {
- SelectObject(hdc, hpen1);
- Rectangle(hdc, x1, y1, x2, y2);
- }
- else {
- SelectObject(hdc, hpen2);
- Ellipse(hdc, x1, y1, x2, y2);
- }
- }
- EndPaint(hWnd, &ps);
- break;
- case WM_DESTROY:
- DeleteObject(hpen1);
- DeleteObject(hpen2);
- PostQuitMessage(0);
- break;
- default: return DefWindowProc(hWnd, message, wParam, lParam);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement