如何改变界面按钮的形状

xiaoshu811024 2009-09-01 03:40:12
界面上的按钮,都是矩形的能不能改变其形状,如何改变,请讲的细致一些,谢谢!
...全文
669 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
aqqwrpggame 2009-09-05
  • 打赏
  • 举报
回复
裁剪窗口。就是楼上说的第2个方法
psbeond 2009-09-05
  • 打赏
  • 举报
回复
两种方法:
1.一种是贴图, 用一个画成圆形的图作为按钮背景, 但按钮本身还是长方形的, 圆形以外的部分, 与按钮的父窗口的背景融合到一起就可以了. 这样, 按钮看上去是圆形的,但实际上还是长方形的.

2.用RGN, 给按钮设置一个圆形的RGN.
songtao_01 2009-09-02
  • 打赏
  • 举报
回复
// NOTE: CMyButton is a class derived from CButton. The CMyButton
// object was created as follows:
//
// CMyButton myButton;
// myButton.Create(_T("My button"),
// WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_OWNERDRAW,
// CRect(10,10,100,30), pParentWnd, 1);
//

// This example implements the DrawItem method for a CButton-derived
// class that draws the button's text using the color red.
void CMyButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
UINT uStyle = DFCS_BUTTONPUSH;

// This code only works with buttons.
ASSERT(lpDrawItemStruct->CtlType == ODT_BUTTON);

// If drawing selected, add the pushed style to DrawFrameControl.
if (lpDrawItemStruct->itemState & ODS_SELECTED)
uStyle |= DFCS_PUSHED;

// Draw the button frame.
::DrawFrameControl(lpDrawItemStruct->hDC, &lpDrawItemStruct->rcItem,
DFC_BUTTON, uStyle);

// Get the button's text.
CString strText;
GetWindowText(strText);

// Draw the button text using the text color red.
COLORREF crOldColor = ::SetTextColor(lpDrawItemStruct->hDC, RGB(255,0,0));
::DrawText(lpDrawItemStruct->hDC, strText, strText.GetLength(),
&lpDrawItemStruct->rcItem, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
::SetTextColor(lpDrawItemStruct->hDC, crOldColor);
}

就是改写CButton::DrawItem
songsu 2009-09-01
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 olivertang 的回复:]
需要你自己画,继承以后自己写了
[/Quote]
正解!

小广告:XproerIM即将开源
youyifang 2009-09-01
  • 打赏
  • 举报
回复
http://www.vckbase.com/document/viewdoc/?id=561
看看这个例子,是圆形按钮的
olivertang 2009-09-01
  • 打赏
  • 举报
回复
需要你自己画,继承以后自己写了

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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