• 大小: 4KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-07-18
  • 语言: C/C++
  • 标签: VC++  圆形按钮  MFC  

资源简介

CSDN上原有此类资源,但却使用了全局函数,本人稍微修改封装成了一个独立的类。

资源截图

代码片段和文件信息

// RoundButton.cpp : implementation file
//
// Round Buttons!
//
// Written by Chris Maunder (Chris.Maunder@cbr.clw.csiro.au)
// Copyright (c) 19971998.
// 
// Modified: 2 Feb 1998 - Fix vis problem CRgn resource leak
//                        button reposition code redone. CJM.
//
// This code may be used in compiled form in any way you desire. This
// file may be redistributed unmodified by any means PROVIDING it is 
// not sold for profit without the authors written consent and 
// providing that this notice and the authors name is included. If 
// the source code in this file is used in any commercial application 
// then a simple email would be nice.
//
// This file is provided “as is“ with no expressed or implied warranty.
// The author accepts no liability if it causes any damage to your
// computer causes your pet cat to fall ill increases baldness or
// makes you car start emitting strange noises when you start it up.
//
// Expect bugs.
// 
// Please use and enjoy. Please let me know of any bugs/mods/improvements 
// that you have found/implemented and I will fix/incorporate them into this
// file. 
//
/////////////////////////////////////////////////////////////////////////////

#include “stdafx.h“
#include 
#include “RoundButton.h“

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

/////////////////////////////////////////////////////////////////////////////
// CRoundButton

CRoundButton::CRoundButton()
{
m_bDrawDashedFocusCircle = TRUE;
}

CRoundButton::~CRoundButton()
{
m_rgn.Deleteobject();
}

BEGIN_MESSAGE_MAP(CRoundButton CButton)
//{{AFX_MSG_MAP(CRoundButton)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRoundButton message handlers

void CRoundButton::PreSubclassWindow() 
{
CButton::PreSubclassWindow();

Modifystyle(0 BS_OWNERDRAW);

CRect rect;
GetClientRect(rect);

// Resize the window to make it square
rect.bottom = rect.right = min(rect.bottomrect.right);

// Get the vital statistics of the window
m_ptCentre = rect.CenterPoint();
m_nRadius  = rect.bottom/2-1;

// Set the window region so mouse clicks only activate the round section 
// of the button
m_rgn.Deleteobject(); 
SetWindowRgn(NULL FALSE);
m_rgn.CreateEllipticRgnIndirect(rect);
SetWindowRgn(m_rgn TRUE);

// Convert client coords to the parents client coords
ClientToScreen(rect);
CWnd* pParent = GetParent();
if (pParent) pParent->ScreenToClient(rect);

// Resize the window
MoveWindow(rect.left rect.top rect.Width() rect.Height() TRUE);
}

void CRoundButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
ASSERT(lpDrawItemStruct != NULL);

CDC* pDC   = CDC::FromHandle(lpDrawItemStruct->hDC);
CRect rect = lpDrawItemStruct->rcItem;
UINT state = lpDrawItemStruct->itemState;
UINT nstyle = Getstyle();
int 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       9310  2009-12-13 21:35  RoundButtons\RoundButton.cpp

     文件       2620  2009-12-13 21:30  RoundButtons\RoundButton.h

     目录          0  2009-12-13 20:04  RoundButtons

----------- ---------  ---------- -----  ----

                11930                    3


评论

共有 条评论