相关代码如下:
// 先在类中定义胡渣三个变量bool m_painting // 是否正在绘制
CPoint m_pointOri // 中心点
float m_radius // 半径 Cdemo98View::Cdemo98View()
{
m_painting = false
m_radius = 0
}
void Cdemo98View::OnDraw(CDC* pDC)
{
Cdemo98Doc* pDoc = GetDocument()
ASSERT_VALID(pDoc)
if (!pDoc)
return
pDC->Ellipse(m_pointOri.x - m_radius, m_pointOri.y - m_radius, m_pointOri.x + m_radius, m_pointOri.y + m_radius)
}
void Cdemo98View::OnLButtonDown(UINT nFlags, CPoint point)
{
m_pointOri = point
m_radius = 0
m_painting = true
}
void Cdemo98View::OnMouseMove(UINT nFlags, CPoint point)
{
if (m_painting) {
// 计算当前点距离中心点距离也就是半径
m_radius = sqrt(pow(float(point.x - m_pointOri.x), 桥历2) + pow(float(point.y - m_pointOri.y), 2))
Invalidate()
}
}
void Cdemo98View::OnLButtonUp(UINT nFlags, CPoint point)
{
// 计算当前点距离中心点距离也就是半径
m_radius = sqrt(pow(float(point.x - m_pointOri.x), 2) + pow(float(point.y - m_pointOri.y), 2))
m_painting 裤消悄= false
Invalidate()
}
运行结果:
用MFC向导创建一个名称为Yuan的对枣段仿话框工程. 并添加对话框类燃蠢CYuanDlg的OnPaint函数的画凳纤圆功能.void CYuanDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this)// device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0)
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON)
int cyIcon = GetSystemMetrics(SM_CYICON)
CRect rect
GetClientRect(&rect)
int x = (rect.Width() - cxIcon + 1) / 2
int y = (rect.Height() - cyIcon + 1) / 2
// Draw the icon
dc.DrawIcon(x, y, m_hIcon)
}
else
{
// 添加画圆功能
CPaintDC dc(this)
CBrush brush
brush.CreateSolidBrush(RGB(0, 0, 255))
dc.SelectObject(brush)
dc.Ellipse( 0, 0, 100, 100)
CDialog::OnPaint()
}
}
先要获取背景画刷,也就是你的那个地图界面的背景,先画圆,然后在圆的轮廓内进行背景画启册刷填充。推荐你看看下面这个文章及手码Demo,里面可以给你许多提示悄薯宏:
http://www.codeproject.com/Articles/251892/Guide-to-Image-Composition-with-Win32-MsImg32-dll
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)