📄 tempbar.cpp
字号:
// TempBar.cpp : implementation file
//
#include "stdafx.h"
#include "FuShe.h"
#include "TempBar.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTempBar
CTempBar::CTempBar()
{
m_bDown=FALSE;
m_bHilight=TRUE;
}
CTempBar::~CTempBar()
{
}
BEGIN_MESSAGE_MAP(CTempBar, CListBox)
//{{AFX_MSG_MAP(CTempBar)
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_TIMER()
ON_WM_LBUTTONUP()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTempBar message handlers
void CTempBar::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your code to draw the specified item
CDC *dc=CDC::FromHandle(lpDrawItemStruct->hDC);
CRect rcItem(lpDrawItemStruct->rcItem);
CRect rClient(rcItem);
CRect rText;
CPoint pt((rcItem.Width()-32)/2,rcItem.top+15);
pTempItems pTemp=&m_pItem[lpDrawItemStruct->itemID];
HICON hIcon=AfxGetApp()->LoadIcon(pTemp->nImageID);
rClient.DeflateRect(5,10);
rcItem.CopyRect(rClient);
rText.CopyRect(rClient);
rText.top+=45;
dc->SetBkMode(TRANSPARENT);
if(lpDrawItemStruct->itemAction&ODA_DRAWENTIRE)
{
// dc->FillSolidRect(rClient,GetSysColor(COLOR_BTNSHADOW));
dc->DrawIcon(pt,hIcon);
dc->DrawText(pTemp->strText,rText,DT_CENTER|DT_WORDBREAK);
}
if(m_bDown)
{
pt.x+=5;
pt.y+=5;
rcItem.DeflateRect(5,5);
rText.DeflateRect(5,5);
}
///////////////处于选种状态下的列表颜色/////////////////////////////////////////////////
if((lpDrawItemStruct->itemState&ODS_SELECTED)&&(lpDrawItemStruct->itemAction&(ODA_SELECT|ODA_DRAWENTIRE)))
{
if(m_bHilight)
{
dc->FillSolidRect(rClient,GetSysColor(COLOR_BTNFACE));
if(m_bDown)
dc->Draw3dRect(rClient,GetSysColor(COLOR_3DSHADOW),GetSysColor(COLOR_3DHILIGHT));
else
dc->Draw3dRect(rClient,GetSysColor(COLOR_3DHILIGHT),GetSysColor(COLOR_3DSHADOW));
}
dc->DrawIcon(pt,hIcon);
dc->DrawText(pTemp->strText,rText,DT_CENTER|DT_WORDBREAK);
}
///////没有处于选中状态的列表的颜色////////////////////////////////////////////////////
if(!(lpDrawItemStruct->itemState&ODS_SELECTED)&&(lpDrawItemStruct->itemAction&ODA_SELECT|ODA_DRAWENTIRE))
{
dc->FillSolidRect(rClient,GetSysColor(COLOR_WINDOW));
dc->DrawIcon(pt,hIcon);
dc->DrawText(pTemp->strText,rText,DT_CENTER|DT_WORDBREAK);
}
}
void CTempBar::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
// TODO: Add your code to determine the size of specified item
lpMeasureItemStruct->itemHeight=85;
}
void CTempBar::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_bDown=TRUE;
SetCurSel(GetCurSel()); //使得当前状态进入选中状态
CListBox::OnLButtonDown(nFlags, point);
}
void CTempBar::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_point=point;
SetTimer(1,50,NULL);
CListBox::OnMouseMove(nFlags, point);
}
void CTempBar::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
BOOL bOutPoint;
CRect rWindow;
CPoint CurPoint;
GetWindowRect(rWindow); //得到窗口的矩形区域
GetCursorPos(&CurPoint); //得到鼠标的位置
/////////////////判断鼠标是否落在矩形区域///////////////////////////////////////
if(!rWindow.PtInRect(CurPoint))
{
if(!m_bDown)
{
SetCurSel(-1);
m_bHilight=FALSE;
}
KillTimer(1);
return;
}
/////////找出与鼠标最近的那个列表项,将之设为选中项//////////////////////////////
m_bHilight=TRUE;
int index;
index=ItemFromPoint(m_point,bOutPoint);
if((index!=GetCurSel())&&!bOutPoint)
SetCurSel(index);
// CListBox::OnTimer(nIDEvent);
}
void CTempBar::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_bDown=FALSE;
SetCurSel(GetCurSel());
CListBox::OnLButtonUp(nFlags, point);
}
void CTempBar::CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType)
{
// TODO: Add your specialized code here and/or call the base class
CListBox::CalcWindowRect(lpClientRect, nAdjustType);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -