【VC开源代码栏目提醒】:本文主要为网学会员提供DrawTool.cpp,希望对需要DrawTool.cpp网友有所帮助,学习一下!
// DrawTool.cpp : implementation file
//
#include "stdafx.h"
#include "DrawToolBar.h"
#include "DrawTool.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDrawTool
CDrawTool::CDrawTool()
{
m_HotColor = RGB(193, 210, 238);
m_TextColor = RGB(0,0,255);
m_LineColor = RGB(49, 106, 197);
m_HotTextColor = RGB(255,0,0);
m_IsDraw = TRUE;
}
CDrawTool::~CDrawTool()
{
}
void CDrawTool::OnOwnerDraw(NMHDR *pNotifyStruct, LRESULT *pResult)
{
NMTBCUSTOMDRAW *pCustomDraw = (NMTBCUSTOMDRAW *)pNotifyStruct;
CDC dc;
dc.Attach(pCustomDraw->nmcd.hdc);
if (pCustomDraw->nmcd.uItemState &CDIS_HOT )
pCustomDraw->clrText =m_HotTextColor;
else
pCustomDraw->clrText =m_TextColor;
switch (pCustomDraw->nmcd.dwDrawStage)
{
case CDDS_PREPAINT:
*pResult = CDRF_NOTIFYITEMDRAW;
break;
case CDDS_ITEMPREPAINT:
DrawButton(&dc, pCustomDraw->nmcd.rc, pCustomDraw->nmcd.uItemState);
*pResult = TBCDRF_NOEDGES; //不绘按钮边框
break;
}
dc.Detach();
}
void CDrawTool::DrawButton(CDC *pDC, const RECT &rect, UINT uState)
{
CPoint pt;
GetCursorPos(&pt);
ScreenToClient(&pt);
CRect rect1;
GetClientRect(rect1);
if (rect1.PtInRect(pt))
{
if (uState & CDIS_HOT)
{
CPen pen(PS_SOLID, 1, m_LineColor);
CPen *pOldPen = pDC->SelectObject(&pen);
CBrush brush(m_HotColor);
CBrush *pOldBrush = pDC->SelectObject(&brush);
pDC->Rectangle(&rect);
pDC->SelectObject(pOldBrush);
pDC->SelectObject(pOldPen);
}
}
}
BEGIN_MESSAGE_MAP(CDrawTool, CToolBarCtrl)
//{{AFX_MSG_MAP(CDrawTool)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnOwnerDraw)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDrawTool message handlers
上一篇:
DrawTH.cpp
下一篇:
个人哪些方面的情况值得你在简历里做介绍?