如何画一个四角修圆的客户区!最好有代码!

babam 2002-03-27 03:49:44
问了好多地方都没有人告诉我该怎么做!
...全文
107 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
40Star 2002-03-27
  • 打赏
  • 举报
回复
CreatePolygonRgn
40Star 2002-03-27
  • 打赏
  • 举报
回复
setwindowrgn
tomPeakz 2002-03-27
  • 打赏
  • 举报
回复
下面是一个绘制XP圆角风格的按钮代码:
#include "stdafx.h"
#include "WinXPButtonST.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

CWinXPButtonST::CWinXPButtonST()
{
// No rounded borders
m_bIsRounded = FALSE;
}

CWinXPButtonST::~CWinXPButtonST()
{
}

// This function is called every time the button border needs to be painted.
// If the button is in standard (not flat) mode this function will NOT be called.
// This is a virtual function that can be rewritten in CButtonST-derived classes
// to produce a whole range of buttons not available by default.
//
// Parameters:
// [IN] pDC
// Pointer to a CDC object that indicates the device context.
// [IN] pRect
// Pointer to a CRect object that indicates the bounds of the
// area to be painted.
//
// Return value:
// BTNST_OK
// Function executed successfully.
//
DWORD CWinXPButtonST::OnDrawBorder(CDC* pDC, LPCRECT pRect)
{
return BTNST_OK;
} // End of OnDrawBorder

// This function is called every time the button background needs to be painted.
// If the button is in transparent mode this function will NOT be called.
// This is a virtual function that can be rewritten in CButtonST-derived classes
// to produce a whole range of buttons not available by default.
//
// Parameters:
// [IN] pDC
// Pointer to a CDC object that indicates the device context.
// [IN] pRect
// Pointer to a CRect object that indicates the bounds of the
// area to be painted.
//
// Return value:
// BTNST_OK
// Function executed successfully.
//
DWORD CWinXPButtonST::OnDrawBackground(CDC* pDC, LPCRECT pRect)
{
if (!m_bMouseOnButton && !m_bIsPressed)
return BASE_BUTTONST::OnDrawBackground(pDC, pRect);

// Create and select a solid brush for button background
CBrush brushBK(m_crColors[BTNST_COLOR_BK_IN]);
CBrush* pOldBrush = pDC->SelectObject(&brushBK);

// Create and select a thick black pen for button border
CPen penBorder;
penBorder.CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
CPen* pOldPen = pDC->SelectObject(&penBorder);

if (m_bIsRounded)
pDC->RoundRect(pRect, CPoint(8, 8));
else
pDC->Rectangle(pRect);

// Put back the old objects
pDC->SelectObject(pOldBrush);
pDC->SelectObject(pOldPen);

return BTNST_OK;
} // End of OnDrawBackground

// This function enables or disables the rounded border for the button.
//
// Parameters:
// [IN] bRounded
// If TRUE the button will have a round border.
// [IN] bRepaint
// If TRUE the button will be repainted.
//
// Return value:
// BTNST_OK
// Function executed successfully.
//
DWORD CWinXPButtonST::SetRounded(BOOL bRounded, BOOL bRepaint)
{
m_bIsRounded = bRounded;
if (bRepaint) Invalidate();

return BTNST_OK;
} // End of SetRounded

#undef BASE_BUTTONST
shuiyan 2002-03-27
  • 打赏
  • 举报
回复
我是在Dialog内的,你可以到MSDN中找对应的函数看:
1.定义一个CRng对象 m_rgn;
2.在OnInitDialog()中(即初始化)添加如下代码
//这个设置成“四角圆形”
m_rgn.CreateRoundRectRgn(0, 0, rect.right, rect.bottom, 40, 40);
//这个设置成“椭圆”
//m_rgn.CreateEllipticRgn(0,0,rect.Width(),rect.Height());
//以上两个选一个就行,另外还有可以设置多边形的函数

//调用Win32API函数显示
::SetWindowRgn(GetSafeHwnd(),(HRGN)m_rgn,TRUE);
coraykuang 2002-03-27
  • 打赏
  • 举报
回复
CDC::RoundRect
BOOL RoundRect( int x1, int y1, int x2, int y2, int x3, int y3 );
BOOL RoundRect( LPCRECT lpRect, POINT point );
bhsbhs 2002-03-27
  • 打赏
  • 举报
回复
说明白一点,我给你看看
lingg2002 2002-03-27
  • 打赏
  • 举报
回复
关注

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧