Facet class file
#include "stdafx.h"
#include "Facet.h"
#include "CircularPath.h"
CircularPath* cyc_path;
Facet::Facet(HWND hWnd, int window_width, int window_height)
{
cyc_path = new CircularPath(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() {
cyc_path->paint();
}
bool Facet::actionPerformed(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
switch (LOWORD(wParam))
{
case 12321:
cyc_path->moveCyclic();
return TRUE;
default:
return FALSE;
}
}
Facet::~Facet()
{
delete cyc_path;
}
CircularPath Header file
#pragma once
#define aWIDTH 10
#define aHEIGHT 10
class CircularPath
{
public:
CircularPath(HWND, int, int);
virtual ~CircularPath();
void paint();
void moveCyclic();
protected:
HWND hWindow;
HDC hdc;
int window_width;
int window_height;
COLORREF ball_colour;
int a;
int b;
const int r = 150;
int x;
int y;
HPEN ball_pen;
HBRUSH ball_brush;
};
C++ code for CircularPath Class file
#include "stdafx.h"
#include "CircularPath.h"
#include <math.h>
CircularPath::CircularPath(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);
a = 250;
b = 265;
x = a - r;
y = b;
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 CircularPath::paint() {
Ellipse(hdc, x, y, x + aWIDTH, y + aHEIGHT);
}
void CircularPath::moveCyclic() {
while (x <= a + r) {
y = b - (int)round(sqrt(pow(r, 2) - pow((x - a), 2)));
paint();
y = b + (int)round(sqrt(pow(r, 2) - pow((x - a), 2)));
paint();
x += 20;
Sleep(50);
}
}
CircularPath::~CircularPath()
{
DeleteObject(ball_pen);
DeleteObject(ball_brush);
ReleaseDC(hWindow, hdc);
}