就是所谓热感应控件。有没有简单的方法。

解决方案 »

  1.   

    http://www.vckbase.com/code/listcode.asp?mclsid=3&sclsid=315
      

  2.   

    // FlatComboBox.cpp : implementation file
    // 
    // Copyright ?1998 Kirk Stowell 
    // All Rights Reserved. 
    // 
    // Email: [email protected] 
    // URL:   www.geocities.com/SiliconValley/Haven/8230 
    // 
    // 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 and all copyright 
    // notices remains intact. If the source code in this file is used in 
    // any  commercial application then a statement along the lines of 
    // "Portions Copyright ?1998 Kirk Stowell" must be included in 
    // the startup banner, "About" box or printed documentation. An email 
    // letting me know that you are using it would be nice as well. That's 
    // not much to ask considering the amount of work that went into this.
    //
    // This file is provided "as is" with no expressed or implied warranty.
    // The author accepts no liability for any damage/loss of business that
    // this product may cause.
    //
    // Expect bugs!
    // 
    // Please use and enjoy, and let me know of any bugs/mods/improvements 
    // that you have found/implemented and I will fix/incorporate them into 
    // this file. 
    //
    // History:
    // --------
    // This control is constantly evolving, sometimes due to new features that I
    // feel are necessary, and sometimes due to existing bugs. Where possible I 
    // have credited the changes to those who contributed code corrections or
    // enhancements (names in brackets) or code suggestions (suggested by...)
    //   
    //          1.0     02 Oct 1998   First release version.
    //          1.01    05 Oct 1998   Fixed cross platform offset bug (Todd Brannam)
    //                                to use GetSystemMetrics(), instead of hard coded values.
    //
    /////////////////////////////////////////////////////////////////////////////#include "stdafx.h"
    #include "LSComboBox.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CLSComboBoxCLSComboBox::CLSComboBox()
    {
    m_bLBtnDown  = false;
    m_bAutoFocus = TRUE;
    m_clr3DFace = GetSysColor(COLOR_3DFACE);
    m_clr3DLight = GetSysColor(COLOR_3DLIGHT);
    m_clr3DHilight = GetSysColor(COLOR_3DHILIGHT);
    m_clr3DShadow = GetSysColor(COLOR_3DSHADOW);
    m_clr3DDkShadow = GetSysColor(COLOR_3DDKSHADOW);
        m_clrText = GetSysColor(COLOR_WINDOWTEXT);
        m_clrBackground = GetSysColor(COLOR_WINDOW);
    }CLSComboBox::~CLSComboBox()
    {
    }BEGIN_MESSAGE_MAP(CLSComboBox, CComboBox)
    //{{AFX_MSG_MAP(CLSComboBox)
    ON_WM_MOUSEMOVE()
    ON_WM_LBUTTONDOWN()
    ON_WM_LBUTTONUP()
    ON_WM_TIMER()
    ON_WM_PAINT()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CLSComboBox message handlersvoid CLSComboBox::OnMouseMove(UINT nFlags, CPoint point) 
    {
    SetTimer(1, 10, NULL);
    CComboBox::OnMouseMove(nFlags, point);
    }void CLSComboBox::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    m_bLBtnDown = true;
    CComboBox::OnLButtonDown(nFlags, point);
    }void CLSComboBox::OnLButtonUp(UINT nFlags, CPoint point) 
    {
    m_bLBtnDown = false;
    Invalidate();
    CComboBox::OnLButtonUp(nFlags, point);
    }void CLSComboBox::OnTimer(UINT nIDEvent) 
    {
    POINT pt;
    CRect rcItem;
    static bool bPainted = false; GetCursorPos(&pt);
    GetWindowRect(&rcItem);
    if (m_bLBtnDown==true) // 如果鼠标左键按下
    {
    KillTimer (1);
    if (bPainted == true) 
    {
    DrawCombo(FC_DRAWPRESSD, m_clr3DHilight, m_clr3DHilight);
    bPainted = false;
    }
    return;
    } if (!rcItem.PtInRect(pt))  // 如果鼠标在组合框外
    {
    KillTimer (1);
    if (bPainted == true) 
    {
    DrawCombo(FC_DRAWNORMAL, m_clr3DFace, m_clr3DFace);
    bPainted = false;
    }
    return;
    }
    else // 如果鼠标在组合框内
    {
    if (bPainted == true)
    return;
    else 
    {
    bPainted = true;
    if(m_bAutoFocus)
    {
    SetFocus();
    DrawCombo(FC_DRAWRAISED, m_clr3DHilight, m_clr3DHilight);
    }
    else
    DrawCombo(FC_DRAWRAISED, m_clr3DFace, m_clr3DFace);
    }
    }

    CComboBox::OnTimer(nIDEvent);
    }void CLSComboBox::OnPaint() 
    {
    Default();
    DrawCombo(FC_DRAWNORMAL, m_clr3DFace, m_clr3DFace);
    }void CLSComboBox::DrawCombo(DWORD dwStyle, COLORREF clrTopLeft, COLORREF clrBottomRight)
    {
    CRect rcItem;
    GetClientRect(&rcItem);
    CDC* pDC = GetDC();

    pDC->Draw3dRect(rcItem, clrTopLeft, clrBottomRight);
    rcItem.DeflateRect(1,1);

    if (!IsWindowEnabled()) 
    {
    pDC->Draw3dRect(rcItem, m_clr3DHilight, m_clr3DHilight);
    rcItem.DeflateRect(1,1);
    rcItem.left = rcItem.right-Offset();
    pDC->Draw3dRect(rcItem, m_clr3DFace, m_clr3DFace);
    rcItem.DeflateRect(1,1);
    pDC->Draw3dRect(rcItem, m_clr3DFace, m_clr3DFace);

    rcItem.top--;
    rcItem.left--;
    rcItem.right++;
    rcItem.bottom++;
    pDC->Draw3dRect(rcItem, m_clr3DHilight, m_clr3DHilight);
    return;
    } switch (dwStyle)
    {
    case FC_DRAWNORMAL:
    pDC->Draw3dRect(rcItem, m_clr3DShadow, m_clr3DShadow); rcItem.DeflateRect(1,1);
    rcItem.left = rcItem.right-Offset();
    pDC->Draw3dRect(rcItem, m_clr3DFace, m_clr3DFace);
    rcItem.DeflateRect(1,1);
    pDC->Draw3dRect(rcItem, m_clr3DFace, m_clr3DFace);

    rcItem.top --;
    rcItem.bottom ++;
    pDC->Draw3dRect(rcItem, m_clr3DHilight, m_clr3DShadow);
    rcItem.left --;
    pDC->Draw3dRect(rcItem, m_clr3DFace, m_clr3DFace);
    break; case FC_DRAWRAISED:
    pDC->Draw3dRect(rcItem, m_clr3DDkShadow, m_clr3DDkShadow); //边框 rcItem.DeflateRect(1,1);
    rcItem.left = rcItem.right-Offset();
    pDC->Draw3dRect(rcItem, m_clr3DFace, m_clr3DFace);
    rcItem.DeflateRect(1,1);
    pDC->Draw3dRect(rcItem, m_clr3DFace, m_clr3DFace);

    rcItem.top--;
    rcItem.left--;
    rcItem.right++;
    rcItem.bottom++;
    pDC->Draw3dRect(rcItem, m_clr3DHilight, m_clr3DHilight);
    break; case FC_DRAWPRESSD:
    pDC->Draw3dRect(rcItem, m_clr3DDkShadow, m_clr3DDkShadow); rcItem.DeflateRect(1,1);
    rcItem.left = rcItem.right-Offset();
    pDC->Draw3dRect(rcItem, m_clr3DFace, m_clr3DFace);
    rcItem.DeflateRect(1,1);
    pDC->Draw3dRect(rcItem, m_clr3DFace, m_clr3DFace);

    rcItem.top--;
    rcItem.left--;
    rcItem.right++;
    rcItem.bottom++;
    pDC->Draw3dRect(rcItem, m_clr3DShadow, m_clr3DShadow);
    break;
    } ReleaseDC(pDC);
    }int CLSComboBox::Offset()
    {
    return ::GetSystemMetrics(SM_CXHTHUMB);
    }void CLSComboBox::SetAutoFocus(BOOL bAutoFocs)
    {
    m_bAutoFocus = bAutoFocs;
    }