大家看看我的程序错哪了?
#include "stdafx.h"#include "Calculator_1.h"
#include "AdvButton.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAdvButton
CAdvButton::CAdvButton()
{//初始化m_ClientRect
m_ClientRect.left=0;
m_ClientRect.top=0;
m_ClientRect.right=0;
m_ClientRect.bottom=0;
m_ClientRgn.DeleteObject();//删除区域对象
m_ClientRgn.CreateEllipticRgnIndirect(&m_ClientRect);//创建椭圆区域
m_State=0;
m_Point.x=m_Point.y=0;
m_IsTimerOn=FALSE;
}
CAdvButton::~CAdvButton()
{
}
BEGIN_MESSAGE_MAP(CAdvButton, CButton)
//{{AFX_MSG_MAP(CAdvButton)
ON_WM_CREATE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAdvButton message handlers
BOOL CAdvButton::Create(LPCTSTR lpszCaption,DWORD dwStyle,const RECT& rect,CWnd *pParentWnd,UINT nID)//编译的时候这地方错了??
{
return CButton::Create(lpszCaption, dwStyle, rect, pParentWnd, nID);
}
//当鼠标在按钮的客户区内按下时,改变按钮的形状
void CAdvButton::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CRect rect;
GetWindowRect(&rect);//得到按钮客户区域的屏幕坐标位置
GetCursorPos(&m_Point);//得到鼠标的屏幕坐标位置
if((rect.PtInRect(m_Point))&&(m_State != 2))
{
m_State = 2; //2:select state
Invalidate(); //重绘客户区
}
CButton::OnLButtonDown(nFlags, point);
}
//当鼠标在按钮的客户区内弹起时,改变按钮状态
void CAdvButton::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CRect rect;
GetWindowRect(&rect); //得到按钮客户区域的屏幕坐标位置
GetCursorPos(&m_Point); //得到鼠标的屏幕坐标位置
if((rect.PtInRect(m_Point))&&(m_State != 1))
{
m_State = 1; //1:focus state
Invalidate(); //重绘客户区
}
CButton::OnLButtonUp(nFlags, point);
}
void CAdvButton::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(!m_IsTimerOn) //如果计时器没用启动
{
SetTimer(1000,100,NULL); //启动计时器
m_IsTimerOn = TRUE;
}
CButton::OnMouseMove(nFlags, point);
}
void CAdvButton::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CRect rect;
GetWindowRect(&rect); //得到按钮客户区域的屏幕坐标位置
GetCursorPos(&m_Point); //得到鼠标的屏幕坐标位置
if(rect.PtInRect(m_Point)) //如果鼠标在按钮的客户区内
{
if((m_State != 1)&&(m_State != 2))
{
m_State = 1;
Invalidate();
}
}
else //如果鼠标已经不在按钮的客户区内了
{
if(m_State != 0)
{
m_State = 0;
Invalidate(); //重绘客户区
}
KillTimer(nIDEvent); //关闭计时器
m_IsTimerOn = FALSE;
}
CButton::OnTimer(nIDEvent);
}
void CAdvButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your code to draw the specified item
//get client rect
GetClientRect(&m_ClientRect); //得到窗口的有效矩形区域
m_ClientRgn.DeleteObject();//
m_ClientRgn.CreateEllipticRgnIndirect(&m_ClientRect); //在矩形区域内创建椭圆
//设置窗口的有效区域为椭圆
SetWindowRgn(m_ClientRgn,FALSE);
CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);//得到按钮控件客户区域的设备环境变量指针
CPen* pPen = NULL;
switch (m_State) //根据按钮不同的状态,创建不同的画笔
{
case 0:
pPen = new CPen(PS_SOLID,1,DefaultColor);
break;
case 1:
pPen = new CPen(PS_SOLID,1,FocusColor);
break;
case 2:
pPen = new CPen(PS_SOLID,1,SelectColor);
break;
case 3:
pPen = new CPen(PS_SOLID,1,DesiableColor);
break;
}
pDC->SetBkMode(TRANSPARENT);//设置背景模式为透明
pPen = pDC->SelectObject(pPen);
pDC->Ellipse(&m_ClientRect); //在按钮客户区内绘制椭圆
pPen = pDC->SelectObject(pPen);
if(pPen) delete pPen;
LPTSTR pCaption = new char[MAXCAPTIONLEN]; //
int iLen = GetWindowText(pCaption,MAXCAPTIONLEN);
pDC->SetTextColor(TextColor); //指定文本颜色
//绘制文本,作为按钮标题
pDC->DrawText(pCaption,iLen,&m_ClientRect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
}
void CAdvButton::PreSubclassWindow()
{
// TODO: Add your specialized code here and/or call the base class
//修改按钮控件风格
ModifyStyle(0,BS_OWNERDRAW|BS_PUSHBUTTON);
CButton::PreSubclassWindow();
}