Facet class file
#include "stdafx.h"
#include "Facet.h"
#include "EllipticalPath.h"
EllipticalPath* elp_path;
Facet::Facet(HWND hWnd, int window_width, int window_height)
{
elp_path = new EllipticalPath(hWnd, window_width, window_height);
}
bool Facet::decorateButton(WPARAM wParam, LPARAM lParam) {
if (wParam == 12321)
{
LPDRAWITEMSTRUCT lpDIS = (LPDRAWITEMSTRUCT)lParam;
SetDCBrushColor(lpDIS->hDC, RGB(255, 192, 203));
SelectObject(lpDIS->hDC, GetStockObject(DC_BRUSH));
RECT rect = { 0 };
rect.left = lpDIS->rcItem.left;
rect.right = lpDIS->rcItem.right;
rect.top = lpDIS->rcItem.top;
rect.bottom = lpDIS->rcItem.bottom;
RoundRect(lpDIS->hDC, rect.left, rect.top, rect.right, rect.bottom, 50, 50);
DrawText(lpDIS->hDC, TEXT("MOVE"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
return TRUE;
}
return FALSE;
}
void Facet::informPaint() {
elp_path->paint();
}
bool Facet::actionPerformed(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
switch (LOWORD(wParam))
{
case 12321:
elp_path->moveElliptic();
return TRUE;
default:
return FALSE;
}
}
Facet::~Facet()
{
delete elp_path;
}
EllipticalPath Header file
#pragma once
#define aWIDTH 10
#define aHEIGHT 10
class EllipticalPath
{
public:
EllipticalPath(HWND, int, int);
virtual ~EllipticalPath();
void paint();
void moveElliptic();
protected:
HWND hWindow;
HDC hdc;
int window_width;
int window_height;
COLORREF ball_colour;
int h;
int k;
int a;
int b;
int x;
int y;
HPEN ball_pen;
HBRUSH ball_brush;
};
C++ code for EllipticalPath Class file
#include "stdafx.h"
#include "EllipticalPath.h"
#include <math.h>
EllipticalPath::EllipticalPath(HWND hWnd, int window_width, int window_height)
{
hWindow = hWnd;
this->window_width = window_width;
this->window_height = window_height;
ball_colour = RGB(255, 0, 0);
h = 250;
k = 275;
a = 150;
b = 100;
x = h - a;
y = k;
ball_pen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
ball_brush = CreateSolidBrush(ball_colour);
hdc = GetDC(hWindow);
SelectObject(hdc, ball_pen);
SelectObject(hdc, ball_brush);
}
void EllipticalPath::paint() {
Ellipse(hdc, x, y, x + aWIDTH, y + aHEIGHT);
}
void EllipticalPath::moveElliptic() {
while (x <= h + a) {
y = (int)round(k - ((double)b / a) * sqrt(pow(a, 2) - pow((x - h), 2)));
paint();
y = (int)round(k + ((double)b / a) * sqrt(pow(a, 2) - pow((x - h), 2)));
paint();
x += 20;
Sleep(50);
}
}
EllipticalPath::~EllipticalPath()
{
DeleteObject(ball_pen);
DeleteObject(ball_brush);
ReleaseDC(hWindow, hdc);
}