📄 polyctl.cpp
字号:
// PolyCtl.cpp : Implementation of CPolyCtl
#include "stdafx.h"
#include "AxAtlCtl.h"
#include "PolyCtl.h"
/////////////////////////////////////////////////////////////////////////////
// CPolyCtl
STDMETHODIMP CPolyCtl::get_Slides(short *pVal)
{
*pVal = m_nSides;
return S_OK;
}
STDMETHODIMP CPolyCtl::put_Slides(short newVal)
{
if (newVal >=3 && newVal <= 100)
{
m_nSides = newVal;
FireViewChange();
return S_OK;
}
else
return Error(_T("圆内接正多边形的边数必须在3~100之间!"));
}
void CPolyCtl::CalcPoints(const RECT& rc)
{
const double pi = 3.14159265358979;
POINT ptCenter;
double dblRadiusx = (rc.right - rc.left) / 2;
double dblRadiusy = (rc.bottom - rc.top) / 2;
double dblAngle = 3 * pi / 2; // Start at the top
double dblDiff = 2 * pi / m_nSides; // Angle each side will make
ptCenter.x = (rc.left + rc.right) / 2;
ptCenter.y = (rc.top + rc.bottom) / 2;
// Calculate the points for each side
for (int i = 0; i < m_nSides; i++)
{
m_arrPoint[i].x = (long)(dblRadiusx * cos(dblAngle) + ptCenter.x + 0.5);
m_arrPoint[i].y = (long)(dblRadiusy * sin(dblAngle) + ptCenter.y + 0.5);
dblAngle += dblDiff;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -