龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > VC开发 >

用VC++在工具栏上添加平面组合框控件(3)

时间:2009-12-30 15:42来源:未知 作者:admin 点击:
分享到:
///////////////////////////////// CFlatComboBox CFlatComboBox::CFlatComboBox() { m_bLBtnDown = false; } CFlatComboBox::~CFlatComboBox() { } BEGIN_MESSAGE_MAP(CFlatComboBox, CComboBox) //{{AFX_MSG_MAP(

///////////////////////////////// CFlatComboBox

CFlatComboBox::CFlatComboBox()
{
 m_bLBtnDown = false;
}

CFlatComboBox::~CFlatComboBox()
{
}

BEGIN_MESSAGE_MAP(CFlatComboBox, CComboBox)
//{{AFX_MSG_MAP(CFlatComboBox)
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_TIMER()
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

///////////////////////////////////////////////////// CFlatComboBox message handlers
void CFlatComboBox::OnMouseMove(UINT nFlags, CPoint point)
{
 SetTimer(1,10,NULL);
 CComboBox::OnMouseMove(nFlags, point);
}

void CFlatComboBox::OnLButtonDown(UINT nFlags, CPoint point)
{
 m_bLBtnDown = true;
 CComboBox::OnLButtonDown(nFlags, point);
}

void CFlatComboBox::OnLButtonUp(UINT nFlags, CPoint point)
{
 m_bLBtnDown = false;
 Invalidate();
 CComboBox::OnLButtonUp(nFlags, point);
}

void CFlatComboBox::OnTimer(UINT nIDEvent)
{
 POINT pt;
 GetCursorPos(&pt);
 CRect rcItem;
 GetWindowRect(&rcItem);
 static bool bPainted = false;
 // OnLButtonDown, show pressed.
 if (m_bLBtnDown==true) {
  KillTimer (1);
   if (bPainted == true) {
    DrawCombo(FC_DRAWPRESSD, ::GetSysColor(COLOR_BTNSHADOW),
    ::GetSysColor(COLOR_BTNHIGHLIGHT));
    bPainted = false;
   }
  return;
 }
 // If mouse leaves, show flat.
 if (!rcItem.PtInRect(pt)) {
  KillTimer (1);
  if (bPainted == true) {
    DrawCombo(FC_DRAWNORMAL, ::GetSysColor(COLOR_BTNFACE),::GetSysColor(COLOR_BTNFACE));
    bPainted = false;
  }
  return;
 }

精彩图集

赞助商链接